diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md index a8353a6..459d87f 100644 --- a/docs/resources/deployment.md +++ b/docs/resources/deployment.md @@ -24,6 +24,7 @@ Artie Deployment resource ### Optional - `destination_uuid` (String) +- `ssh_tunnel_uuid` (String) ### Read-Only diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf index ea81f87..e01c43d 100644 --- a/examples/deployments/main.tf +++ b/examples/deployments/main.tf @@ -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 diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go index 83e5cf4..e9e5f27 100644 --- a/internal/provider/deployment_resource.go +++ b/internal/provider/deployment_resource.go @@ -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{ diff --git a/internal/provider/destination_resource.go b/internal/provider/destination_resource.go index ba3458c..c76132a 100644 --- a/internal/provider/destination_resource.go +++ b/internal/provider/destination_resource.go @@ -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 { diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go index 2e17e10..163ebb3 100644 --- a/internal/provider/models/deployment_api_model.go +++ b/internal/provider/models/deployment_api_model.go @@ -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"` } diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go index 17d0ebe..24ab0e0 100644 --- a/internal/provider/models/deployment_resource_model.go +++ b/internal/provider/models/deployment_resource_model.go @@ -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"` } diff --git a/internal/provider/models/destination_api_model.go b/internal/provider/models/destination_api_model.go index d7ced40..0fbdf1b 100644 --- a/internal/provider/models/destination_api_model.go +++ b/internal/provider/models/destination_api_model.go @@ -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"` } diff --git a/internal/provider/models/translate_deployment.go b/internal/provider/models/translate_deployment.go index 29eca19..a11affa 100644 --- a/internal/provider/models/translate_deployment.go +++ b/internal/provider/models/translate_deployment.go @@ -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{ @@ -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{ diff --git a/internal/provider/models/translate_destination.go b/internal/provider/models/translate_destination.go index e5c9308..654bd86 100644 --- a/internal/provider/models/translate_destination.go +++ b/internal/provider/models/translate_destination.go @@ -1,7 +1,6 @@ package models import ( - "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -9,7 +8,12 @@ func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel * 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): @@ -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() {