From 0e583db5e29490524a0058a9f082dab39761c109 Mon Sep 17 00:00:00 2001 From: Dana Fallon <8871189+danafallon@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:00:54 -0800 Subject: [PATCH] Start adding support for advanced settings --- internal/artieclient/deployment.go | 26 +++++++++++++++++++++--- internal/provider/deployment_resource.go | 2 ++ internal/provider/tfmodels/deployment.go | 8 ++++++++ internal/provider/tfmodels/util.go | 15 ++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/internal/artieclient/deployment.go b/internal/artieclient/deployment.go index 74b0bc3..d4b24c7 100644 --- a/internal/artieclient/deployment.go +++ b/internal/artieclient/deployment.go @@ -39,6 +39,10 @@ type BaseDeployment struct { DestinationConfig DestinationConfig `json:"specificDestCfg"` SSHTunnelUUID *uuid.UUID `json:"sshTunnelUUID"` SnowflakeEcoScheduleUUID *uuid.UUID `json:"snowflakeEcoScheduleUUID"` + + // Advanced settings + DropDeletedColumns *bool `json:"dropDeletedColumns"` + EnableSoftDelete *bool `json:"enableSoftDelete"` } type Deployment struct { @@ -47,6 +51,22 @@ type Deployment struct { Status string `json:"status"` } +type deploymentWithAdvSettings struct { + Deployment + AdvancedSettings advancedSettings `json:"advancedSettings"` +} + +type advancedSettings struct { + DropDeletedColumns bool `json:"dropDeletedColumns"` + EnableSoftDelete bool `json:"enableSoftDelete"` +} + +func unnestAdvSettings(deployment deploymentWithAdvSettings) Deployment { + deployment.DropDeletedColumns = &deployment.AdvancedSettings.DropDeletedColumns + deployment.EnableSoftDelete = &deployment.AdvancedSettings.EnableSoftDelete + return deployment.Deployment +} + type Source struct { Type SourceType `json:"type"` Config SourceConfig `json:"config"` @@ -88,7 +108,7 @@ func (DeploymentClient) basePath() string { } type deploymentAPIResponse struct { - Deployment Deployment `json:"deploy"` + Deployment deploymentWithAdvSettings `json:"deploy"` } type validationResponse struct { @@ -104,7 +124,7 @@ func (dc DeploymentClient) Get(ctx context.Context, deploymentUUID string) (Depl if err != nil { return Deployment{}, err } - return response.Deployment, nil + return unnestAdvSettings(response.Deployment), nil } func (dc DeploymentClient) Create(ctx context.Context, deployment BaseDeployment) (Deployment, error) { @@ -130,7 +150,7 @@ func (dc DeploymentClient) Update(ctx context.Context, deployment Deployment) (D if err != nil { return Deployment{}, err } - return response.Deployment, nil + return unnestAdvSettings(response.Deployment), nil } func (dc DeploymentClient) ValidateSource(ctx context.Context, deployment BaseDeployment) error { diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go index e802487..1e18a00 100644 --- a/internal/provider/deployment_resource.go +++ b/internal/provider/deployment_resource.go @@ -149,6 +149,8 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ }, }, }, + "drop_deleted_columns": schema.BoolAttribute{Optional: true, Computed: true, PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, MarkdownDescription: "If set to true, when a column is dropped from the source it will also be dropped in the destination."}, + "soft_delete_rows": schema.BoolAttribute{Optional: true, Computed: true, PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, MarkdownDescription: "If set to true, a new boolean column called __artie_delete will be added to your destination to indicate if the row has been deleted."}, }, } } diff --git a/internal/provider/tfmodels/deployment.go b/internal/provider/tfmodels/deployment.go index 01bffe7..a27e8a0 100644 --- a/internal/provider/tfmodels/deployment.go +++ b/internal/provider/tfmodels/deployment.go @@ -15,6 +15,10 @@ type Deployment struct { DestinationConfig DeploymentDestinationConfig `tfsdk:"destination_config"` SSHTunnelUUID types.String `tfsdk:"ssh_tunnel_uuid"` SnowflakeEcoScheduleUUID types.String `tfsdk:"snowflake_eco_schedule_uuid"` + + // Advanced settings + DropDeletedColumns types.Bool `tfsdk:"drop_deleted_columns"` + SoftDeleteRows types.Bool `tfsdk:"soft_delete_rows"` } func (d Deployment) ToAPIBaseModel() artieclient.BaseDeployment { @@ -25,6 +29,8 @@ func (d Deployment) ToAPIBaseModel() artieclient.BaseDeployment { DestinationConfig: d.DestinationConfig.ToAPIModel(), SSHTunnelUUID: ParseOptionalUUID(d.SSHTunnelUUID), SnowflakeEcoScheduleUUID: ParseOptionalUUID(d.SnowflakeEcoScheduleUUID), + DropDeletedColumns: parseOptionalBool(d.DropDeletedColumns), + EnableSoftDelete: parseOptionalBool(d.SoftDeleteRows), } } @@ -46,6 +52,8 @@ func DeploymentFromAPIModel(apiModel artieclient.Deployment) Deployment { DestinationConfig: DeploymentDestinationConfigFromAPIModel(apiModel.DestinationConfig), SSHTunnelUUID: optionalUUIDToStringValue(apiModel.SSHTunnelUUID), SnowflakeEcoScheduleUUID: optionalUUIDToStringValue(apiModel.SnowflakeEcoScheduleUUID), + DropDeletedColumns: optionalBoolToBoolValue(apiModel.DropDeletedColumns), + SoftDeleteRows: optionalBoolToBoolValue(apiModel.EnableSoftDelete), } } diff --git a/internal/provider/tfmodels/util.go b/internal/provider/tfmodels/util.go index 42785c8..134ce13 100644 --- a/internal/provider/tfmodels/util.go +++ b/internal/provider/tfmodels/util.go @@ -26,3 +26,18 @@ func optionalUUIDToStringValue(value *uuid.UUID) types.String { } return types.StringValue(value.String()) } + +func parseOptionalBool(value types.Bool) *bool { + if value.IsNull() { + return nil + } + _bool := value.ValueBool() + return &_bool +} + +func optionalBoolToBoolValue(value *bool) types.Bool { + if value == nil { + return types.BoolValue(false) + } + return types.BoolValue(*value) +}