From 1cb60ee6fde1e1eb84c2d8aa8591f5aea851c1ad Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Tue, 23 Jul 2024 20:35:08 -0700
Subject: [PATCH 01/12] Start adding rest of deployment schema
---
examples/deployments/main.tf | 19 ++++
internal/provider/deployment_resource.go | 114 ++++++++++++++++++++++-
2 files changed, 130 insertions(+), 3 deletions(-)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index f4388fe..9ba5282 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -17,6 +17,25 @@ import {
resource "artie_deployment" "example" {
name = "MongoDB ➡️ BigQuery"
+ source = {
+ name = "MongoDB"
+ config = {
+ database = "myFirstDatabase"
+ host = "mongodb+srv://cluster0.szddg49.mongodb.net/"
+ port = 0
+ user = "artie"
+ }
+ tables = [
+ {
+ name = "customers"
+ schema = ""
+ },
+ {
+ name = "stock"
+ schema = ""
+ }
+ ]
+ }
}
# data "artie_deployments" "example" {}
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index 66b347f..fd5290f 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -28,24 +28,80 @@ type DeploymentResource struct {
apiKey string
}
+// Resource model
type DeploymentResourceModel struct {
UUID types.String `tfsdk:"uuid"`
Name types.String `tfsdk:"name"`
Status types.String `tfsdk:"status"`
LastUpdatedAt types.String `tfsdk:"last_updated_at"`
+ DestinationUUID types.String `tfsdk:"destination_uuid"`
HasUndeployedChanges types.Bool `tfsdk:"has_undeployed_changes"`
+ Source *SourceModel `tfsdk:"source"`
+ AdvancedSettings types.Map `tfsdk:"advanced_settings"`
+ UniqueConfig types.Map `tfsdk:"unique_config"`
}
+type SourceModel struct {
+ Name types.String `tfsdk:"name"`
+ Config SourceConfigModel `tfsdk:"config"`
+ Tables []TableModel `tfsdk:"tables"`
+}
+
+type SourceConfigModel struct {
+ Host types.String `tfsdk:"host"`
+ Port types.Int64 `tfsdk:"port"`
+ User types.String `tfsdk:"user"`
+ Database types.String `tfsdk:"database"`
+}
+
+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 types.Map `tfsdk:"advanced_settings"`
+}
+
+// API response model
type DeploymentResponse struct {
Deployment DeploymentResourceAPIModel `json:"deploy"`
}
type DeploymentResourceAPIModel struct {
+ UUID string `json:"uuid"`
+ Name string `json:"name"`
+ Status string `json:"status"`
+ LastUpdatedAt string `json:"lastUpdatedAt"`
+ DestinationUUID string `json:"destinationUUID"`
+ HasUndeployedChanges bool `json:"hasUndeployedChanges"`
+ Source SourceAPIModel `json:"source"`
+ AdvancedSettings map[string]any `json:"advancedSettings"`
+ UniqueConfig map[string]any `json:"uniqueConfig"`
+}
+
+type SourceAPIModel struct {
+ Name string `json:"name"`
+ Config SourceConfigAPIModel `json:"config"`
+ Tables []TableAPIModel `json:"tables"`
+}
+
+type SourceConfigAPIModel struct {
+ Host string `json:"host"`
+ Port int64 `json:"port"`
+ User string `json:"user"`
+ Database string `json:"database"`
+}
+
+type TableAPIModel struct {
UUID string `json:"uuid"`
Name string `json:"name"`
- Status string `json:"status"`
- LastUpdatedAt string `json:"lastUpdatedAt"`
- HasUndeployedChanges bool `json:"hasUndeployedChanges"`
+ Schema string `json:"schema"`
+ EnableHistoryMode bool `json:"enableHistoryMode"`
+ IndividualDeployment bool `json:"individualDeployment"`
+ IsPartitioned bool `json:"isPartitioned"`
+ // AdvancedSettings map[string]any `json:"advancedSettings"`
}
func (r *DeploymentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -60,7 +116,48 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"name": schema.StringAttribute{Required: true},
"status": schema.StringAttribute{Computed: true, Optional: true},
"last_updated_at": schema.StringAttribute{Computed: true},
+ "destination_uuid": schema.StringAttribute{Computed: true},
"has_undeployed_changes": schema.BoolAttribute{Computed: true},
+ "source": schema.SingleNestedAttribute{
+ Required: true,
+ Attributes: map[string]schema.Attribute{
+ "name": schema.StringAttribute{Required: true},
+ "config": schema.SingleNestedAttribute{
+ Required: true,
+ Attributes: map[string]schema.Attribute{
+ "host": schema.StringAttribute{Required: true},
+ "port": schema.NumberAttribute{Required: true},
+ "user": schema.StringAttribute{Required: true},
+ "database": schema.StringAttribute{Required: true},
+ },
+ },
+ "tables": schema.ListNestedAttribute{
+ Required: true,
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "uuid": schema.StringAttribute{Computed: true},
+ "name": schema.StringAttribute{Required: true},
+ "schema": schema.StringAttribute{Required: true},
+ "enable_history_mode": schema.BoolAttribute{Optional: true},
+ "individual_deployment": schema.BoolAttribute{Optional: true},
+ "is_partitioned": schema.BoolAttribute{Optional: true},
+ // "advanced_settings": schema.MapAttribute{
+ // Optional: true,
+ // ElementType: types.StringType,
+ // },
+ },
+ },
+ },
+ },
+ },
+ "advanced_settings": schema.MapAttribute{
+ Optional: true,
+ ElementType: types.StringType,
+ },
+ "unique_config": schema.MapAttribute{
+ Optional: true,
+ ElementType: types.StringType,
+ },
},
}
}
@@ -160,6 +257,17 @@ func (r *DeploymentResource) Read(ctx context.Context, req resource.ReadRequest,
data.Status = types.StringValue(deploymentResp.Deployment.Status)
data.LastUpdatedAt = types.StringValue(deploymentResp.Deployment.LastUpdatedAt)
data.HasUndeployedChanges = types.BoolValue(deploymentResp.Deployment.HasUndeployedChanges)
+ data.DestinationUUID = types.StringValue(deploymentResp.Deployment.DestinationUUID)
+ data.Source = &SourceModel{
+ Name: types.StringValue(deploymentResp.Deployment.Source.Name),
+ Config: SourceConfigModel{
+ Host: types.StringValue(deploymentResp.Deployment.Source.Config.Host),
+ Port: types.Int64Value(deploymentResp.Deployment.Source.Config.Port),
+ User: types.StringValue(deploymentResp.Deployment.Source.Config.User),
+ Database: types.StringValue(deploymentResp.Deployment.Source.Config.Database),
+ },
+ Tables: make([]TableModel, len(deploymentResp.Deployment.Source.Tables)),
+ }
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
From 11ef0749e518c21a5767314eef8f26bcc360116c Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Tue, 23 Jul 2024 20:35:32 -0700
Subject: [PATCH 02/12] Generate
---
docs/resources/deployment.md | 42 ++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index e27b9a4..4566dcf 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -18,13 +18,55 @@ Artie Deployment resource
### Required
- `name` (String)
+- `source` (Attributes) (see [below for nested schema](#nestedatt--source))
### Optional
+- `advanced_settings` (Map of String)
- `status` (String)
+- `unique_config` (Map of String)
### Read-Only
+- `destination_uuid` (String)
- `has_undeployed_changes` (Boolean)
- `last_updated_at` (String)
- `uuid` (String)
+
+
+### Nested Schema for `source`
+
+Required:
+
+- `config` (Attributes) (see [below for nested schema](#nestedatt--source--config))
+- `name` (String)
+- `tables` (Attributes List) (see [below for nested schema](#nestedatt--source--tables))
+
+
+### Nested Schema for `source.config`
+
+Required:
+
+- `database` (String)
+- `host` (String)
+- `port` (Number)
+- `user` (String)
+
+
+
+### Nested Schema for `source.tables`
+
+Required:
+
+- `name` (String)
+- `schema` (String)
+
+Optional:
+
+- `enable_history_mode` (Boolean)
+- `individual_deployment` (Boolean)
+- `is_partitioned` (Boolean)
+
+Read-Only:
+
+- `uuid` (String)
From d3662329e10c0f3ab3c63447cd4d45f5f1807e4b Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Tue, 23 Jul 2024 20:40:32 -0700
Subject: [PATCH 03/12] Lint
---
internal/provider/deployment_resource.go | 2 --
1 file changed, 2 deletions(-)
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index fd5290f..3772652 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -28,7 +28,6 @@ type DeploymentResource struct {
apiKey string
}
-// Resource model
type DeploymentResourceModel struct {
UUID types.String `tfsdk:"uuid"`
Name types.String `tfsdk:"name"`
@@ -64,7 +63,6 @@ type TableModel struct {
// AdvancedSettings types.Map `tfsdk:"advanced_settings"`
}
-// API response model
type DeploymentResponse struct {
Deployment DeploymentResourceAPIModel `json:"deploy"`
}
From 824afdc1bc3b752e017e383ea4dd340d69ff0c66 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 11:06:32 -0700
Subject: [PATCH 04/12] Table advanced settings
---
docs/resources/deployment.md | 12 +++
examples/deployments/main.tf | 3 +
internal/provider/deployment_resource.go | 96 +++++++++++++++++++-----
3 files changed, 92 insertions(+), 19 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index 4566dcf..6746ef5 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -63,6 +63,7 @@ Required:
Optional:
+- `advanced_settings` (Attributes) (see [below for nested schema](#nestedatt--source--tables--advanced_settings))
- `enable_history_mode` (Boolean)
- `individual_deployment` (Boolean)
- `is_partitioned` (Boolean)
@@ -70,3 +71,14 @@ Optional:
Read-Only:
- `uuid` (String)
+
+
+### Nested Schema for `source.tables.advanced_settings`
+
+Optional:
+
+- `alias` (String)
+- `buffer_rows` (Number)
+- `flush_interval_seconds` (Number)
+- `flush_size_kb` (Number)
+- `skip_delete` (Boolean)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index 9ba5282..f94e425 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -29,6 +29,9 @@ resource "artie_deployment" "example" {
{
name = "customers"
schema = ""
+ advanced_settings = {
+ skip_delete = false
+ }
},
{
name = "stock"
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index 3772652..64e44eb 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -51,16 +51,34 @@ type SourceConfigModel struct {
Port types.Int64 `tfsdk:"port"`
User types.String `tfsdk:"user"`
Database types.String `tfsdk:"database"`
+ // Password
+ // DynamoDBConfig
+ // SnapshotHost
}
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 types.Map `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 {
+ Alias types.String `tfsdk:"alias"`
+ SkipDelete types.Bool `tfsdk:"skip_delete"`
+ FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
+ BufferRows types.Int64 `tfsdk:"buffer_rows"`
+ FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
+ // BigQueryPartitionSettings
+ // MergePredicates
+ // AutoscaleMaxReplicas
+ // AutoscaleTargetValue
+ // K8sRequestCPU
+ // K8sRequestMemoryMB
+ // ExcludeColumns
}
type DeploymentResponse struct {
@@ -93,13 +111,28 @@ type SourceConfigAPIModel 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 map[string]any `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 {
+ Alias string `json:"alias"`
+ SkipDelete bool `json:"skip_delete"`
+ FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
+ BufferRows int64 `json:"buffer_rows"`
+ FlushSizeKB int64 `json:"flush_size_kb"`
+ // BigQueryPartitionSettings
+ // MergePredicates
+ // AutoscaleMaxReplicas
+ // AutoscaleTargetValue
+ // K8sRequestCPU
+ // K8sRequestMemoryMB
+ // ExcludeColumns
}
func (r *DeploymentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -139,10 +172,16 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"enable_history_mode": schema.BoolAttribute{Optional: true},
"individual_deployment": schema.BoolAttribute{Optional: true},
"is_partitioned": schema.BoolAttribute{Optional: true},
- // "advanced_settings": schema.MapAttribute{
- // Optional: true,
- // ElementType: types.StringType,
- // },
+ "advanced_settings": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "alias": schema.StringAttribute{Optional: true},
+ "skip_delete": schema.BoolAttribute{Optional: true},
+ "flush_interval_seconds": schema.NumberAttribute{Optional: true},
+ "buffer_rows": schema.NumberAttribute{Optional: true},
+ "flush_size_kb": schema.NumberAttribute{Optional: true},
+ },
+ },
},
},
},
@@ -256,6 +295,25 @@ func (r *DeploymentResource) Read(ctx context.Context, req resource.ReadRequest,
data.LastUpdatedAt = types.StringValue(deploymentResp.Deployment.LastUpdatedAt)
data.HasUndeployedChanges = types.BoolValue(deploymentResp.Deployment.HasUndeployedChanges)
data.DestinationUUID = types.StringValue(deploymentResp.Deployment.DestinationUUID)
+
+ tables := []TableModel{}
+ for _, apiTable := range deploymentResp.Deployment.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{
+ Alias: types.StringValue(apiTable.AdvancedSettings.Alias),
+ SkipDelete: types.BoolValue(apiTable.AdvancedSettings.SkipDelete),
+ FlushIntervalSeconds: types.Int64Value(apiTable.AdvancedSettings.FlushIntervalSeconds),
+ BufferRows: types.Int64Value(apiTable.AdvancedSettings.BufferRows),
+ FlushSizeKB: types.Int64Value(apiTable.AdvancedSettings.FlushSizeKB),
+ },
+ })
+ }
data.Source = &SourceModel{
Name: types.StringValue(deploymentResp.Deployment.Source.Name),
Config: SourceConfigModel{
@@ -264,7 +322,7 @@ func (r *DeploymentResource) Read(ctx context.Context, req resource.ReadRequest,
User: types.StringValue(deploymentResp.Deployment.Source.Config.User),
Database: types.StringValue(deploymentResp.Deployment.Source.Config.Database),
},
- Tables: make([]TableModel, len(deploymentResp.Deployment.Source.Tables)),
+ Tables: tables,
}
// Save updated data into Terraform state
From de369a6d31c399d3e228900346ac5febd47029b7 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 11:29:52 -0700
Subject: [PATCH 05/12] Deployment advanced settings
---
docs/resources/deployment.md | 19 ++++-
examples/deployments/main.tf | 4 +
internal/provider/deployment_resource.go | 99 ++++++++++++++++++------
3 files changed, 96 insertions(+), 26 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index 6746ef5..67f33de 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -22,7 +22,7 @@ Artie Deployment resource
### Optional
-- `advanced_settings` (Map of String)
+- `advanced_settings` (Attributes) (see [below for nested schema](#nestedatt--advanced_settings))
- `status` (String)
- `unique_config` (Map of String)
@@ -82,3 +82,20 @@ Optional:
- `flush_interval_seconds` (Number)
- `flush_size_kb` (Number)
- `skip_delete` (Boolean)
+
+
+
+
+
+### Nested Schema for `advanced_settings`
+
+Optional:
+
+- `buffer_rows` (Number)
+- `drop_deleted_columns` (Boolean)
+- `enable_heartbeats` (Boolean)
+- `enable_soft_delete` (Boolean)
+- `flush_interval_seconds` (Number)
+- `flush_size_kb` (Number)
+- `include_artie_updated_at_column` (Boolean)
+- `include_database_updated_at_column` (Boolean)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index f94e425..5b9500d 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -39,6 +39,10 @@ resource "artie_deployment" "example" {
}
]
}
+ advanced_settings = {
+ drop_deleted_columns = false
+ enable_soft_delete = true
+ }
}
# data "artie_deployments" "example" {}
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index 64e44eb..c0fd689 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -29,15 +29,30 @@ type DeploymentResource struct {
}
type DeploymentResourceModel struct {
- UUID types.String `tfsdk:"uuid"`
- Name types.String `tfsdk:"name"`
- Status types.String `tfsdk:"status"`
- LastUpdatedAt types.String `tfsdk:"last_updated_at"`
- DestinationUUID types.String `tfsdk:"destination_uuid"`
- HasUndeployedChanges types.Bool `tfsdk:"has_undeployed_changes"`
- Source *SourceModel `tfsdk:"source"`
- AdvancedSettings types.Map `tfsdk:"advanced_settings"`
- UniqueConfig types.Map `tfsdk:"unique_config"`
+ UUID types.String `tfsdk:"uuid"`
+ Name types.String `tfsdk:"name"`
+ Status types.String `tfsdk:"status"`
+ LastUpdatedAt types.String `tfsdk:"last_updated_at"`
+ DestinationUUID types.String `tfsdk:"destination_uuid"`
+ HasUndeployedChanges types.Bool `tfsdk:"has_undeployed_changes"`
+ Source *SourceModel `tfsdk:"source"`
+ AdvancedSettings *DeploymentAdvancedSettingsModel `tfsdk:"advanced_settings"`
+ UniqueConfig types.Map `tfsdk:"unique_config"`
+}
+
+type DeploymentAdvancedSettingsModel struct {
+ DropDeletedColumns types.Bool `tfsdk:"drop_deleted_columns"`
+ IncludeArtieUpdatedAtColumn types.Bool `tfsdk:"include_artie_updated_at_column"`
+ IncludeDatabaseUpdatedAtColumn types.Bool `tfsdk:"include_database_updated_at_column"`
+ EnableHeartbeats types.Bool `tfsdk:"enable_heartbeats"`
+ EnableSoftDelete types.Bool `tfsdk:"enable_soft_delete"`
+ FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
+ BufferRows types.Int64 `tfsdk:"buffer_rows"`
+ FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
+ // PublicationNameOverride
+ // ReplicationSlotOverride
+ // PublicationAutoCreateMode
+ // PartitionRegex
}
type SourceModel struct {
@@ -86,15 +101,15 @@ type DeploymentResponse struct {
}
type DeploymentResourceAPIModel struct {
- UUID string `json:"uuid"`
- Name string `json:"name"`
- Status string `json:"status"`
- LastUpdatedAt string `json:"lastUpdatedAt"`
- DestinationUUID string `json:"destinationUUID"`
- HasUndeployedChanges bool `json:"hasUndeployedChanges"`
- Source SourceAPIModel `json:"source"`
- AdvancedSettings map[string]any `json:"advancedSettings"`
- UniqueConfig map[string]any `json:"uniqueConfig"`
+ UUID string `json:"uuid"`
+ Name string `json:"name"`
+ Status string `json:"status"`
+ LastUpdatedAt string `json:"lastUpdatedAt"`
+ DestinationUUID string `json:"destinationUUID"`
+ HasUndeployedChanges bool `json:"hasUndeployedChanges"`
+ Source SourceAPIModel `json:"source"`
+ AdvancedSettings DeploymentAdvancedSettingsAPIModel `json:"advancedSettings"`
+ UniqueConfig map[string]any `json:"uniqueConfig"`
}
type SourceAPIModel struct {
@@ -135,6 +150,21 @@ type TableAdvancedSettingsAPIModel struct {
// ExcludeColumns
}
+type DeploymentAdvancedSettingsAPIModel struct {
+ DropDeletedColumns bool `json:"drop_deleted_columns"`
+ IncludeArtieUpdatedAtColumn bool `json:"include_artie_updated_at_column"`
+ IncludeDatabaseUpdatedAtColumn bool `json:"include_database_updated_at_column"`
+ EnableHeartbeats bool `json:"enable_heartbeats"`
+ EnableSoftDelete bool `json:"enable_soft_delete"`
+ FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
+ BufferRows int64 `json:"buffer_rows"`
+ FlushSizeKB int64 `json:"flush_size_kb"`
+ // PublicationNameOverride
+ // ReplicationSlotOverride
+ // PublicationAutoCreateMode
+ // PartitionRegex
+}
+
func (r *DeploymentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_deployment"
}
@@ -157,7 +187,7 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
Required: true,
Attributes: map[string]schema.Attribute{
"host": schema.StringAttribute{Required: true},
- "port": schema.NumberAttribute{Required: true},
+ "port": schema.Int64Attribute{Required: true},
"user": schema.StringAttribute{Required: true},
"database": schema.StringAttribute{Required: true},
},
@@ -177,9 +207,9 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
Attributes: map[string]schema.Attribute{
"alias": schema.StringAttribute{Optional: true},
"skip_delete": schema.BoolAttribute{Optional: true},
- "flush_interval_seconds": schema.NumberAttribute{Optional: true},
- "buffer_rows": schema.NumberAttribute{Optional: true},
- "flush_size_kb": schema.NumberAttribute{Optional: true},
+ "flush_interval_seconds": schema.Int64Attribute{Optional: true},
+ "buffer_rows": schema.Int64Attribute{Optional: true},
+ "flush_size_kb": schema.Int64Attribute{Optional: true},
},
},
},
@@ -187,9 +217,18 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
},
},
},
- "advanced_settings": schema.MapAttribute{
- Optional: true,
- ElementType: types.StringType,
+ "advanced_settings": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "drop_deleted_columns": schema.BoolAttribute{Optional: true},
+ "include_artie_updated_at_column": schema.BoolAttribute{Optional: true},
+ "include_database_updated_at_column": schema.BoolAttribute{Optional: true},
+ "enable_heartbeats": schema.BoolAttribute{Optional: true},
+ "enable_soft_delete": schema.BoolAttribute{Optional: true},
+ "flush_interval_seconds": schema.Int64Attribute{Optional: true},
+ "buffer_rows": schema.Int64Attribute{Optional: true},
+ "flush_size_kb": schema.Int64Attribute{Optional: true},
+ },
},
"unique_config": schema.MapAttribute{
Optional: true,
@@ -324,6 +363,16 @@ func (r *DeploymentResource) Read(ctx context.Context, req resource.ReadRequest,
},
Tables: tables,
}
+ data.AdvancedSettings = &DeploymentAdvancedSettingsModel{
+ DropDeletedColumns: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.DropDeletedColumns),
+ IncludeArtieUpdatedAtColumn: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.IncludeArtieUpdatedAtColumn),
+ IncludeDatabaseUpdatedAtColumn: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.IncludeDatabaseUpdatedAtColumn),
+ EnableHeartbeats: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.EnableHeartbeats),
+ EnableSoftDelete: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.EnableSoftDelete),
+ FlushIntervalSeconds: types.Int64Value(deploymentResp.Deployment.AdvancedSettings.FlushIntervalSeconds),
+ BufferRows: types.Int64Value(deploymentResp.Deployment.AdvancedSettings.BufferRows),
+ FlushSizeKB: types.Int64Value(deploymentResp.Deployment.AdvancedSettings.FlushSizeKB),
+ }
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
From 1490b911d2cbc4de854c58c5b52871094d15f5b6 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 11:49:15 -0700
Subject: [PATCH 06/12] Pull models out into separate package
---
internal/provider/deployment_resource.go | 194 +-----------------
.../provider/models/deployment_api_model.go | 73 +++++++
.../models/deployment_resource_model.go | 71 +++++++
internal/provider/models/translate.go | 50 +++++
4 files changed, 202 insertions(+), 186 deletions(-)
create mode 100644 internal/provider/models/deployment_api_model.go
create mode 100644 internal/provider/models/deployment_resource_model.go
create mode 100644 internal/provider/models/translate.go
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index c0fd689..7a6da07 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
+ "terraform-provider-artie/internal/provider/models"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -28,143 +29,6 @@ type DeploymentResource struct {
apiKey string
}
-type DeploymentResourceModel struct {
- UUID types.String `tfsdk:"uuid"`
- Name types.String `tfsdk:"name"`
- Status types.String `tfsdk:"status"`
- LastUpdatedAt types.String `tfsdk:"last_updated_at"`
- DestinationUUID types.String `tfsdk:"destination_uuid"`
- HasUndeployedChanges types.Bool `tfsdk:"has_undeployed_changes"`
- Source *SourceModel `tfsdk:"source"`
- AdvancedSettings *DeploymentAdvancedSettingsModel `tfsdk:"advanced_settings"`
- UniqueConfig types.Map `tfsdk:"unique_config"`
-}
-
-type DeploymentAdvancedSettingsModel struct {
- DropDeletedColumns types.Bool `tfsdk:"drop_deleted_columns"`
- IncludeArtieUpdatedAtColumn types.Bool `tfsdk:"include_artie_updated_at_column"`
- IncludeDatabaseUpdatedAtColumn types.Bool `tfsdk:"include_database_updated_at_column"`
- EnableHeartbeats types.Bool `tfsdk:"enable_heartbeats"`
- EnableSoftDelete types.Bool `tfsdk:"enable_soft_delete"`
- FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
- BufferRows types.Int64 `tfsdk:"buffer_rows"`
- FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
- // PublicationNameOverride
- // ReplicationSlotOverride
- // PublicationAutoCreateMode
- // PartitionRegex
-}
-
-type SourceModel struct {
- Name types.String `tfsdk:"name"`
- Config SourceConfigModel `tfsdk:"config"`
- Tables []TableModel `tfsdk:"tables"`
-}
-
-type SourceConfigModel struct {
- Host types.String `tfsdk:"host"`
- Port types.Int64 `tfsdk:"port"`
- User types.String `tfsdk:"user"`
- Database types.String `tfsdk:"database"`
- // Password
- // DynamoDBConfig
- // SnapshotHost
-}
-
-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"`
-}
-
-type TableAdvancedSettingsModel struct {
- Alias types.String `tfsdk:"alias"`
- SkipDelete types.Bool `tfsdk:"skip_delete"`
- FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
- BufferRows types.Int64 `tfsdk:"buffer_rows"`
- FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
- // BigQueryPartitionSettings
- // MergePredicates
- // AutoscaleMaxReplicas
- // AutoscaleTargetValue
- // K8sRequestCPU
- // K8sRequestMemoryMB
- // ExcludeColumns
-}
-
-type DeploymentResponse struct {
- Deployment DeploymentResourceAPIModel `json:"deploy"`
-}
-
-type DeploymentResourceAPIModel struct {
- UUID string `json:"uuid"`
- Name string `json:"name"`
- Status string `json:"status"`
- LastUpdatedAt string `json:"lastUpdatedAt"`
- DestinationUUID string `json:"destinationUUID"`
- HasUndeployedChanges bool `json:"hasUndeployedChanges"`
- Source SourceAPIModel `json:"source"`
- AdvancedSettings DeploymentAdvancedSettingsAPIModel `json:"advancedSettings"`
- UniqueConfig map[string]any `json:"uniqueConfig"`
-}
-
-type SourceAPIModel struct {
- Name string `json:"name"`
- Config SourceConfigAPIModel `json:"config"`
- Tables []TableAPIModel `json:"tables"`
-}
-
-type SourceConfigAPIModel struct {
- Host string `json:"host"`
- Port int64 `json:"port"`
- User string `json:"user"`
- Database string `json:"database"`
-}
-
-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"`
-}
-
-type TableAdvancedSettingsAPIModel struct {
- Alias string `json:"alias"`
- SkipDelete bool `json:"skip_delete"`
- FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
- BufferRows int64 `json:"buffer_rows"`
- FlushSizeKB int64 `json:"flush_size_kb"`
- // BigQueryPartitionSettings
- // MergePredicates
- // AutoscaleMaxReplicas
- // AutoscaleTargetValue
- // K8sRequestCPU
- // K8sRequestMemoryMB
- // ExcludeColumns
-}
-
-type DeploymentAdvancedSettingsAPIModel struct {
- DropDeletedColumns bool `json:"drop_deleted_columns"`
- IncludeArtieUpdatedAtColumn bool `json:"include_artie_updated_at_column"`
- IncludeDatabaseUpdatedAtColumn bool `json:"include_database_updated_at_column"`
- EnableHeartbeats bool `json:"enable_heartbeats"`
- EnableSoftDelete bool `json:"enable_soft_delete"`
- FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
- BufferRows int64 `json:"buffer_rows"`
- FlushSizeKB int64 `json:"flush_size_kb"`
- // PublicationNameOverride
- // ReplicationSlotOverride
- // PublicationAutoCreateMode
- // PartitionRegex
-}
-
func (r *DeploymentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_deployment"
}
@@ -259,7 +123,7 @@ func (r *DeploymentResource) Configure(ctx context.Context, req resource.Configu
}
func (r *DeploymentResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
- var data DeploymentResourceModel
+ var data models.DeploymentResourceModel
// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
@@ -289,7 +153,7 @@ func (r *DeploymentResource) Create(ctx context.Context, req resource.CreateRequ
}
func (r *DeploymentResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
- var data DeploymentResourceModel
+ var data models.DeploymentResourceModel
// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
@@ -322,64 +186,22 @@ func (r *DeploymentResource) Read(ctx context.Context, req resource.ReadRequest,
return
}
- var deploymentResp DeploymentResponse
+ var deploymentResp models.DeploymentAPIResponse
err = json.Unmarshal(bodyBytes, &deploymentResp)
if err != nil {
resp.Diagnostics.AddError("Unable to Read Deployment", err.Error())
return
}
- data.Name = types.StringValue(deploymentResp.Deployment.Name)
- data.Status = types.StringValue(deploymentResp.Deployment.Status)
- data.LastUpdatedAt = types.StringValue(deploymentResp.Deployment.LastUpdatedAt)
- data.HasUndeployedChanges = types.BoolValue(deploymentResp.Deployment.HasUndeployedChanges)
- data.DestinationUUID = types.StringValue(deploymentResp.Deployment.DestinationUUID)
-
- tables := []TableModel{}
- for _, apiTable := range deploymentResp.Deployment.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{
- Alias: types.StringValue(apiTable.AdvancedSettings.Alias),
- SkipDelete: types.BoolValue(apiTable.AdvancedSettings.SkipDelete),
- FlushIntervalSeconds: types.Int64Value(apiTable.AdvancedSettings.FlushIntervalSeconds),
- BufferRows: types.Int64Value(apiTable.AdvancedSettings.BufferRows),
- FlushSizeKB: types.Int64Value(apiTable.AdvancedSettings.FlushSizeKB),
- },
- })
- }
- data.Source = &SourceModel{
- Name: types.StringValue(deploymentResp.Deployment.Source.Name),
- Config: SourceConfigModel{
- Host: types.StringValue(deploymentResp.Deployment.Source.Config.Host),
- Port: types.Int64Value(deploymentResp.Deployment.Source.Config.Port),
- User: types.StringValue(deploymentResp.Deployment.Source.Config.User),
- Database: types.StringValue(deploymentResp.Deployment.Source.Config.Database),
- },
- Tables: tables,
- }
- data.AdvancedSettings = &DeploymentAdvancedSettingsModel{
- DropDeletedColumns: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.DropDeletedColumns),
- IncludeArtieUpdatedAtColumn: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.IncludeArtieUpdatedAtColumn),
- IncludeDatabaseUpdatedAtColumn: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.IncludeDatabaseUpdatedAtColumn),
- EnableHeartbeats: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.EnableHeartbeats),
- EnableSoftDelete: types.BoolValue(deploymentResp.Deployment.AdvancedSettings.EnableSoftDelete),
- FlushIntervalSeconds: types.Int64Value(deploymentResp.Deployment.AdvancedSettings.FlushIntervalSeconds),
- BufferRows: types.Int64Value(deploymentResp.Deployment.AdvancedSettings.BufferRows),
- FlushSizeKB: types.Int64Value(deploymentResp.Deployment.AdvancedSettings.FlushSizeKB),
- }
+ // Translate API response into Terraform state
+ models.DeploymentAPIToResourceModel(deploymentResp.Deployment, &data)
// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
func (r *DeploymentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
- var data DeploymentResourceModel
+ var data models.DeploymentResourceModel
// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
@@ -401,7 +223,7 @@ func (r *DeploymentResource) Update(ctx context.Context, req resource.UpdateRequ
}
func (r *DeploymentResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
- var data DeploymentResourceModel
+ var data models.DeploymentResourceModel
// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
new file mode 100644
index 0000000..900d564
--- /dev/null
+++ b/internal/provider/models/deployment_api_model.go
@@ -0,0 +1,73 @@
+package models
+
+type DeploymentAPIResponse struct {
+ Deployment DeploymentAPIModel `json:"deploy"`
+}
+
+type DeploymentAPIModel struct {
+ UUID string `json:"uuid"`
+ Name string `json:"name"`
+ Status string `json:"status"`
+ LastUpdatedAt string `json:"lastUpdatedAt"`
+ DestinationUUID string `json:"destinationUUID"`
+ HasUndeployedChanges bool `json:"hasUndeployedChanges"`
+ Source SourceAPIModel `json:"source"`
+ AdvancedSettings DeploymentAdvancedSettingsAPIModel `json:"advancedSettings"`
+ UniqueConfig map[string]any `json:"uniqueConfig"`
+}
+
+type SourceAPIModel struct {
+ Name string `json:"name"`
+ Config SourceConfigAPIModel `json:"config"`
+ Tables []TableAPIModel `json:"tables"`
+}
+
+type SourceConfigAPIModel struct {
+ Host string `json:"host"`
+ Port int64 `json:"port"`
+ User string `json:"user"`
+ Database string `json:"database"`
+ // Password
+ // DynamoDBConfig
+ // SnapshotHost
+}
+
+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"`
+}
+
+type TableAdvancedSettingsAPIModel struct {
+ Alias string `json:"alias"`
+ SkipDelete bool `json:"skip_delete"`
+ FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
+ BufferRows int64 `json:"buffer_rows"`
+ FlushSizeKB int64 `json:"flush_size_kb"`
+ // BigQueryPartitionSettings
+ // MergePredicates
+ // AutoscaleMaxReplicas
+ // AutoscaleTargetValue
+ // K8sRequestCPU
+ // K8sRequestMemoryMB
+ // ExcludeColumns
+}
+
+type DeploymentAdvancedSettingsAPIModel struct {
+ DropDeletedColumns bool `json:"drop_deleted_columns"`
+ IncludeArtieUpdatedAtColumn bool `json:"include_artie_updated_at_column"`
+ IncludeDatabaseUpdatedAtColumn bool `json:"include_database_updated_at_column"`
+ EnableHeartbeats bool `json:"enable_heartbeats"`
+ EnableSoftDelete bool `json:"enable_soft_delete"`
+ FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
+ BufferRows int64 `json:"buffer_rows"`
+ FlushSizeKB int64 `json:"flush_size_kb"`
+ // PublicationNameOverride
+ // ReplicationSlotOverride
+ // PublicationAutoCreateMode
+ // PartitionRegex
+}
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
new file mode 100644
index 0000000..ad7f5a0
--- /dev/null
+++ b/internal/provider/models/deployment_resource_model.go
@@ -0,0 +1,71 @@
+package models
+
+import "github.com/hashicorp/terraform-plugin-framework/types"
+
+type DeploymentResourceModel struct {
+ UUID types.String `tfsdk:"uuid"`
+ Name types.String `tfsdk:"name"`
+ Status types.String `tfsdk:"status"`
+ LastUpdatedAt types.String `tfsdk:"last_updated_at"`
+ DestinationUUID types.String `tfsdk:"destination_uuid"`
+ HasUndeployedChanges types.Bool `tfsdk:"has_undeployed_changes"`
+ Source *SourceModel `tfsdk:"source"`
+ AdvancedSettings *DeploymentAdvancedSettingsModel `tfsdk:"advanced_settings"`
+ UniqueConfig types.Map `tfsdk:"unique_config"`
+}
+
+type SourceModel struct {
+ Name types.String `tfsdk:"name"`
+ Config SourceConfigModel `tfsdk:"config"`
+ Tables []TableModel `tfsdk:"tables"`
+}
+
+type SourceConfigModel struct {
+ Host types.String `tfsdk:"host"`
+ Port types.Int64 `tfsdk:"port"`
+ User types.String `tfsdk:"user"`
+ Database types.String `tfsdk:"database"`
+ // Password
+ // DynamoDBConfig
+ // SnapshotHost
+}
+
+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"`
+}
+
+type TableAdvancedSettingsModel struct {
+ Alias types.String `tfsdk:"alias"`
+ SkipDelete types.Bool `tfsdk:"skip_delete"`
+ FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
+ BufferRows types.Int64 `tfsdk:"buffer_rows"`
+ FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
+ // BigQueryPartitionSettings
+ // MergePredicates
+ // AutoscaleMaxReplicas
+ // AutoscaleTargetValue
+ // K8sRequestCPU
+ // K8sRequestMemoryMB
+ // ExcludeColumns
+}
+
+type DeploymentAdvancedSettingsModel struct {
+ DropDeletedColumns types.Bool `tfsdk:"drop_deleted_columns"`
+ IncludeArtieUpdatedAtColumn types.Bool `tfsdk:"include_artie_updated_at_column"`
+ IncludeDatabaseUpdatedAtColumn types.Bool `tfsdk:"include_database_updated_at_column"`
+ EnableHeartbeats types.Bool `tfsdk:"enable_heartbeats"`
+ EnableSoftDelete types.Bool `tfsdk:"enable_soft_delete"`
+ FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
+ BufferRows types.Int64 `tfsdk:"buffer_rows"`
+ FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
+ // PublicationNameOverride
+ // ReplicationSlotOverride
+ // PublicationAutoCreateMode
+ // PartitionRegex
+}
diff --git a/internal/provider/models/translate.go b/internal/provider/models/translate.go
new file mode 100644
index 0000000..c911dfe
--- /dev/null
+++ b/internal/provider/models/translate.go
@@ -0,0 +1,50 @@
+package models
+
+import "github.com/hashicorp/terraform-plugin-framework/types"
+
+func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *DeploymentResourceModel) {
+ resourceModel.Name = types.StringValue(apiModel.Name)
+ resourceModel.Status = types.StringValue(apiModel.Status)
+ resourceModel.LastUpdatedAt = types.StringValue(apiModel.LastUpdatedAt)
+ resourceModel.HasUndeployedChanges = types.BoolValue(apiModel.HasUndeployedChanges)
+ resourceModel.DestinationUUID = types.StringValue(apiModel.DestinationUUID)
+
+ 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{
+ Alias: types.StringValue(apiTable.AdvancedSettings.Alias),
+ SkipDelete: types.BoolValue(apiTable.AdvancedSettings.SkipDelete),
+ FlushIntervalSeconds: types.Int64Value(apiTable.AdvancedSettings.FlushIntervalSeconds),
+ BufferRows: types.Int64Value(apiTable.AdvancedSettings.BufferRows),
+ FlushSizeKB: types.Int64Value(apiTable.AdvancedSettings.FlushSizeKB),
+ },
+ })
+ }
+ resourceModel.Source = &SourceModel{
+ Name: types.StringValue(apiModel.Source.Name),
+ Config: SourceConfigModel{
+ Host: types.StringValue(apiModel.Source.Config.Host),
+ Port: types.Int64Value(apiModel.Source.Config.Port),
+ User: types.StringValue(apiModel.Source.Config.User),
+ Database: types.StringValue(apiModel.Source.Config.Database),
+ },
+ Tables: tables,
+ }
+ resourceModel.AdvancedSettings = &DeploymentAdvancedSettingsModel{
+ DropDeletedColumns: types.BoolValue(apiModel.AdvancedSettings.DropDeletedColumns),
+ IncludeArtieUpdatedAtColumn: types.BoolValue(apiModel.AdvancedSettings.IncludeArtieUpdatedAtColumn),
+ IncludeDatabaseUpdatedAtColumn: types.BoolValue(apiModel.AdvancedSettings.IncludeDatabaseUpdatedAtColumn),
+ EnableHeartbeats: types.BoolValue(apiModel.AdvancedSettings.EnableHeartbeats),
+ EnableSoftDelete: types.BoolValue(apiModel.AdvancedSettings.EnableSoftDelete),
+ FlushIntervalSeconds: types.Int64Value(apiModel.AdvancedSettings.FlushIntervalSeconds),
+ BufferRows: types.Int64Value(apiModel.AdvancedSettings.BufferRows),
+ FlushSizeKB: types.Int64Value(apiModel.AdvancedSettings.FlushSizeKB),
+ }
+}
From 6aae87d1d21017f2380a7bf7c3b8de48668b9c43 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 12:58:49 -0700
Subject: [PATCH 07/12] Add default/computed for optional attributes
---
examples/deployments/main.tf | 3 +-
internal/provider/deployment_resource.go | 35 +++++++++++++-----------
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index 5b9500d..963eadf 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -40,8 +40,7 @@ resource "artie_deployment" "example" {
]
}
advanced_settings = {
- drop_deleted_columns = false
- enable_soft_delete = true
+ enable_soft_delete = true
}
}
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index 7a6da07..e20df32 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -11,6 +11,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
@@ -63,18 +65,19 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"uuid": schema.StringAttribute{Computed: true},
"name": schema.StringAttribute{Required: true},
"schema": schema.StringAttribute{Required: true},
- "enable_history_mode": schema.BoolAttribute{Optional: true},
- "individual_deployment": schema.BoolAttribute{Optional: true},
- "is_partitioned": schema.BoolAttribute{Optional: true},
+ "enable_history_mode": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "individual_deployment": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "is_partitioned": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
"advanced_settings": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
- "alias": schema.StringAttribute{Optional: true},
- "skip_delete": schema.BoolAttribute{Optional: true},
- "flush_interval_seconds": schema.Int64Attribute{Optional: true},
- "buffer_rows": schema.Int64Attribute{Optional: true},
- "flush_size_kb": schema.Int64Attribute{Optional: true},
+ "alias": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "skip_delete": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "flush_interval_seconds": schema.Int64Attribute{Optional: true, Computed: true},
+ "buffer_rows": schema.Int64Attribute{Optional: true, Computed: true},
+ "flush_size_kb": schema.Int64Attribute{Optional: true, Computed: true},
},
+ Computed: true,
},
},
},
@@ -84,14 +87,14 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"advanced_settings": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{
- "drop_deleted_columns": schema.BoolAttribute{Optional: true},
- "include_artie_updated_at_column": schema.BoolAttribute{Optional: true},
- "include_database_updated_at_column": schema.BoolAttribute{Optional: true},
- "enable_heartbeats": schema.BoolAttribute{Optional: true},
- "enable_soft_delete": schema.BoolAttribute{Optional: true},
- "flush_interval_seconds": schema.Int64Attribute{Optional: true},
- "buffer_rows": schema.Int64Attribute{Optional: true},
- "flush_size_kb": schema.Int64Attribute{Optional: true},
+ "drop_deleted_columns": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "include_artie_updated_at_column": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(true)},
+ "include_database_updated_at_column": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "enable_heartbeats": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "enable_soft_delete": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "flush_interval_seconds": schema.Int64Attribute{Optional: true, Computed: true},
+ "buffer_rows": schema.Int64Attribute{Optional: true, Computed: true},
+ "flush_size_kb": schema.Int64Attribute{Optional: true, Computed: true},
},
},
"unique_config": schema.MapAttribute{
From 13dbb8a6500bdb6aaf18981e38b52cf04568d56c Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 14:16:06 -0700
Subject: [PATCH 08/12] Destination config
---
docs/resources/deployment.md | 17 ++++++++++++++++-
examples/deployments/main.tf | 3 +++
internal/provider/deployment_resource.go | 16 ++++++++++++----
.../provider/models/deployment_api_model.go | 13 ++++++++++++-
.../models/deployment_resource_model.go | 13 ++++++++++++-
internal/provider/models/translate.go | 10 ++++++++++
6 files changed, 65 insertions(+), 7 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index 67f33de..d487b1a 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -17,6 +17,7 @@ Artie Deployment resource
### Required
+- `destination_config` (Attributes) (see [below for nested schema](#nestedatt--destination_config))
- `name` (String)
- `source` (Attributes) (see [below for nested schema](#nestedatt--source))
@@ -24,7 +25,6 @@ Artie Deployment resource
- `advanced_settings` (Attributes) (see [below for nested schema](#nestedatt--advanced_settings))
- `status` (String)
-- `unique_config` (Map of String)
### Read-Only
@@ -33,6 +33,21 @@ Artie Deployment resource
- `last_updated_at` (String)
- `uuid` (String)
+
+### Nested Schema for `destination_config`
+
+Optional:
+
+- `bucket_name` (String)
+- `database` (String)
+- `dataset` (String)
+- `optional_prefix` (String)
+- `schema` (String)
+- `schema_name_prefix` (String)
+- `schema_override` (String)
+- `use_same_schema_as_source` (Boolean)
+
+
### Nested Schema for `source`
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index 963eadf..d88998e 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -39,6 +39,9 @@ resource "artie_deployment" "example" {
}
]
}
+ destination_config = {
+ dataset = "customers"
+ }
advanced_settings = {
enable_soft_delete = true
}
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index e20df32..018703e 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
- "github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
@@ -97,9 +96,18 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"flush_size_kb": schema.Int64Attribute{Optional: true, Computed: true},
},
},
- "unique_config": schema.MapAttribute{
- Optional: true,
- ElementType: types.StringType,
+ "destination_config": schema.SingleNestedAttribute{
+ Required: true,
+ Attributes: map[string]schema.Attribute{
+ "database": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "schema": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "dataset": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "use_same_schema_as_source": schema.BoolAttribute{Optional: true, Computed: true, Default: booldefault.StaticBool(false)},
+ "schema_name_prefix": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "schema_override": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "bucket_name": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "optional_prefix": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ },
},
},
}
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
index 900d564..5c276d2 100644
--- a/internal/provider/models/deployment_api_model.go
+++ b/internal/provider/models/deployment_api_model.go
@@ -13,7 +13,7 @@ type DeploymentAPIModel struct {
HasUndeployedChanges bool `json:"hasUndeployedChanges"`
Source SourceAPIModel `json:"source"`
AdvancedSettings DeploymentAdvancedSettingsAPIModel `json:"advancedSettings"`
- UniqueConfig map[string]any `json:"uniqueConfig"`
+ DestinationConfig DestinationConfigAPIModel `json:"uniqueConfig"`
}
type SourceAPIModel struct {
@@ -71,3 +71,14 @@ type DeploymentAdvancedSettingsAPIModel struct {
// PublicationAutoCreateMode
// PartitionRegex
}
+
+type DestinationConfigAPIModel struct {
+ Dataset string `json:"dataset"`
+ Database string `json:"database"`
+ Schema string `json:"schema"`
+ SchemaOverride string `json:"schemaOverride"`
+ UseSameSchemaAsSource bool `json:"useSameSchemaAsSource"`
+ SchemaNamePrefix string `json:"schemaNamePrefix"`
+ BucketName string `json:"bucketName"`
+ OptionalPrefix string `json:"optionalPrefix"`
+}
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index ad7f5a0..b0ab084 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -11,7 +11,7 @@ type DeploymentResourceModel struct {
HasUndeployedChanges types.Bool `tfsdk:"has_undeployed_changes"`
Source *SourceModel `tfsdk:"source"`
AdvancedSettings *DeploymentAdvancedSettingsModel `tfsdk:"advanced_settings"`
- UniqueConfig types.Map `tfsdk:"unique_config"`
+ DestinationConfig *DestinationConfigModel `tfsdk:"destination_config"`
}
type SourceModel struct {
@@ -69,3 +69,14 @@ type DeploymentAdvancedSettingsModel struct {
// PublicationAutoCreateMode
// PartitionRegex
}
+
+type DestinationConfigModel struct {
+ Dataset types.String `tfsdk:"dataset"`
+ Database types.String `tfsdk:"database"`
+ Schema types.String `tfsdk:"schema"`
+ SchemaOverride types.String `tfsdk:"schema_override"`
+ UseSameSchemaAsSource types.Bool `tfsdk:"use_same_schema_as_source"`
+ SchemaNamePrefix types.String `tfsdk:"schema_name_prefix"`
+ BucketName types.String `tfsdk:"bucket_name"`
+ OptionalPrefix types.String `tfsdk:"optional_prefix"`
+}
diff --git a/internal/provider/models/translate.go b/internal/provider/models/translate.go
index c911dfe..6554e20 100644
--- a/internal/provider/models/translate.go
+++ b/internal/provider/models/translate.go
@@ -37,6 +37,16 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
},
Tables: tables,
}
+ resourceModel.DestinationConfig = &DestinationConfigModel{
+ Dataset: types.StringValue(apiModel.DestinationConfig.Dataset),
+ Database: types.StringValue(apiModel.DestinationConfig.Database),
+ Schema: types.StringValue(apiModel.DestinationConfig.Schema),
+ SchemaOverride: types.StringValue(apiModel.DestinationConfig.SchemaOverride),
+ UseSameSchemaAsSource: types.BoolValue(apiModel.DestinationConfig.UseSameSchemaAsSource),
+ SchemaNamePrefix: types.StringValue(apiModel.DestinationConfig.SchemaNamePrefix),
+ BucketName: types.StringValue(apiModel.DestinationConfig.BucketName),
+ OptionalPrefix: types.StringValue(apiModel.DestinationConfig.OptionalPrefix),
+ }
resourceModel.AdvancedSettings = &DeploymentAdvancedSettingsModel{
DropDeletedColumns: types.BoolValue(apiModel.AdvancedSettings.DropDeletedColumns),
IncludeArtieUpdatedAtColumn: types.BoolValue(apiModel.AdvancedSettings.IncludeArtieUpdatedAtColumn),
From 7317d34cd2013d09cd5abf2b55ae1c97a29a32f8 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 14:35:08 -0700
Subject: [PATCH 09/12] Snapshot host & dynamodb config
---
docs/resources/deployment.md | 17 ++++++++++++++
internal/provider/deployment_resource.go | 19 ++++++++++++----
.../provider/models/deployment_api_model.go | 22 +++++++++++++------
.../models/deployment_resource_model.go | 22 +++++++++++++------
internal/provider/models/translate.go | 16 ++++++++++----
5 files changed, 74 insertions(+), 22 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index d487b1a..e4abced 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -67,6 +67,23 @@ Required:
- `port` (Number)
- `user` (String)
+Optional:
+
+- `dynamodb` (Attributes) (see [below for nested schema](#nestedatt--source--config--dynamodb))
+- `snapshot_host` (String)
+
+
+### Nested Schema for `source.config.dynamodb`
+
+Optional:
+
+- `aws_access_key_id` (String)
+- `aws_secret_access_key` (String)
+- `region` (String)
+- `streams_arn` (String)
+- `table_name` (String)
+
+
### Nested Schema for `source.tables`
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index 018703e..c1cb07f 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -51,10 +51,21 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"config": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
- "host": schema.StringAttribute{Required: true},
- "port": schema.Int64Attribute{Required: true},
- "user": schema.StringAttribute{Required: true},
- "database": schema.StringAttribute{Required: true},
+ "host": schema.StringAttribute{Required: true},
+ "snapshot_host": schema.StringAttribute{Optional: true},
+ "port": schema.Int64Attribute{Required: true},
+ "user": schema.StringAttribute{Required: true},
+ "database": schema.StringAttribute{Required: true},
+ "dynamodb": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "region": schema.StringAttribute{Optional: true},
+ "table_name": schema.StringAttribute{Optional: true},
+ "streams_arn": schema.StringAttribute{Optional: true},
+ "aws_access_key_id": schema.StringAttribute{Optional: true},
+ "aws_secret_access_key": schema.StringAttribute{Optional: true},
+ },
+ },
},
},
"tables": schema.ListNestedAttribute{
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
index 5c276d2..7955ae6 100644
--- a/internal/provider/models/deployment_api_model.go
+++ b/internal/provider/models/deployment_api_model.go
@@ -23,13 +23,21 @@ type SourceAPIModel struct {
}
type SourceConfigAPIModel struct {
- Host string `json:"host"`
- Port int64 `json:"port"`
- User string `json:"user"`
- Database string `json:"database"`
- // Password
- // DynamoDBConfig
- // SnapshotHost
+ Host string `json:"host"`
+ SnapshotHost string `json:"snapshotHost"`
+ Port int64 `json:"port"`
+ User string `json:"user"`
+ Database string `json:"database"`
+ DynamoDB DynamoDBConfigAPIModel `json:"dynamodb"`
+ // TODO Password
+}
+
+type DynamoDBConfigAPIModel struct {
+ Region string `json:"region"`
+ TableName string `json:"tableName"`
+ StreamsArn string `json:"streamsArn"`
+ AwsAccessKeyID string `json:"awsAccessKeyId"`
+ AwsSecretAccessKey string `json:"awsSecretAccessKey"`
}
type TableAPIModel struct {
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index b0ab084..52df32b 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -21,13 +21,21 @@ type SourceModel struct {
}
type SourceConfigModel struct {
- Host types.String `tfsdk:"host"`
- Port types.Int64 `tfsdk:"port"`
- User types.String `tfsdk:"user"`
- Database types.String `tfsdk:"database"`
- // Password
- // DynamoDBConfig
- // SnapshotHost
+ Host types.String `tfsdk:"host"`
+ SnapshotHost types.String `tfsdk:"snapshot_host"`
+ Port types.Int64 `tfsdk:"port"`
+ User types.String `tfsdk:"user"`
+ Database types.String `tfsdk:"database"`
+ DynamoDB *DynamoDBConfigModel `tfsdk:"dynamodb"`
+ // TODO Password
+}
+
+type DynamoDBConfigModel struct {
+ Region types.String `tfsdk:"region"`
+ TableName types.String `tfsdk:"table_name"`
+ StreamsArn types.String `tfsdk:"streams_arn"`
+ AwsAccessKeyID types.String `tfsdk:"aws_access_key_id"`
+ AwsSecretAccessKey types.String `tfsdk:"aws_secret_access_key"`
}
type TableModel struct {
diff --git a/internal/provider/models/translate.go b/internal/provider/models/translate.go
index 6554e20..7b16bfc 100644
--- a/internal/provider/models/translate.go
+++ b/internal/provider/models/translate.go
@@ -30,10 +30,18 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
resourceModel.Source = &SourceModel{
Name: types.StringValue(apiModel.Source.Name),
Config: SourceConfigModel{
- Host: types.StringValue(apiModel.Source.Config.Host),
- Port: types.Int64Value(apiModel.Source.Config.Port),
- User: types.StringValue(apiModel.Source.Config.User),
- Database: types.StringValue(apiModel.Source.Config.Database),
+ Host: types.StringValue(apiModel.Source.Config.Host),
+ SnapshotHost: types.StringValue(apiModel.Source.Config.SnapshotHost),
+ Port: types.Int64Value(apiModel.Source.Config.Port),
+ User: types.StringValue(apiModel.Source.Config.User),
+ Database: types.StringValue(apiModel.Source.Config.Database),
+ DynamoDB: &DynamoDBConfigModel{
+ Region: types.StringValue(apiModel.Source.Config.DynamoDB.Region),
+ TableName: types.StringValue(apiModel.Source.Config.DynamoDB.TableName),
+ StreamsArn: types.StringValue(apiModel.Source.Config.DynamoDB.StreamsArn),
+ AwsAccessKeyID: types.StringValue(apiModel.Source.Config.DynamoDB.AwsAccessKeyID),
+ AwsSecretAccessKey: types.StringValue(apiModel.Source.Config.DynamoDB.AwsSecretAccessKey),
+ },
},
Tables: tables,
}
From f9cd8a904df1bff9528a1900deb092b3020b6da8 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 14:40:31 -0700
Subject: [PATCH 10/12] More advanced settings
---
docs/resources/deployment.md | 3 +++
internal/provider/deployment_resource.go | 3 +++
.../provider/models/deployment_api_model.go | 24 +++++++++----------
.../models/deployment_resource_model.go | 24 +++++++++----------
internal/provider/models/translate.go | 3 +++
5 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index e4abced..034538d 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -131,3 +131,6 @@ Optional:
- `flush_size_kb` (Number)
- `include_artie_updated_at_column` (Boolean)
- `include_database_updated_at_column` (Boolean)
+- `publication_auto_create_mode` (String)
+- `publication_name_override` (String)
+- `replication_slot_override` (String)
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index c1cb07f..e86901d 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -105,6 +105,9 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"flush_interval_seconds": schema.Int64Attribute{Optional: true, Computed: true},
"buffer_rows": schema.Int64Attribute{Optional: true, Computed: true},
"flush_size_kb": schema.Int64Attribute{Optional: true, Computed: true},
+ "publication_name_override": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "replication_slot_override": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ "publication_auto_create_mode": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
},
},
"destination_config": schema.SingleNestedAttribute{
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
index 7955ae6..53c9eed 100644
--- a/internal/provider/models/deployment_api_model.go
+++ b/internal/provider/models/deployment_api_model.go
@@ -66,18 +66,18 @@ type TableAdvancedSettingsAPIModel struct {
}
type DeploymentAdvancedSettingsAPIModel struct {
- DropDeletedColumns bool `json:"drop_deleted_columns"`
- IncludeArtieUpdatedAtColumn bool `json:"include_artie_updated_at_column"`
- IncludeDatabaseUpdatedAtColumn bool `json:"include_database_updated_at_column"`
- EnableHeartbeats bool `json:"enable_heartbeats"`
- EnableSoftDelete bool `json:"enable_soft_delete"`
- FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
- BufferRows int64 `json:"buffer_rows"`
- FlushSizeKB int64 `json:"flush_size_kb"`
- // PublicationNameOverride
- // ReplicationSlotOverride
- // PublicationAutoCreateMode
- // PartitionRegex
+ DropDeletedColumns bool `json:"drop_deleted_columns"`
+ IncludeArtieUpdatedAtColumn bool `json:"include_artie_updated_at_column"`
+ IncludeDatabaseUpdatedAtColumn bool `json:"include_database_updated_at_column"`
+ EnableHeartbeats bool `json:"enable_heartbeats"`
+ EnableSoftDelete bool `json:"enable_soft_delete"`
+ FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
+ BufferRows int64 `json:"buffer_rows"`
+ FlushSizeKB int64 `json:"flush_size_kb"`
+ PublicationNameOverride string `json:"publicationNameOverride"`
+ ReplicationSlotOverride string `json:"replicationSlotOverride"`
+ PublicationAutoCreateMode string `json:"publicationAutoCreateMode"`
+ // TODO PartitionRegex
}
type DestinationConfigAPIModel struct {
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index 52df32b..6065ca7 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -64,18 +64,18 @@ type TableAdvancedSettingsModel struct {
}
type DeploymentAdvancedSettingsModel struct {
- DropDeletedColumns types.Bool `tfsdk:"drop_deleted_columns"`
- IncludeArtieUpdatedAtColumn types.Bool `tfsdk:"include_artie_updated_at_column"`
- IncludeDatabaseUpdatedAtColumn types.Bool `tfsdk:"include_database_updated_at_column"`
- EnableHeartbeats types.Bool `tfsdk:"enable_heartbeats"`
- EnableSoftDelete types.Bool `tfsdk:"enable_soft_delete"`
- FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
- BufferRows types.Int64 `tfsdk:"buffer_rows"`
- FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
- // PublicationNameOverride
- // ReplicationSlotOverride
- // PublicationAutoCreateMode
- // PartitionRegex
+ DropDeletedColumns types.Bool `tfsdk:"drop_deleted_columns"`
+ IncludeArtieUpdatedAtColumn types.Bool `tfsdk:"include_artie_updated_at_column"`
+ IncludeDatabaseUpdatedAtColumn types.Bool `tfsdk:"include_database_updated_at_column"`
+ EnableHeartbeats types.Bool `tfsdk:"enable_heartbeats"`
+ EnableSoftDelete types.Bool `tfsdk:"enable_soft_delete"`
+ FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
+ BufferRows types.Int64 `tfsdk:"buffer_rows"`
+ FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
+ PublicationNameOverride types.String `tfsdk:"publication_name_override"`
+ ReplicationSlotOverride types.String `tfsdk:"replication_slot_override"`
+ PublicationAutoCreateMode types.String `tfsdk:"publication_auto_create_mode"`
+ // TODO PartitionRegex
}
type DestinationConfigModel struct {
diff --git a/internal/provider/models/translate.go b/internal/provider/models/translate.go
index 7b16bfc..65762da 100644
--- a/internal/provider/models/translate.go
+++ b/internal/provider/models/translate.go
@@ -64,5 +64,8 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
FlushIntervalSeconds: types.Int64Value(apiModel.AdvancedSettings.FlushIntervalSeconds),
BufferRows: types.Int64Value(apiModel.AdvancedSettings.BufferRows),
FlushSizeKB: types.Int64Value(apiModel.AdvancedSettings.FlushSizeKB),
+ PublicationNameOverride: types.StringValue(apiModel.AdvancedSettings.PublicationNameOverride),
+ ReplicationSlotOverride: types.StringValue(apiModel.AdvancedSettings.ReplicationSlotOverride),
+ PublicationAutoCreateMode: types.StringValue(apiModel.AdvancedSettings.PublicationAutoCreateMode),
}
}
From c2cf828d1e857b1ebd0329d13d865fc5ae6a637f Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 14:52:49 -0700
Subject: [PATCH 11/12] More table advanced settings
---
docs/resources/deployment.md | 4 +++
examples/deployments/main.tf | 3 +-
internal/provider/deployment_resource.go | 4 +++
.../provider/models/deployment_api_model.go | 32 +++++++++----------
.../models/deployment_resource_model.go | 8 ++---
internal/provider/models/translate.go | 4 +++
6 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index 034538d..f8dce28 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -110,9 +110,13 @@ Read-Only:
Optional:
- `alias` (String)
+- `autoscale_max_replicas` (Number)
+- `autoscale_target_value` (Number)
- `buffer_rows` (Number)
- `flush_interval_seconds` (Number)
- `flush_size_kb` (Number)
+- `k8s_request_cpu` (Number)
+- `k8s_request_memory_mb` (Number)
- `skip_delete` (Boolean)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index d88998e..e3cd1b1 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -43,7 +43,8 @@ resource "artie_deployment" "example" {
dataset = "customers"
}
advanced_settings = {
- enable_soft_delete = true
+ enable_soft_delete = true
+ flush_interval_seconds = 60
}
}
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index e86901d..7173836 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -86,6 +86,10 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"flush_interval_seconds": schema.Int64Attribute{Optional: true, Computed: true},
"buffer_rows": schema.Int64Attribute{Optional: true, Computed: true},
"flush_size_kb": schema.Int64Attribute{Optional: true, Computed: true},
+ "autoscale_max_replicas": schema.Int64Attribute{Optional: true, Computed: true},
+ "autoscale_target_value": schema.Int64Attribute{Optional: true, Computed: true},
+ "k8s_request_cpu": schema.Int64Attribute{Optional: true, Computed: true},
+ "k8s_request_memory_mb": schema.Int64Attribute{Optional: true, Computed: true},
},
Computed: true,
},
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
index 53c9eed..8ee24a7 100644
--- a/internal/provider/models/deployment_api_model.go
+++ b/internal/provider/models/deployment_api_model.go
@@ -52,28 +52,28 @@ type TableAPIModel struct {
type TableAdvancedSettingsAPIModel struct {
Alias string `json:"alias"`
- SkipDelete bool `json:"skip_delete"`
- FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
- BufferRows int64 `json:"buffer_rows"`
- FlushSizeKB int64 `json:"flush_size_kb"`
+ SkipDelete bool `json:"skipDelete"`
+ FlushIntervalSeconds int64 `json:"flushIntervalSeconds"`
+ BufferRows int64 `json:"bufferRows"`
+ FlushSizeKB int64 `json:"flushSizeKb"`
// BigQueryPartitionSettings
// MergePredicates
- // AutoscaleMaxReplicas
- // AutoscaleTargetValue
- // K8sRequestCPU
- // K8sRequestMemoryMB
+ AutoscaleMaxReplicas int64 `json:"autoscaleMaxReplicas"`
+ AutoscaleTargetValue int64 `json:"autoscaleTargetValue"`
+ K8sRequestCPU int64 `json:"k8sRequestCPU"`
+ K8sRequestMemoryMB int64 `json:"k8sRequestMemoryMB"`
// ExcludeColumns
}
type DeploymentAdvancedSettingsAPIModel struct {
- DropDeletedColumns bool `json:"drop_deleted_columns"`
- IncludeArtieUpdatedAtColumn bool `json:"include_artie_updated_at_column"`
- IncludeDatabaseUpdatedAtColumn bool `json:"include_database_updated_at_column"`
- EnableHeartbeats bool `json:"enable_heartbeats"`
- EnableSoftDelete bool `json:"enable_soft_delete"`
- FlushIntervalSeconds int64 `json:"flush_interval_seconds"`
- BufferRows int64 `json:"buffer_rows"`
- FlushSizeKB int64 `json:"flush_size_kb"`
+ DropDeletedColumns bool `json:"dropDeletedColumns"`
+ IncludeArtieUpdatedAtColumn bool `json:"includeArtieUpdatedAtColumn"`
+ IncludeDatabaseUpdatedAtColumn bool `json:"includeDatabaseUpdatedAtColumn"`
+ EnableHeartbeats bool `json:"enableHeartbeats"`
+ EnableSoftDelete bool `json:"enableSoftDelete"`
+ FlushIntervalSeconds int64 `json:"flushIntervalSeconds"`
+ BufferRows int64 `json:"bufferRows"`
+ FlushSizeKB int64 `json:"flushSizeKb"`
PublicationNameOverride string `json:"publicationNameOverride"`
ReplicationSlotOverride string `json:"replicationSlotOverride"`
PublicationAutoCreateMode string `json:"publicationAutoCreateMode"`
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index 6065ca7..6cddc97 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -56,10 +56,10 @@ type TableAdvancedSettingsModel struct {
FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
// BigQueryPartitionSettings
// MergePredicates
- // AutoscaleMaxReplicas
- // AutoscaleTargetValue
- // K8sRequestCPU
- // K8sRequestMemoryMB
+ AutoscaleMaxReplicas types.Int64 `tfsdk:"autoscale_max_replicas"`
+ AutoscaleTargetValue types.Int64 `tfsdk:"autoscale_target_value"`
+ K8sRequestCPU types.Int64 `tfsdk:"k8s_request_cpu"`
+ K8sRequestMemoryMB types.Int64 `tfsdk:"k8s_request_memory_mb"`
// ExcludeColumns
}
diff --git a/internal/provider/models/translate.go b/internal/provider/models/translate.go
index 65762da..e9b2572 100644
--- a/internal/provider/models/translate.go
+++ b/internal/provider/models/translate.go
@@ -24,6 +24,10 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
FlushIntervalSeconds: types.Int64Value(apiTable.AdvancedSettings.FlushIntervalSeconds),
BufferRows: types.Int64Value(apiTable.AdvancedSettings.BufferRows),
FlushSizeKB: types.Int64Value(apiTable.AdvancedSettings.FlushSizeKB),
+ AutoscaleMaxReplicas: types.Int64Value(apiTable.AdvancedSettings.AutoscaleMaxReplicas),
+ AutoscaleTargetValue: types.Int64Value(apiTable.AdvancedSettings.AutoscaleTargetValue),
+ K8sRequestCPU: types.Int64Value(apiTable.AdvancedSettings.K8sRequestCPU),
+ K8sRequestMemoryMB: types.Int64Value(apiTable.AdvancedSettings.K8sRequestMemoryMB),
},
})
}
From 71cf4a7801f8c855d12d0626a183c8ff1b4062ef Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Wed, 24 Jul 2024 14:56:25 -0700
Subject: [PATCH 12/12] Todos
---
internal/provider/deployment_resource.go | 3 +++
internal/provider/models/deployment_api_model.go | 12 +++++-------
.../provider/models/deployment_resource_model.go | 12 +++++-------
internal/provider/models/translate.go | 3 +++
4 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index 7173836..44561a3 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -66,6 +66,7 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"aws_secret_access_key": schema.StringAttribute{Optional: true},
},
},
+ // TODO Password
},
},
"tables": schema.ListNestedAttribute{
@@ -90,6 +91,7 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"autoscale_target_value": schema.Int64Attribute{Optional: true, Computed: true},
"k8s_request_cpu": schema.Int64Attribute{Optional: true, Computed: true},
"k8s_request_memory_mb": schema.Int64Attribute{Optional: true, Computed: true},
+ // TODO BigQueryPartitionSettings, MergePredicates, ExcludeColumns
},
Computed: true,
},
@@ -112,6 +114,7 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"publication_name_override": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
"replication_slot_override": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
"publication_auto_create_mode": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
+ // TODO PartitionRegex
},
},
"destination_config": schema.SingleNestedAttribute{
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
index 8ee24a7..f9d3324 100644
--- a/internal/provider/models/deployment_api_model.go
+++ b/internal/provider/models/deployment_api_model.go
@@ -56,13 +56,11 @@ type TableAdvancedSettingsAPIModel struct {
FlushIntervalSeconds int64 `json:"flushIntervalSeconds"`
BufferRows int64 `json:"bufferRows"`
FlushSizeKB int64 `json:"flushSizeKb"`
- // BigQueryPartitionSettings
- // MergePredicates
- AutoscaleMaxReplicas int64 `json:"autoscaleMaxReplicas"`
- AutoscaleTargetValue int64 `json:"autoscaleTargetValue"`
- K8sRequestCPU int64 `json:"k8sRequestCPU"`
- K8sRequestMemoryMB int64 `json:"k8sRequestMemoryMB"`
- // ExcludeColumns
+ AutoscaleMaxReplicas int64 `json:"autoscaleMaxReplicas"`
+ AutoscaleTargetValue int64 `json:"autoscaleTargetValue"`
+ K8sRequestCPU int64 `json:"k8sRequestCPU"`
+ K8sRequestMemoryMB int64 `json:"k8sRequestMemoryMB"`
+ // TODO BigQueryPartitionSettings, MergePredicates, ExcludeColumns
}
type DeploymentAdvancedSettingsAPIModel struct {
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index 6cddc97..9b1c49c 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -54,13 +54,11 @@ type TableAdvancedSettingsModel struct {
FlushIntervalSeconds types.Int64 `tfsdk:"flush_interval_seconds"`
BufferRows types.Int64 `tfsdk:"buffer_rows"`
FlushSizeKB types.Int64 `tfsdk:"flush_size_kb"`
- // BigQueryPartitionSettings
- // MergePredicates
- AutoscaleMaxReplicas types.Int64 `tfsdk:"autoscale_max_replicas"`
- AutoscaleTargetValue types.Int64 `tfsdk:"autoscale_target_value"`
- K8sRequestCPU types.Int64 `tfsdk:"k8s_request_cpu"`
- K8sRequestMemoryMB types.Int64 `tfsdk:"k8s_request_memory_mb"`
- // ExcludeColumns
+ AutoscaleMaxReplicas types.Int64 `tfsdk:"autoscale_max_replicas"`
+ AutoscaleTargetValue types.Int64 `tfsdk:"autoscale_target_value"`
+ K8sRequestCPU types.Int64 `tfsdk:"k8s_request_cpu"`
+ K8sRequestMemoryMB types.Int64 `tfsdk:"k8s_request_memory_mb"`
+ // TODO BigQueryPartitionSettings, MergePredicates, ExcludeColumns
}
type DeploymentAdvancedSettingsModel struct {
diff --git a/internal/provider/models/translate.go b/internal/provider/models/translate.go
index e9b2572..e6ba9de 100644
--- a/internal/provider/models/translate.go
+++ b/internal/provider/models/translate.go
@@ -28,6 +28,7 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
AutoscaleTargetValue: types.Int64Value(apiTable.AdvancedSettings.AutoscaleTargetValue),
K8sRequestCPU: types.Int64Value(apiTable.AdvancedSettings.K8sRequestCPU),
K8sRequestMemoryMB: types.Int64Value(apiTable.AdvancedSettings.K8sRequestMemoryMB),
+ // TODO BigQueryPartitionSettings, MergePredicates, ExcludeColumns
},
})
}
@@ -46,6 +47,7 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
AwsAccessKeyID: types.StringValue(apiModel.Source.Config.DynamoDB.AwsAccessKeyID),
AwsSecretAccessKey: types.StringValue(apiModel.Source.Config.DynamoDB.AwsSecretAccessKey),
},
+ // TODO Password
},
Tables: tables,
}
@@ -71,5 +73,6 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
PublicationNameOverride: types.StringValue(apiModel.AdvancedSettings.PublicationNameOverride),
ReplicationSlotOverride: types.StringValue(apiModel.AdvancedSettings.ReplicationSlotOverride),
PublicationAutoCreateMode: types.StringValue(apiModel.AdvancedSettings.PublicationAutoCreateMode),
+ // TODO PartitionRegex
}
}