diff --git a/.changelog/29470.txt b/.changelog/29470.txt new file mode 100644 index 000000000000..77a2333bc515 --- /dev/null +++ b/.changelog/29470.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_dms_endpoint: Add `elasticsearch_settings.use_new_mapping_type` argument +``` \ No newline at end of file diff --git a/internal/service/dms/endpoint.go b/internal/service/dms/endpoint.go index 0d5974108653..c150396f45c2 100644 --- a/internal/service/dms/endpoint.go +++ b/internal/service/dms/endpoint.go @@ -68,35 +68,33 @@ func ResourceEndpoint() *schema.Resource { "endpoint_uri": { Type: schema.TypeString, Required: true, - // API returns this error with ModifyEndpoint: - // InvalidParameterCombinationException: OpenSearch endpoint cant be modified. ForceNew: true, }, "error_retry_duration": { Type: schema.TypeInt, Optional: true, + ForceNew: true, Default: 300, ValidateFunc: validation.IntAtLeast(0), - // API returns this error with ModifyEndpoint: - // InvalidParameterCombinationException: OpenSearch endpoint cant be modified. - ForceNew: true, }, "full_load_error_percentage": { Type: schema.TypeInt, Optional: true, + ForceNew: true, Default: 10, ValidateFunc: validation.IntBetween(0, 100), - // API returns this error with ModifyEndpoint: - // InvalidParameterCombinationException: OpenSearch endpoint cant be modified. - ForceNew: true, }, "service_access_role_arn": { Type: schema.TypeString, Required: true, + ForceNew: true, ValidateFunc: verify.ValidARN, - // API returns this error with ModifyEndpoint: - // InvalidParameterCombinationException: OpenSearch endpoint cant be modified. + }, + "use_new_mapping_type": { + Type: schema.TypeBool, + Optional: true, ForceNew: true, + Default: false, }, }, }, @@ -857,6 +855,7 @@ func resourceEndpointCreate(ctx context.Context, d *schema.ResourceData, meta in EndpointUri: aws.String(d.Get("elasticsearch_settings.0.endpoint_uri").(string)), ErrorRetryDuration: aws.Int64(int64(d.Get("elasticsearch_settings.0.error_retry_duration").(int))), FullLoadErrorPercentage: aws.Int64(int64(d.Get("elasticsearch_settings.0.full_load_error_percentage").(int))), + UseNewMappingType: aws.Bool(d.Get("elasticsearch_settings.0.use_new_mapping_type").(bool)), } case engineNameKafka: input.KafkaSettings = expandKafkaSettings(d.Get("kafka_settings").([]interface{})[0].(map[string]interface{})) @@ -1147,12 +1146,14 @@ func resourceEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta in "elasticsearch_settings.0.endpoint_uri", "elasticsearch_settings.0.error_retry_duration", "elasticsearch_settings.0.full_load_error_percentage", - "elasticsearch_settings.0.service_access_role_arn") { + "elasticsearch_settings.0.service_access_role_arn", + "elasticsearch_settings.0.use_new_mapping_type") { input.ElasticsearchSettings = &dms.ElasticsearchSettings{ ServiceAccessRoleArn: aws.String(d.Get("elasticsearch_settings.0.service_access_role_arn").(string)), EndpointUri: aws.String(d.Get("elasticsearch_settings.0.endpoint_uri").(string)), ErrorRetryDuration: aws.Int64(int64(d.Get("elasticsearch_settings.0.error_retry_duration").(int))), FullLoadErrorPercentage: aws.Int64(int64(d.Get("elasticsearch_settings.0.full_load_error_percentage").(int))), + UseNewMappingType: aws.Bool(d.Get("elasticsearch_settings.0.use_new_mapping_type").(bool)), } input.EngineName = aws.String(engineName) } @@ -1783,6 +1784,7 @@ func flattenOpenSearchSettings(settings *dms.ElasticsearchSettings) []map[string "error_retry_duration": aws.Int64Value(settings.ErrorRetryDuration), "full_load_error_percentage": aws.Int64Value(settings.FullLoadErrorPercentage), "service_access_role_arn": aws.StringValue(settings.ServiceAccessRoleArn), + "use_new_mapping_type": aws.BoolValue(settings.UseNewMappingType), } return []map[string]interface{}{m} diff --git a/internal/service/dms/endpoint_test.go b/internal/service/dms/endpoint_test.go index 8dc8d0d08d18..8c41537fa035 100644 --- a/internal/service/dms/endpoint_test.go +++ b/internal/service/dms/endpoint_test.go @@ -573,6 +573,7 @@ func TestAccDMSEndpoint_OpenSearch_basic(t *testing.T) { testAccCheckResourceAttrRegionalHostname(resourceName, "elasticsearch_settings.0.endpoint_uri", "es", "search-estest"), resource.TestCheckResourceAttr(resourceName, "elasticsearch_settings.0.full_load_error_percentage", "10"), resource.TestCheckResourceAttr(resourceName, "elasticsearch_settings.0.error_retry_duration", "300"), + resource.TestCheckResourceAttr(resourceName, "elasticsearch_settings.0.use_new_mapping_type", "false"), ), }, { @@ -656,6 +657,35 @@ func TestAccDMSEndpoint_OpenSearch_errorRetryDuration(t *testing.T) { }) } +func TestAccDMSEndpoint_OpenSearch_UseNewMappingType(t *testing.T) { + ctx := acctest.Context(t) + resourceName := "aws_dms_endpoint.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, dms.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckEndpointDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccEndpointConfig_openSearchUseNewMappingType(rName, true), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckEndpointExists(ctx, resourceName), + resource.TestCheckResourceAttr(resourceName, "elasticsearch_settings.#", "1"), + resource.TestCheckResourceAttr(resourceName, "elasticsearch_settings.0.use_new_mapping_type", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"password"}, + }, + }, + }) +} + func TestAccDMSEndpoint_OpenSearch_fullLoadErrorPercentage(t *testing.T) { ctx := acctest.Context(t) resourceName := "aws_dms_endpoint.test" @@ -3337,6 +3367,26 @@ resource "aws_dms_endpoint" "test" { `, rName, errorRetryDuration)) } +func testAccEndpointConfig_openSearchUseNewMappingType(rName string, useNewMappingType bool) string { + return acctest.ConfigCompose( + testAccEndpointConfig_openSearchBase(rName), + fmt.Sprintf(` +resource "aws_dms_endpoint" "test" { + endpoint_id = %[1]q + endpoint_type = "target" + engine_name = "elasticsearch" + + elasticsearch_settings { + endpoint_uri = "search-estest.${data.aws_region.current.name}.es.${data.aws_partition.current.dns_suffix}" + use_new_mapping_type = %[2]t + service_access_role_arn = aws_iam_role.test.arn + } + + depends_on = [aws_iam_role_policy.test] +} +`, rName, useNewMappingType)) +} + func testAccEndpointConfig_openSearchFullLoadErrorPercentage(rName string, fullLoadErrorPercentage int) string { return acctest.ConfigCompose( testAccEndpointConfig_openSearchBase(rName), diff --git a/website/docs/r/dms_endpoint.html.markdown b/website/docs/r/dms_endpoint.html.markdown index 191b0af20709..5fbc5319642d 100644 --- a/website/docs/r/dms_endpoint.html.markdown +++ b/website/docs/r/dms_endpoint.html.markdown @@ -79,6 +79,7 @@ The following arguments are optional: * `error_retry_duration` - (Optional) Maximum number of seconds for which DMS retries failed API requests to the OpenSearch cluster. Default is `300`. * `full_load_error_percentage` - (Optional) Maximum percentage of records that can fail to be written before a full load operation stops. Default is `10`. * `service_access_role_arn` - (Required) ARN of the IAM Role with permissions to write to the OpenSearch cluster. +* `use_new_mapping_type` - (Optional) Enable to migrate documentation using the documentation type `_doc`. OpenSearch and an Elasticsearch clusters only support the _doc documentation type in versions 7.x and later. The default value is `false`. ### kafka_settings