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

Add new use_new_mapping_type for aws_dms_endpoint #29470

Merged
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
3 changes: 3 additions & 0 deletions .changelog/29470.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_dms_endpoint: Add `elasticsearch_settings.use_new_mapping_type` argument
```
24 changes: 13 additions & 11 deletions internal/service/dms/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down Expand Up @@ -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{}))
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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}
Expand Down
50 changes: 50 additions & 0 deletions internal/service/dms/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/dms_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading