diff --git a/.changelog/21174.txt b/.changelog/21174.txt new file mode 100644 index 00000000000..230d607c6e2 --- /dev/null +++ b/.changelog/21174.txt @@ -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 +``` \ No newline at end of file diff --git a/aws/internal/service/dms/enum.go b/aws/internal/service/dms/enum.go new file mode 100644 index 00000000000..61960847a28 --- /dev/null +++ b/aws/internal/service/dms/enum.go @@ -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, + } +} diff --git a/aws/resource_aws_dms_endpoint.go b/aws/resource_aws_dms_endpoint.go index c3e69117fc5..324c0a47974 100644 --- a/aws/resource_aws_dms_endpoint.go +++ b/aws/resource_aws_dms_endpoint.go @@ -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 { @@ -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": { @@ -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, @@ -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": { @@ -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, @@ -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, @@ -240,7 +199,7 @@ func resourceAwsDmsEndpoint() *schema.Resource { "auth_source": { Type: schema.TypeString, Optional: true, - Default: "admin", + Default: tfdms.MongoDbAuthSourceAdmin, }, }, }, @@ -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": { @@ -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, @@ -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, @@ -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(),