Skip to content

Commit

Permalink
Start adding support for advanced settings (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
danafallon authored Nov 19, 2024
1 parent 462710f commit 202f53a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/resources/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ resource "artie_deployment" "postgres_to_snowflake" {

### Optional

- `drop_deleted_columns` (Boolean) If set to true, when a column is dropped from the source it will also be dropped in the destination.
- `soft_delete_rows` (Boolean) 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.
- `ssh_tunnel_uuid` (String) This can point to an `artie_ssh_tunnel` resource if you need us to use an SSH tunnel to connect to your source database.

### Read-Only
Expand Down
26 changes: 23 additions & 3 deletions internal/artieclient/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`
Expand Down Expand Up @@ -88,7 +108,7 @@ func (DeploymentClient) basePath() string {
}

type deploymentAPIResponse struct {
Deployment Deployment `json:"deploy"`
Deployment deploymentWithAdvSettings `json:"deploy"`
}

type validationResponse struct {
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/deployment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions internal/provider/tfmodels/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
}

Expand All @@ -48,6 +54,8 @@ func DeploymentFromAPIModel(apiModel artieclient.Deployment) Deployment {
DestinationConfig: &destinationConfig,
SSHTunnelUUID: optionalUUIDToStringValue(apiModel.SSHTunnelUUID),
SnowflakeEcoScheduleUUID: optionalUUIDToStringValue(apiModel.SnowflakeEcoScheduleUUID),
DropDeletedColumns: optionalBoolToBoolValue(apiModel.DropDeletedColumns),
SoftDeleteRows: optionalBoolToBoolValue(apiModel.EnableSoftDelete),
}
}

Expand Down
15 changes: 15 additions & 0 deletions internal/provider/tfmodels/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 202f53a

Please sign in to comment.