Skip to content

Commit

Permalink
Add ssh_tunnel_uuid to deployment schema; make it nillable in api mod…
Browse files Browse the repository at this point in the history
…els for both deployment & destination
  • Loading branch information
danafallon committed Aug 6, 2024
1 parent cf6969e commit 93d8b2d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/resources/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Artie Deployment resource
### Optional

- `destination_uuid` (String)
- `ssh_tunnel_uuid` (String)

### Read-Only

Expand Down
14 changes: 13 additions & 1 deletion examples/deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ resource "artie_deployment" "dev_postgres_to_snowflake" {
password = var.postgres_password
}
tables = [
{
name = "account"
schema = "public"
},
{
name = "company"
schema = "public"
},
{
name = "invite"
schema = "public"
}
},
{
name = "monitor"
schema = "public"
},
]
}
destination_uuid = artie_destination.snowflake.uuid
Expand Down
1 change: 1 addition & 0 deletions internal/provider/deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"name": schema.StringAttribute{Required: true},
"status": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
"destination_uuid": schema.StringAttribute{Computed: true, Optional: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
"ssh_tunnel_uuid": schema.StringAttribute{Computed: true, Optional: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
"source": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/destination_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (r *DestinationResource) Create(ctx context.Context, req resource.CreateReq
"label": destModel.Label,
"sharedConfig": destModel.Config,
}
if destModel.SSHTunnelUUID != "" {
payload["sshTunnelUUID"] = destModel.SSHTunnelUUID
if destModel.SSHTunnelUUID != nil {
payload["sshTunnelUUID"] = *destModel.SSHTunnelUUID
}
payloadBytes, err := json.Marshal(payload)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/provider/models/deployment_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type DeploymentAPIModel struct {
Name string `json:"name"`
Status string `json:"status"`
DestinationUUID string `json:"destinationUUID"`
SSHTunnelUUID *string `json:"sshTunnelUUID"`
Source SourceAPIModel `json:"source"`
DestinationConfig DestinationConfigAPIModel `json:"uniqueConfig"`
}
Expand Down
1 change: 1 addition & 0 deletions internal/provider/models/deployment_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DeploymentResourceModel struct {
Name types.String `tfsdk:"name"`
Status types.String `tfsdk:"status"`
DestinationUUID types.String `tfsdk:"destination_uuid"`
SSHTunnelUUID types.String `tfsdk:"ssh_tunnel_uuid"`
Source *SourceModel `tfsdk:"source"`
DestinationConfig *DeploymentDestinationConfigModel `tfsdk:"destination_config"`
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/models/destination_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type DestinationAPIModel struct {
UUID string `json:"uuid"`
Type string `json:"name"`
Label string `json:"label"`
SSHTunnelUUID string `json:"sshTunnelUUID"`
SSHTunnelUUID *string `json:"sshTunnelUUID"`
Config DestinationSharedConfigAPIModel `json:"sharedConfig"`
}

Expand Down
11 changes: 11 additions & 0 deletions internal/provider/models/translate_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
resourceModel.Status = types.StringValue(apiModel.Status)
resourceModel.DestinationUUID = types.StringValue(apiModel.DestinationUUID)

sshTunnelUUID := ""
if apiModel.SSHTunnelUUID != nil {
sshTunnelUUID = *apiModel.SSHTunnelUUID
}
resourceModel.SSHTunnelUUID = types.StringValue(sshTunnelUUID)

tables := []TableModel{}
for _, apiTable := range apiModel.Source.Tables {
tables = append(tables, TableModel{
Expand Down Expand Up @@ -91,6 +97,11 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
},
}

sshTunnelUUID := resourceModel.SSHTunnelUUID.ValueString()
if sshTunnelUUID != "" {
apiModel.SSHTunnelUUID = &sshTunnelUUID
}

switch resourceModel.Source.Type.ValueString() {
case string(PostgreSQL):
apiModel.Source.Config = SourceConfigAPIModel{
Expand Down
24 changes: 14 additions & 10 deletions internal/provider/models/translate_destination.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package models

import (
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel *DestinationResourceModel) {
resourceModel.UUID = types.StringValue(apiModel.UUID)
resourceModel.Type = types.StringValue(apiModel.Type)
resourceModel.Label = types.StringValue(apiModel.Label)
resourceModel.SSHTunnelUUID = types.StringValue(apiModel.SSHTunnelUUID)

sshTunnelUUID := ""
if apiModel.SSHTunnelUUID != nil {
sshTunnelUUID = *apiModel.SSHTunnelUUID
}
resourceModel.SSHTunnelUUID = types.StringValue(sshTunnelUUID)

switch resourceModel.Type.ValueString() {
case string(Snowflake):
Expand Down Expand Up @@ -38,15 +42,15 @@ func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel *
}

func DestinationResourceToAPIModel(resourceModel DestinationResourceModel) DestinationAPIModel {
sshTunnelUUID := resourceModel.SSHTunnelUUID.ValueString()
if sshTunnelUUID == "" {
sshTunnelUUID = uuid.Nil.String()
}
apiModel := DestinationAPIModel{
UUID: resourceModel.UUID.ValueString(),
Type: resourceModel.Type.ValueString(),
Label: resourceModel.Label.ValueString(),
SSHTunnelUUID: sshTunnelUUID,
UUID: resourceModel.UUID.ValueString(),
Type: resourceModel.Type.ValueString(),
Label: resourceModel.Label.ValueString(),
}

sshTunnelUUID := resourceModel.SSHTunnelUUID.ValueString()
if sshTunnelUUID != "" {
apiModel.SSHTunnelUUID = &sshTunnelUUID
}

switch resourceModel.Type.ValueString() {
Expand Down

0 comments on commit 93d8b2d

Please sign in to comment.