From 88c12e7acf22b3f67457d33c3b400cab9608f9f2 Mon Sep 17 00:00:00 2001 From: Dana Fallon <8871189+danafallon@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:52:56 -0700 Subject: [PATCH] Make dynamo db config optional (nillable in models) --- examples/deployments/main.tf | 2 - .../provider/models/deployment_api_model.go | 14 +++---- .../provider/models/translate_deployment.go | 37 ++++++++++++------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf index f0d3970..8d0752a 100644 --- a/examples/deployments/main.tf +++ b/examples/deployments/main.tf @@ -50,7 +50,6 @@ resource "artie_deployment" "dev_postgres_to_snowflake" { database = "prod_dump_july_2024_4cvzb" user = "doadmin" password = var.postgres_password - dynamodb = {} } tables = [ { @@ -108,7 +107,6 @@ resource "artie_deployment" "dev_postgres_to_snowflake" { # port = 0 # user = "artie" # password = var.mongodb_password -# dynamodb = {} # } # tables = [ # { diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go index 0da911f..b7ab5c5 100644 --- a/internal/provider/models/deployment_api_model.go +++ b/internal/provider/models/deployment_api_model.go @@ -24,13 +24,13 @@ type SourceAPIModel struct { } type SourceConfigAPIModel struct { - Host string `json:"host"` - SnapshotHost string `json:"snapshotHost"` - Port int64 `json:"port"` - User string `json:"user"` - Password string `json:"password"` - Database string `json:"database"` - DynamoDB DynamoDBConfigAPIModel `json:"dynamodb"` + Host string `json:"host"` + SnapshotHost string `json:"snapshotHost"` + Port int64 `json:"port"` + User string `json:"user"` + Password string `json:"password"` + Database string `json:"database"` + DynamoDB *DynamoDBConfigAPIModel `json:"dynamodb"` } type DynamoDBConfigAPIModel struct { diff --git a/internal/provider/models/translate_deployment.go b/internal/provider/models/translate_deployment.go index 253c25e..7b5e553 100644 --- a/internal/provider/models/translate_deployment.go +++ b/internal/provider/models/translate_deployment.go @@ -37,6 +37,16 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De }, }) } + var dynamoDBConfig *DynamoDBConfigModel + if apiModel.Source.Config.DynamoDB != nil { + dynamoDBConfig = &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), + } + } resourceModel.Source = &SourceModel{ Name: types.StringValue(apiModel.Source.Name), Config: SourceConfigModel{ @@ -46,13 +56,7 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De User: types.StringValue(apiModel.Source.Config.User), Password: types.StringValue(apiModel.Source.Config.Password), 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), - }, + DynamoDB: dynamoDBConfig, }, Tables: tables, } @@ -111,6 +115,17 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym }) } + var dynamoDBConfig *DynamoDBConfigAPIModel + if resourceModel.Source.Config.DynamoDB != nil { + dynamoDBConfig = &DynamoDBConfigAPIModel{ + Region: resourceModel.Source.Config.DynamoDB.Region.ValueString(), + TableName: resourceModel.Source.Config.DynamoDB.TableName.ValueString(), + StreamsArn: resourceModel.Source.Config.DynamoDB.StreamsArn.ValueString(), + AwsAccessKeyID: resourceModel.Source.Config.DynamoDB.AwsAccessKeyID.ValueString(), + AwsSecretAccessKey: resourceModel.Source.Config.DynamoDB.AwsSecretAccessKey.ValueString(), + } + } + return DeploymentAPIModel{ UUID: resourceModel.UUID.ValueString(), CompanyUUID: resourceModel.CompanyUUID.ValueString(), @@ -128,13 +143,7 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym User: resourceModel.Source.Config.User.ValueString(), Password: resourceModel.Source.Config.Password.ValueString(), Database: resourceModel.Source.Config.Database.ValueString(), - DynamoDB: DynamoDBConfigAPIModel{ - Region: resourceModel.Source.Config.DynamoDB.Region.ValueString(), - TableName: resourceModel.Source.Config.DynamoDB.TableName.ValueString(), - StreamsArn: resourceModel.Source.Config.DynamoDB.StreamsArn.ValueString(), - AwsAccessKeyID: resourceModel.Source.Config.DynamoDB.AwsAccessKeyID.ValueString(), - AwsSecretAccessKey: resourceModel.Source.Config.DynamoDB.AwsSecretAccessKey.ValueString(), - }, + DynamoDB: dynamoDBConfig, }, Tables: tables, },