Skip to content

Commit

Permalink
Make table advanced settings optional
Browse files Browse the repository at this point in the history
  • Loading branch information
danafallon committed Jul 30, 2024
1 parent 88c12e7 commit 351dbe2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
5 changes: 2 additions & 3 deletions examples/deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ resource "artie_deployment" "dev_postgres_to_snowflake" {
}
tables = [
{
name = "invite"
schema = "public"
advanced_settings = {}
name = "invite"
schema = "public"
}
]
}
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/models/deployment_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ type DynamoDBConfigAPIModel struct {
}

type TableAPIModel struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Schema string `json:"schema"`
EnableHistoryMode bool `json:"enableHistoryMode"`
IndividualDeployment bool `json:"individualDeployment"`
IsPartitioned bool `json:"isPartitioned"`
AdvancedSettings TableAdvancedSettingsAPIModel `json:"advancedSettings"`
UUID string `json:"uuid"`
Name string `json:"name"`
Schema string `json:"schema"`
EnableHistoryMode bool `json:"enableHistoryMode"`
IndividualDeployment bool `json:"individualDeployment"`
IsPartitioned bool `json:"isPartitioned"`
AdvancedSettings *TableAdvancedSettingsAPIModel `json:"advancedSettings"`
}

type TableAdvancedSettingsAPIModel struct {
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/models/deployment_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ type DynamoDBConfigModel struct {
}

type TableModel struct {
UUID types.String `tfsdk:"uuid"`
Name types.String `tfsdk:"name"`
Schema types.String `tfsdk:"schema"`
EnableHistoryMode types.Bool `tfsdk:"enable_history_mode"`
IndividualDeployment types.Bool `tfsdk:"individual_deployment"`
IsPartitioned types.Bool `tfsdk:"is_partitioned"`
AdvancedSettings TableAdvancedSettingsModel `tfsdk:"advanced_settings"`
UUID types.String `tfsdk:"uuid"`
Name types.String `tfsdk:"name"`
Schema types.String `tfsdk:"schema"`
EnableHistoryMode types.Bool `tfsdk:"enable_history_mode"`
IndividualDeployment types.Bool `tfsdk:"individual_deployment"`
IsPartitioned types.Bool `tfsdk:"is_partitioned"`
AdvancedSettings *TableAdvancedSettingsModel `tfsdk:"advanced_settings"`
}

type TableAdvancedSettingsModel struct {
Expand Down
44 changes: 26 additions & 18 deletions internal/provider/models/translate_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De

tables := []TableModel{}
for _, apiTable := range apiModel.Source.Tables {
tables = append(tables, TableModel{
UUID: types.StringValue(apiTable.UUID),
Name: types.StringValue(apiTable.Name),
Schema: types.StringValue(apiTable.Schema),
EnableHistoryMode: types.BoolValue(apiTable.EnableHistoryMode),
IndividualDeployment: types.BoolValue(apiTable.IndividualDeployment),
IsPartitioned: types.BoolValue(apiTable.IsPartitioned),
AdvancedSettings: TableAdvancedSettingsModel{
var advSettings *TableAdvancedSettingsModel
if apiTable.AdvancedSettings != nil {
advSettings = &TableAdvancedSettingsModel{
Alias: types.StringValue(apiTable.AdvancedSettings.Alias),
SkipDelete: types.BoolValue(apiTable.AdvancedSettings.SkipDelete),
FlushIntervalSeconds: types.Int64Value(apiTable.AdvancedSettings.FlushIntervalSeconds),
Expand All @@ -34,7 +29,16 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
K8sRequestCPU: types.Int64Value(apiTable.AdvancedSettings.K8sRequestCPU),
K8sRequestMemoryMB: types.Int64Value(apiTable.AdvancedSettings.K8sRequestMemoryMB),
// TODO BigQueryPartitionSettings, MergePredicates, ExcludeColumns
},
}
}
tables = append(tables, TableModel{
UUID: types.StringValue(apiTable.UUID),
Name: types.StringValue(apiTable.Name),
Schema: types.StringValue(apiTable.Schema),
EnableHistoryMode: types.BoolValue(apiTable.EnableHistoryMode),
IndividualDeployment: types.BoolValue(apiTable.IndividualDeployment),
IsPartitioned: types.BoolValue(apiTable.IsPartitioned),
AdvancedSettings: advSettings,
})
}
var dynamoDBConfig *DynamoDBConfigModel
Expand Down Expand Up @@ -93,14 +97,9 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
if tableUUID == "" {
tableUUID = uuid.Nil.String()
}
tables = append(tables, TableAPIModel{
UUID: tableUUID,
Name: table.Name.ValueString(),
Schema: table.Schema.ValueString(),
EnableHistoryMode: table.EnableHistoryMode.ValueBool(),
IndividualDeployment: table.IndividualDeployment.ValueBool(),
IsPartitioned: table.IsPartitioned.ValueBool(),
AdvancedSettings: TableAdvancedSettingsAPIModel{
var advSettings *TableAdvancedSettingsAPIModel
if table.AdvancedSettings != nil {
advSettings = &TableAdvancedSettingsAPIModel{
Alias: table.AdvancedSettings.Alias.ValueString(),
SkipDelete: table.AdvancedSettings.SkipDelete.ValueBool(),
FlushIntervalSeconds: table.AdvancedSettings.FlushIntervalSeconds.ValueInt64(),
Expand All @@ -111,7 +110,16 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
K8sRequestCPU: table.AdvancedSettings.K8sRequestCPU.ValueInt64(),
K8sRequestMemoryMB: table.AdvancedSettings.K8sRequestMemoryMB.ValueInt64(),
// TODO BigQueryPartitionSettings, MergePredicates, ExcludeColumns
},
}
}
tables = append(tables, TableAPIModel{
UUID: tableUUID,
Name: table.Name.ValueString(),
Schema: table.Schema.ValueString(),
EnableHistoryMode: table.EnableHistoryMode.ValueBool(),
IndividualDeployment: table.IndividualDeployment.ValueBool(),
IsPartitioned: table.IsPartitioned.ValueBool(),
AdvancedSettings: advSettings,
})
}

Expand Down

0 comments on commit 351dbe2

Please sign in to comment.