Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update aws_dms_endpoint ressource to support new engines #21174

Merged
merged 5 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/21174.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_dms_endpoint: Added missing `engine_name` values for sources and/or targets
```

```release-note:enhancement
resource/aws_dms_endpoint: Add plan time validation for `mongodb_settings.auth_type`, `mongodb_settings.auth_mechanism`, `mongodb_settings.nesting_level` and `s3_settings.compression_type` arguments
```
104 changes: 104 additions & 0 deletions aws/internal/service/dms/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package dms

const (
EngineNameAurora = "aurora"
EngineNameAuroraPostgresql = "aurora-postgresql"
EngineNameAuroraPostgresqlServerless = "aurora-postgresql-serverless"
EngineNameAuroraServerless = "aurora-serverless"
EngineNameAzuredb = "azuredb"
EngineNameDb2 = "db2"
EngineNameDmsTransfer = "dms-transfer"
EngineNameDocdb = "docdb"
EngineNameDynamodb = "dynamodb"
EngineNameElasticsearch = "elasticsearch"
EngineNameKafka = "kafka"
EngineNameKinesis = "kinesis"
EngineNameMariadb = "mariadb"
EngineNameMongodb = "mongodb"
EngineNameMysql = "mysql"
EngineNameNeptune = "neptune"
EngineNameOpensearch = "opensearch"
EngineNameOracle = "oracle"
EngineNamePostgres = "postgres"
EngineNameRedis = "redis"
EngineNameRedshift = "redshift"
EngineNameS3 = "s3"
EngineNameSqlServer = "sqlserver"
EngineNameSybase = "sybase"
)

func EngineName_Values() []string {
return []string{
EngineNameAurora,
EngineNameAuroraPostgresql,
EngineNameAuroraPostgresqlServerless,
EngineNameAuroraServerless,
EngineNameAzuredb,
EngineNameDb2,
EngineNameDmsTransfer,
EngineNameDocdb,
EngineNameDynamodb,
EngineNameElasticsearch,
EngineNameKafka,
EngineNameKinesis,
EngineNameMariadb,
EngineNameMongodb,
EngineNameMysql,
EngineNameNeptune,
EngineNameOpensearch,
EngineNameOracle,
EngineNamePostgres,
EngineNameRedis,
EngineNameRedshift,
EngineNameS3,
EngineNameSqlServer,
EngineNameSybase,
}
}

const (
KafkaDefaultTopic = "kafka-default-topic"
)

// https://github.com/aws/aws-sdk-go/issues/2522.
const (
MongoDbAuthMechanismValueDefault = "default"
MongoDbAuthMechanismValueMongodbCr = "mongodb-cr"
MongoDbAuthMechanismValueScramSha1 = "scram-sha-1"
)

func MongoDbAuthMechanismValue_Values() []string {
return []string{
MongoDbAuthMechanismValueDefault,
MongoDbAuthMechanismValueMongodbCr,
MongoDbAuthMechanismValueScramSha1,
}
}

const (
MongoDbAuthSourceAdmin = "admin"
)

const (
S3SettingsCompressionTypeGzip = "GZIP"
S3SettingsCompressionTypeNone = "NONE"
)

func S3SettingsCompressionType_Values() []string {
return []string{
S3SettingsCompressionTypeGzip,
S3SettingsCompressionTypeNone,
}
}

const (
S3SettingsEncryptionModeSseKms = "SSE_KMS"
S3SettingsEncryptionModeSseS3 = "SSE_S3"
)

func S3SettingsEncryptionMode_Values() []string {
return []string{
S3SettingsEncryptionModeSseKms,
S3SettingsEncryptionModeSseS3,
}
}
160 changes: 55 additions & 105 deletions aws/resource_aws_dms_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
tfdms "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/dms"
)

func resourceAwsDmsEndpoint() *schema.Resource {
Expand All @@ -39,15 +40,10 @@ func resourceAwsDmsEndpoint() *schema.Resource {
Optional: true,
},
"elasticsearch_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "1" && new == "0" {
return true
}
return false
},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"endpoint_uri": {
Expand Down Expand Up @@ -97,36 +93,14 @@ func resourceAwsDmsEndpoint() *schema.Resource {
ValidateFunc: validateDmsEndpointId,
},
"endpoint_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
dms.ReplicationEndpointTypeValueSource,
dms.ReplicationEndpointTypeValueTarget,
}, false),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(dms.ReplicationEndpointTypeValue_Values(), false),
},
"engine_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"aurora",
"aurora-postgresql",
"azuredb",
"db2",
"docdb",
"dynamodb",
"elasticsearch",
"kafka",
"kinesis",
"mariadb",
"mongodb",
"mysql",
"oracle",
"postgres",
"redshift",
"s3",
"sqlserver",
"sybase",
}, false),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(tfdms.EngineName_Values(), false),
},
"extra_connection_attributes": {
Type: schema.TypeString,
Expand All @@ -135,15 +109,10 @@ func resourceAwsDmsEndpoint() *schema.Resource {
DiffSuppressFunc: suppressExtraConnectionAttributesDiffs,
},
"kafka_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "1" && new == "0" {
return true
}
return false
},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"broker": {
Expand All @@ -154,31 +123,23 @@ func resourceAwsDmsEndpoint() *schema.Resource {
"topic": {
Type: schema.TypeString,
Optional: true,
Default: "kafka-default-topic",
Default: tfdms.KafkaDefaultTopic,
},
},
},
},
"kinesis_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "1" && new == "0" {
return true
}
return false
},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"message_format": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
dms.MessageFormatValueJson,
dms.MessageFormatValueJsonUnformatted,
}, false),
Default: dms.MessageFormatValueJson,
Type: schema.TypeString,
Optional: true,
Default: dms.MessageFormatValueJson,
ValidateFunc: validation.StringInSlice(dms.MessageFormatValue_Values(), false),
},
"service_access_role_arn": {
Type: schema.TypeString,
Expand All @@ -201,31 +162,29 @@ func resourceAwsDmsEndpoint() *schema.Resource {
ValidateFunc: validateArn,
},
"mongodb_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "1" && new == "0" {
return true
}
return false
},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth_type": {
Type: schema.TypeString,
Optional: true,
Default: dms.AuthTypeValuePassword,
Type: schema.TypeString,
Optional: true,
Default: dms.AuthTypeValuePassword,
ValidateFunc: validation.StringInSlice(dms.AuthTypeValue_Values(), false),
},
"auth_mechanism": {
Type: schema.TypeString,
Optional: true,
Default: dms.AuthMechanismValueDefault,
Type: schema.TypeString,
Optional: true,
Default: tfdms.MongoDbAuthMechanismValueDefault,
ValidateFunc: validation.StringInSlice(tfdms.MongoDbAuthMechanismValue_Values(), false),
},
"nesting_level": {
Type: schema.TypeString,
Optional: true,
Default: dms.NestingLevelValueNone,
Type: schema.TypeString,
Optional: true,
Default: dms.NestingLevelValueNone,
ValidateFunc: validation.StringInSlice(dms.NestingLevelValue_Values(), false),
},
"extract_doc_id": {
Type: schema.TypeString,
Expand All @@ -240,7 +199,7 @@ func resourceAwsDmsEndpoint() *schema.Resource {
"auth_source": {
Type: schema.TypeString,
Optional: true,
Default: "admin",
Default: tfdms.MongoDbAuthSourceAdmin,
},
},
},
Expand All @@ -255,15 +214,10 @@ func resourceAwsDmsEndpoint() *schema.Resource {
Optional: true,
},
"s3_settings": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "1" && new == "0" {
return true
}
return false
},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
DiffSuppressFunc: suppressMissingOptionalConfigurationBlock,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_access_role_arn": {
Expand Down Expand Up @@ -297,9 +251,10 @@ func resourceAwsDmsEndpoint() *schema.Resource {
Default: "",
},
"compression_type": {
Type: schema.TypeString,
Optional: true,
Default: "NONE",
Type: schema.TypeString,
Optional: true,
Default: tfdms.S3SettingsCompressionTypeNone,
ValidateFunc: validation.StringInSlice(tfdms.S3SettingsCompressionType_Values(), false),
},
"date_partition_enabled": {
Type: schema.TypeBool,
Expand All @@ -326,8 +281,8 @@ func resourceAwsDmsEndpoint() *schema.Resource {
"encryption_mode": {
Type: schema.TypeString,
Optional: true,
Default: "SSE_S3",
ValidateFunc: validation.StringInSlice([]string{"SSE_S3", "SSE_KMS"}, false),
Default: tfdms.S3SettingsEncryptionModeSseS3,
ValidateFunc: validation.StringInSlice(tfdms.S3SettingsEncryptionMode_Values(), false),
},
"server_side_encryption_kms_key_id": {
Type: schema.TypeString,
Expand All @@ -345,15 +300,10 @@ func resourceAwsDmsEndpoint() *schema.Resource {
Optional: true,
},
"ssl_mode": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
dms.DmsSslModeValueNone,
dms.DmsSslModeValueRequire,
dms.DmsSslModeValueVerifyCa,
dms.DmsSslModeValueVerifyFull,
}, false),
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice(dms.DmsSslModeValue_Values(), false),
},
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
Expand Down