Skip to content

Commit

Permalink
Make dynamo db config optional (nillable in models)
Browse files Browse the repository at this point in the history
  • Loading branch information
danafallon committed Jul 30, 2024
1 parent 7c7b5bb commit 88c12e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 0 additions & 2 deletions examples/deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -108,7 +107,6 @@ resource "artie_deployment" "dev_postgres_to_snowflake" {
# port = 0
# user = "artie"
# password = var.mongodb_password
# dynamodb = {}
# }
# tables = [
# {
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 @@ -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 {
Expand Down
37 changes: 23 additions & 14 deletions internal/provider/models/translate_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
}
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
},
Expand Down

0 comments on commit 88c12e7

Please sign in to comment.