Skip to content

Commit 723110f

Browse files
authored
Merge pull request #43440 from dacohen/f-aws_dms_endpoint-authentication_method
Add authentication_method and service_access_role_arn to postgres_settings for aws_dms_endpoint
2 parents f6a66a9 + a03131e commit 723110f

File tree

5 files changed

+83
-9
lines changed

5 files changed

+83
-9
lines changed

.changelog/43440.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
resource/aws_dms_endpoint: Add `postgres_settings.authentication_method` and `postgres_settings.service_access_role_arn` arguments
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_dms_endpoint: Add `postgres_settings.authentication_method` and `postgres_settings.service_access_role_arn` attributes
7+
```
8+
9+
```release-note:enhancement
10+
resource/aws_dms_endpoint: Add plan-time validation of `postgres_settings.database_mode`, `postgres_settings.map_long_varchar_as`, and `postgres_settings.plugin_name` arguments
11+
```

internal/service/dms/endpoint.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ func resourceEndpoint() *schema.Resource {
370370
Type: schema.TypeString,
371371
Optional: true,
372372
},
373+
"authentication_method": {
374+
Type: schema.TypeString,
375+
Optional: true,
376+
Computed: true,
377+
ValidateDiagFunc: enum.Validate[awstypes.PostgreSQLAuthenticationMethod](),
378+
},
373379
"babelfish_database_name": {
374380
Type: schema.TypeString,
375381
Optional: true,
@@ -379,8 +385,9 @@ func resourceEndpoint() *schema.Resource {
379385
Optional: true,
380386
},
381387
"database_mode": {
382-
Type: schema.TypeString,
383-
Optional: true,
388+
Type: schema.TypeString,
389+
Optional: true,
390+
ValidateDiagFunc: enum.Validate[awstypes.DatabaseMode](),
384391
},
385392
"ddl_artifacts_schema": {
386393
Type: schema.TypeString,
@@ -415,16 +422,23 @@ func resourceEndpoint() *schema.Resource {
415422
Optional: true,
416423
},
417424
"map_long_varchar_as": {
418-
Type: schema.TypeString,
419-
Optional: true,
425+
Type: schema.TypeString,
426+
Optional: true,
427+
ValidateDiagFunc: enum.Validate[awstypes.LongVarcharMappingType](),
420428
},
421429
"max_file_size": {
422430
Type: schema.TypeInt,
423431
Optional: true,
424432
},
425433
"plugin_name": {
426-
Type: schema.TypeString,
427-
Optional: true,
434+
Type: schema.TypeString,
435+
Optional: true,
436+
ValidateDiagFunc: enum.Validate[awstypes.PluginNameValue](),
437+
},
438+
"service_access_role_arn": {
439+
Type: schema.TypeString,
440+
Optional: true,
441+
ValidateFunc: verify.ValidARN,
428442
},
429443
"slot_name": {
430444
Type: schema.TypeString,
@@ -1922,6 +1936,9 @@ func expandPostgreSQLSettings(tfMap map[string]any) *awstypes.PostgreSQLSettings
19221936
if v, ok := tfMap["after_connect_script"].(string); ok && v != "" {
19231937
apiObject.AfterConnectScript = aws.String(v)
19241938
}
1939+
if v, ok := tfMap["authentication_method"].(string); ok && v != "" {
1940+
apiObject.AuthenticationMethod = awstypes.PostgreSQLAuthenticationMethod(v)
1941+
}
19251942
if v, ok := tfMap["babelfish_database_name"].(string); ok && v != "" {
19261943
apiObject.BabelfishDatabaseName = aws.String(v)
19271944
}
@@ -1964,6 +1981,9 @@ func expandPostgreSQLSettings(tfMap map[string]any) *awstypes.PostgreSQLSettings
19641981
if v, ok := tfMap["plugin_name"].(string); ok && v != "" {
19651982
apiObject.PluginName = awstypes.PluginNameValue(v)
19661983
}
1984+
if v, ok := tfMap["service_access_role_arn"].(string); ok && v != "" {
1985+
apiObject.ServiceAccessRoleArn = aws.String(v)
1986+
}
19671987
if v, ok := tfMap["slot_name"].(string); ok && v != "" {
19681988
apiObject.SlotName = aws.String(v)
19691989
}
@@ -1981,13 +2001,14 @@ func flattenPostgreSQLSettings(apiObject *awstypes.PostgreSQLSettings) []map[str
19812001
if v := apiObject.AfterConnectScript; v != nil {
19822002
tfMap["after_connect_script"] = aws.ToString(v)
19832003
}
2004+
tfMap["authentication_method"] = apiObject.AuthenticationMethod
19842005
if v := apiObject.BabelfishDatabaseName; v != nil {
19852006
tfMap["babelfish_database_name"] = aws.ToString(v)
19862007
}
19872008
if v := apiObject.CaptureDdls; v != nil {
19882009
tfMap["capture_ddls"] = aws.ToBool(v)
19892010
}
1990-
tfMap["database_mode"] = string(apiObject.DatabaseMode)
2011+
tfMap["database_mode"] = apiObject.DatabaseMode
19912012
if v := apiObject.DdlArtifactsSchema; v != nil {
19922013
tfMap["ddl_artifacts_schema"] = aws.ToString(v)
19932014
}
@@ -2012,11 +2033,14 @@ func flattenPostgreSQLSettings(apiObject *awstypes.PostgreSQLSettings) []map[str
20122033
if v := apiObject.MapJsonbAsClob; v != nil {
20132034
tfMap["map_jsonb_as_clob"] = aws.ToBool(v)
20142035
}
2015-
tfMap["map_long_varchar_as"] = string(apiObject.MapLongVarcharAs)
2036+
tfMap["map_long_varchar_as"] = apiObject.MapLongVarcharAs
20162037
if v := apiObject.MaxFileSize; v != nil {
20172038
tfMap["max_file_size"] = aws.ToInt32(v)
20182039
}
2019-
tfMap["plugin_name"] = string(apiObject.PluginName)
2040+
tfMap["plugin_name"] = apiObject.PluginName
2041+
if v := apiObject.ServiceAccessRoleArn; v != nil {
2042+
tfMap["service_access_role_arn"] = aws.ToString(v)
2043+
}
20202044
if v := apiObject.SlotName; v != nil {
20212045
tfMap["slot_name"] = aws.ToString(v)
20222046
}

internal/service/dms/endpoint_data_source.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func dataSourceEndpoint() *schema.Resource {
262262
Type: schema.TypeString,
263263
Computed: true,
264264
},
265+
"authentication_method": {
266+
Type: schema.TypeString,
267+
Computed: true,
268+
},
265269
"babelfish_database_name": {
266270
Type: schema.TypeString,
267271
Computed: true,
@@ -318,6 +322,10 @@ func dataSourceEndpoint() *schema.Resource {
318322
Type: schema.TypeString,
319323
Computed: true,
320324
},
325+
"service_access_role_arn": {
326+
Type: schema.TypeString,
327+
Computed: true,
328+
},
321329
"slot_name": {
322330
Type: schema.TypeString,
323331
Computed: true,

internal/service/dms/endpoint_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ func TestAccDMSEndpoint_PostgreSQL_settings_source(t *testing.T) {
11331133
testAccCheckEndpointExists(ctx, resourceName),
11341134
resource.TestCheckResourceAttr(resourceName, "postgres_settings.#", "1"),
11351135
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.after_connect_script", "SET search_path TO pg_catalog,public;"),
1136+
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.authentication_method", "iam"),
11361137
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.capture_ddls", acctest.CtTrue),
11371138
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.ddl_artifacts_schema", acctest.CtTrue),
11381139
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.execute_timeout", "100"),
@@ -1145,6 +1146,7 @@ func TestAccDMSEndpoint_PostgreSQL_settings_source(t *testing.T) {
11451146
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.map_long_varchar_as", "wstring"),
11461147
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.max_file_size", "1024"),
11471148
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.plugin_name", "pglogical"),
1149+
resource.TestCheckResourceAttrSet(resourceName, "postgres_settings.0.service_access_role_arn"),
11481150
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.slot_name", "test"),
11491151
),
11501152
},
@@ -1169,6 +1171,7 @@ func TestAccDMSEndpoint_PostgreSQL_settings_target(t *testing.T) {
11691171
testAccCheckEndpointExists(ctx, resourceName),
11701172
resource.TestCheckResourceAttr(resourceName, "postgres_settings.#", "1"),
11711173
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.after_connect_script", "SET search_path TO pg_catalog,public;"),
1174+
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.authentication_method", names.AttrPassword),
11721175
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.babelfish_database_name", "babelfish"),
11731176
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.database_mode", "babelfish"),
11741177
resource.TestCheckResourceAttr(resourceName, "postgres_settings.0.execute_timeout", "100"),
@@ -3094,6 +3097,29 @@ resource "aws_dms_endpoint" "test" {
30943097

30953098
func testAccEndpointConfig_postgreSQLSourceSettings(rName string) string {
30963099
return fmt.Sprintf(`
3100+
3101+
data "aws_region" "current" {}
3102+
data "aws_partition" "current" {}
3103+
3104+
resource "aws_iam_role" "test" {
3105+
name = %[1]q
3106+
assume_role_policy = <<EOF
3107+
{
3108+
"Version": "2012-10-17",
3109+
"Statement": [
3110+
{
3111+
"Action": "sts:AssumeRole",
3112+
"Principal": {
3113+
"Service": "dms.${data.aws_region.current.region}.${data.aws_partition.current.dns_suffix}"
3114+
},
3115+
"Effect": "Allow",
3116+
"Sid": ""
3117+
}
3118+
]
3119+
}
3120+
EOF
3121+
}
3122+
30973123
resource "aws_dms_endpoint" "test" {
30983124
endpoint_id = %[1]q
30993125
endpoint_type = "source"
@@ -3108,6 +3134,7 @@ resource "aws_dms_endpoint" "test" {
31083134
31093135
postgres_settings {
31103136
after_connect_script = "SET search_path TO pg_catalog,public;"
3137+
authentication_method = "iam"
31113138
capture_ddls = true
31123139
ddl_artifacts_schema = true
31133140
execute_timeout = 100
@@ -3120,6 +3147,7 @@ resource "aws_dms_endpoint" "test" {
31203147
map_long_varchar_as = "wstring"
31213148
max_file_size = 1024
31223149
plugin_name = "pglogical"
3150+
service_access_role_arn = aws_iam_role.test.arn
31233151
slot_name = "test"
31243152
}
31253153
}
@@ -3142,6 +3170,7 @@ resource "aws_dms_endpoint" "test" {
31423170
31433171
postgres_settings {
31443172
after_connect_script = "SET search_path TO pg_catalog,public;"
3173+
authentication_method = "password"
31453174
babelfish_database_name = "babelfish"
31463175
database_mode = "babelfish"
31473176
execute_timeout = 100

website/docs/r/dms_endpoint.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ The following arguments are optional:
138138
-> Additional information can be found in the [Using PostgreSQL as a Source for AWS DMS documentation](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html).
139139

140140
* `after_connect_script` - (Optional) For use with change data capture (CDC) only, this attribute has AWS DMS bypass foreign keys and user triggers to reduce the time it takes to bulk load data.
141+
* `authentication_method` - (Optional) Specifies the authentication method. Valid values: `password`, `iam`.
141142
* `babelfish_database_name` - (Optional) The Babelfish for Aurora PostgreSQL database name for the endpoint.
142143
* `capture_ddls` - (Optional) To capture DDL events, AWS DMS creates various artifacts in the PostgreSQL database when the task starts.
143144
* `database_mode` - (Optional) Specifies the default behavior of the replication's handling of PostgreSQL- compatible endpoints that require some additional configuration, such as Babelfish endpoints.
@@ -152,6 +153,7 @@ The following arguments are optional:
152153
* `map_long_varchar_as` - Optional When true, DMS migrates LONG values as VARCHAR.
153154
* `max_file_size` - (Optional) Specifies the maximum size (in KB) of any .csv file used to transfer data to PostgreSQL. Default is `32,768 KB`.
154155
* `plugin_name` - (Optional) Specifies the plugin to use to create a replication slot. Valid values: `pglogical`, `test_decoding`.
156+
* `service_access_role_arn` - (Optional) Specifies the IAM role to use to authenticate the connection.
155157
* `slot_name` - (Optional) Sets the name of a previously created logical replication slot for a CDC load of the PostgreSQL source instance.
156158

157159
### redis_settings

0 commit comments

Comments
 (0)