Skip to content

Commit 89a6e93

Browse files
authored
Merge pull request #44309 from tabito-hara/f-aws_rds_proxy-add_default_auth_scheme
[Enhancement] aws_rds_proxy: Add `default_auth_scheme` argument to support RDS Proxy end-to-end IAM authentication
2 parents c5adf8e + e00a21e commit 89a6e93

File tree

7 files changed

+192
-5
lines changed

7 files changed

+192
-5
lines changed

.changelog/44309.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_rds_proxy: Add `default_auth_scheme` argument
3+
```
4+
5+
```release-note:enhancement
6+
resource/aws_rds_proxy: Make `auth` configuration block optional
7+
```
8+
9+
```release-note:enhancement
10+
data-source/aws_rds_proxy: Add `default_auth_scheme` attribute
11+
```

internal/service/rds/proxy.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func resourceProxy() *schema.Resource {
5454
},
5555
"auth": {
5656
Type: schema.TypeSet,
57-
Required: true,
57+
Optional: true,
5858
Elem: &schema.Resource{
5959
Schema: map[string]*schema.Schema{
6060
"auth_scheme": {
@@ -94,6 +94,12 @@ func resourceProxy() *schema.Resource {
9494
Type: schema.TypeBool,
9595
Optional: true,
9696
},
97+
"default_auth_scheme": {
98+
Type: schema.TypeString,
99+
Optional: true,
100+
Computed: true,
101+
ValidateDiagFunc: enum.Validate[types.DefaultAuthScheme](),
102+
},
97103
names.AttrEndpoint: {
98104
Type: schema.TypeString,
99105
Computed: true,
@@ -147,18 +153,27 @@ func resourceProxyCreate(ctx context.Context, d *schema.ResourceData, meta any)
147153

148154
name := d.Get(names.AttrName).(string)
149155
input := &rds.CreateDBProxyInput{
150-
Auth: expandUserAuthConfigs(d.Get("auth").(*schema.Set).List()),
151156
DBProxyName: aws.String(name),
152157
EngineFamily: types.EngineFamily(d.Get("engine_family").(string)),
153158
RoleArn: aws.String(d.Get(names.AttrRoleARN).(string)),
154159
Tags: getTagsIn(ctx),
155160
VpcSubnetIds: flex.ExpandStringValueSet(d.Get("vpc_subnet_ids").(*schema.Set)),
156161
}
157162

163+
if v, ok := d.GetOk("auth"); ok && v.(*schema.Set).Len() > 0 {
164+
input.Auth = expandUserAuthConfigs(v.(*schema.Set).List())
165+
} else {
166+
input.Auth = []types.UserAuthConfig{}
167+
}
168+
158169
if v, ok := d.GetOk("debug_logging"); ok {
159170
input.DebugLogging = aws.Bool(v.(bool))
160171
}
161172

173+
if v, ok := d.GetOk("default_auth_scheme"); ok {
174+
input.DefaultAuthScheme = types.DefaultAuthScheme(v.(string))
175+
}
176+
162177
if v, ok := d.GetOk("idle_client_timeout"); ok {
163178
input.IdleClientTimeout = aws.Int32(int32(v.(int)))
164179
}
@@ -206,6 +221,7 @@ func resourceProxyRead(ctx context.Context, d *schema.ResourceData, meta any) di
206221
d.Set("auth", flattenUserAuthConfigInfos(dbProxy.Auth))
207222
d.Set(names.AttrName, dbProxy.DBProxyName)
208223
d.Set("debug_logging", dbProxy.DebugLogging)
224+
d.Set("default_auth_scheme", dbProxy.DefaultAuthScheme)
209225
d.Set("engine_family", dbProxy.EngineFamily)
210226
d.Set("idle_client_timeout", dbProxy.IdleClientTimeout)
211227
d.Set("require_tls", dbProxy.RequireTLS)
@@ -224,14 +240,23 @@ func resourceProxyUpdate(ctx context.Context, d *schema.ResourceData, meta any)
224240
if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
225241
oName, nName := d.GetChange(names.AttrName)
226242
input := &rds.ModifyDBProxyInput{
227-
Auth: expandUserAuthConfigs(d.Get("auth").(*schema.Set).List()),
228243
DBProxyName: aws.String(oName.(string)),
229244
DebugLogging: aws.Bool(d.Get("debug_logging").(bool)),
230245
NewDBProxyName: aws.String(nName.(string)),
231246
RequireTLS: aws.Bool(d.Get("require_tls").(bool)),
232247
RoleArn: aws.String(d.Get(names.AttrRoleARN).(string)),
233248
}
234249

250+
if v, ok := d.GetOk("auth"); ok && v.(*schema.Set).Len() > 0 {
251+
input.Auth = expandUserAuthConfigs(v.(*schema.Set).List())
252+
} else {
253+
input.Auth = []types.UserAuthConfig{}
254+
}
255+
256+
if v, ok := d.GetOk("default_auth_scheme"); ok {
257+
input.DefaultAuthScheme = types.DefaultAuthScheme(v.(string))
258+
}
259+
235260
if v, ok := d.GetOk("idle_client_timeout"); ok {
236261
input.IdleClientTimeout = aws.Int32(int32(v.(int)))
237262
}

internal/service/rds/proxy_data_source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func dataSourceProxy() *schema.Resource {
5959
Type: schema.TypeBool,
6060
Computed: true,
6161
},
62+
"default_auth_scheme": {
63+
Type: schema.TypeString,
64+
Computed: true,
65+
},
6266
names.AttrEndpoint: {
6367
Type: schema.TypeString,
6468
Computed: true,
@@ -116,6 +120,7 @@ func dataSourceProxyRead(ctx context.Context, d *schema.ResourceData, meta any)
116120
d.Set(names.AttrARN, dbProxy.DBProxyArn)
117121
d.Set("auth", flattenUserAuthConfigInfos(dbProxy.Auth))
118122
d.Set("debug_logging", dbProxy.DebugLogging)
123+
d.Set("default_auth_scheme", dbProxy.DefaultAuthScheme)
119124
d.Set(names.AttrEndpoint, dbProxy.Endpoint)
120125
d.Set("engine_family", dbProxy.EngineFamily)
121126
d.Set("idle_client_timeout", dbProxy.IdleClientTimeout)

internal/service/rds/proxy_data_source_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestAccRDSProxyDataSource_basic(t *testing.T) {
3333
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN),
3434
resource.TestCheckResourceAttrPair(dataSourceName, "auth.#", resourceName, "auth.#"),
3535
resource.TestCheckResourceAttrPair(dataSourceName, "debug_logging", resourceName, "debug_logging"),
36+
resource.TestCheckResourceAttrPair(dataSourceName, "default_auth_scheme", resourceName, "default_auth_scheme"),
3637
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrEndpoint, resourceName, names.AttrEndpoint),
3738
resource.TestCheckResourceAttrPair(dataSourceName, "engine_family", resourceName, "engine_family"),
3839
resource.TestCheckResourceAttrPair(dataSourceName, "idle_client_timeout", resourceName, "idle_client_timeout"),

internal/service/rds/proxy_test.go

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ func TestAccRDSProxy_basic(t *testing.T) {
4848
resource.TestCheckResourceAttr(resourceName, "auth.#", "1"),
4949
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "auth.*", map[string]string{
5050
"auth_scheme": "SECRETS",
51-
"client_password_auth_type": "MYSQL_NATIVE_PASSWORD",
51+
"client_password_auth_type": "MYSQL_CACHING_SHA2_PASSWORD",
5252
names.AttrDescription: "test",
5353
"iam_auth": "DISABLED",
5454
}),
5555
resource.TestCheckResourceAttr(resourceName, "debug_logging", acctest.CtFalse),
56+
resource.TestCheckResourceAttr(resourceName, "default_auth_scheme", string(types.DefaultAuthSchemeNone)),
5657
resource.TestMatchResourceAttr(resourceName, names.AttrEndpoint, regexache.MustCompile(`^[\w\-\.]+\.rds\.amazonaws\.com$`)),
5758
resource.TestCheckResourceAttr(resourceName, "idle_client_timeout", "1800"),
5859
resource.TestCheckResourceAttr(resourceName, "require_tls", acctest.CtTrue),
@@ -446,6 +447,97 @@ func TestAccRDSProxy_authSecretARN(t *testing.T) {
446447
})
447448
}
448449

450+
func TestAccRDSProxy_defaultAuthScheme(t *testing.T) {
451+
ctx := acctest.Context(t)
452+
if testing.Short() {
453+
t.Skip("skipping long-running test in short mode")
454+
}
455+
456+
var v types.DBProxy
457+
resourceName := "aws_db_proxy.test"
458+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
459+
460+
resource.ParallelTest(t, resource.TestCase{
461+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccDBProxyPreCheck(ctx, t) },
462+
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
463+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
464+
CheckDestroy: testAccCheckProxyDestroy(ctx),
465+
Steps: []resource.TestStep{
466+
{
467+
Config: testAccProxyConfig_defaultAuthSchemeIAMAUTH(rName),
468+
Check: resource.ComposeAggregateTestCheckFunc(
469+
testAccCheckProxyExists(ctx, resourceName, &v),
470+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
471+
resource.TestCheckResourceAttr(resourceName, "engine_family", "MYSQL"),
472+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "rds", regexache.MustCompile(`db-proxy:.+`)),
473+
resource.TestCheckResourceAttr(resourceName, "auth.#", "0"),
474+
resource.TestCheckResourceAttr(resourceName, "debug_logging", acctest.CtFalse),
475+
resource.TestCheckResourceAttr(resourceName, "default_auth_scheme", string(types.DefaultAuthSchemeIamAuth)),
476+
resource.TestMatchResourceAttr(resourceName, names.AttrEndpoint, regexache.MustCompile(`^[\w\-\.]+\.rds\.amazonaws\.com$`)),
477+
resource.TestCheckResourceAttr(resourceName, "idle_client_timeout", "1800"),
478+
resource.TestCheckResourceAttr(resourceName, "require_tls", acctest.CtTrue),
479+
resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN),
480+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
481+
resource.TestCheckResourceAttr(resourceName, "vpc_subnet_ids.#", "2"),
482+
resource.TestCheckTypeSetElemAttrPair(resourceName, "vpc_subnet_ids.*", "aws_subnet.test.0", names.AttrID),
483+
resource.TestCheckTypeSetElemAttrPair(resourceName, "vpc_subnet_ids.*", "aws_subnet.test.1", names.AttrID),
484+
),
485+
},
486+
{
487+
ResourceName: resourceName,
488+
ImportState: true,
489+
ImportStateVerify: true,
490+
},
491+
{
492+
Config: testAccProxyConfig_defaultAuthSchemeNONE(rName),
493+
Check: resource.ComposeAggregateTestCheckFunc(
494+
testAccCheckProxyExists(ctx, resourceName, &v),
495+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
496+
resource.TestCheckResourceAttr(resourceName, "engine_family", "MYSQL"),
497+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "rds", regexache.MustCompile(`db-proxy:.+`)),
498+
resource.TestCheckResourceAttr(resourceName, "auth.#", "1"),
499+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "auth.*", map[string]string{
500+
"auth_scheme": "SECRETS",
501+
"client_password_auth_type": "MYSQL_CACHING_SHA2_PASSWORD",
502+
names.AttrDescription: "test",
503+
"iam_auth": "DISABLED",
504+
}),
505+
resource.TestCheckResourceAttr(resourceName, "debug_logging", acctest.CtFalse),
506+
resource.TestCheckResourceAttr(resourceName, "default_auth_scheme", string(types.DefaultAuthSchemeNone)),
507+
resource.TestMatchResourceAttr(resourceName, names.AttrEndpoint, regexache.MustCompile(`^[\w\-\.]+\.rds\.amazonaws\.com$`)),
508+
resource.TestCheckResourceAttr(resourceName, "idle_client_timeout", "1800"),
509+
resource.TestCheckResourceAttr(resourceName, "require_tls", acctest.CtTrue),
510+
resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN),
511+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
512+
resource.TestCheckResourceAttr(resourceName, "vpc_subnet_ids.#", "2"),
513+
resource.TestCheckTypeSetElemAttrPair(resourceName, "vpc_subnet_ids.*", "aws_subnet.test.0", names.AttrID),
514+
resource.TestCheckTypeSetElemAttrPair(resourceName, "vpc_subnet_ids.*", "aws_subnet.test.1", names.AttrID),
515+
),
516+
},
517+
{
518+
Config: testAccProxyConfig_defaultAuthSchemeIAMAUTH(rName),
519+
Check: resource.ComposeAggregateTestCheckFunc(
520+
testAccCheckProxyExists(ctx, resourceName, &v),
521+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
522+
resource.TestCheckResourceAttr(resourceName, "engine_family", "MYSQL"),
523+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "rds", regexache.MustCompile(`db-proxy:.+`)),
524+
resource.TestCheckResourceAttr(resourceName, "auth.#", "0"),
525+
resource.TestCheckResourceAttr(resourceName, "debug_logging", acctest.CtFalse),
526+
resource.TestCheckResourceAttr(resourceName, "default_auth_scheme", string(types.DefaultAuthSchemeIamAuth)),
527+
resource.TestMatchResourceAttr(resourceName, names.AttrEndpoint, regexache.MustCompile(`^[\w\-\.]+\.rds\.amazonaws\.com$`)),
528+
resource.TestCheckResourceAttr(resourceName, "idle_client_timeout", "1800"),
529+
resource.TestCheckResourceAttr(resourceName, "require_tls", acctest.CtTrue),
530+
resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, "aws_iam_role.test", names.AttrARN),
531+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
532+
resource.TestCheckResourceAttr(resourceName, "vpc_subnet_ids.#", "2"),
533+
resource.TestCheckTypeSetElemAttrPair(resourceName, "vpc_subnet_ids.*", "aws_subnet.test.0", names.AttrID),
534+
resource.TestCheckTypeSetElemAttrPair(resourceName, "vpc_subnet_ids.*", "aws_subnet.test.1", names.AttrID),
535+
),
536+
},
537+
},
538+
})
539+
}
540+
449541
func TestAccRDSProxy_tags(t *testing.T) {
450542
ctx := acctest.Context(t)
451543
if testing.Short() {
@@ -955,6 +1047,57 @@ resource "aws_secretsmanager_secret_version" "test2" {
9551047
`, rName, nName))
9561048
}
9571049

1050+
func testAccProxyConfig_defaultAuthSchemeIAMAUTH(rName string) string {
1051+
return acctest.ConfigCompose(testAccProxyConfig_base(rName), fmt.Sprintf(`
1052+
resource "aws_db_proxy" "test" {
1053+
depends_on = [
1054+
aws_secretsmanager_secret_version.test,
1055+
aws_iam_role_policy.test
1056+
]
1057+
1058+
name = %[1]q
1059+
debug_logging = false
1060+
engine_family = "MYSQL"
1061+
idle_client_timeout = 1800
1062+
require_tls = true
1063+
role_arn = aws_iam_role.test.arn
1064+
vpc_security_group_ids = [aws_security_group.test.id]
1065+
vpc_subnet_ids = aws_subnet.test[*].id
1066+
1067+
default_auth_scheme = "IAM_AUTH"
1068+
}
1069+
`, rName))
1070+
}
1071+
1072+
func testAccProxyConfig_defaultAuthSchemeNONE(rName string) string {
1073+
return acctest.ConfigCompose(testAccProxyConfig_base(rName), fmt.Sprintf(`
1074+
resource "aws_db_proxy" "test" {
1075+
depends_on = [
1076+
aws_secretsmanager_secret_version.test,
1077+
aws_iam_role_policy.test
1078+
]
1079+
1080+
name = %[1]q
1081+
debug_logging = false
1082+
engine_family = "MYSQL"
1083+
idle_client_timeout = 1800
1084+
require_tls = true
1085+
role_arn = aws_iam_role.test.arn
1086+
vpc_security_group_ids = [aws_security_group.test.id]
1087+
vpc_subnet_ids = aws_subnet.test[*].id
1088+
1089+
auth {
1090+
auth_scheme = "SECRETS"
1091+
description = "test"
1092+
iam_auth = "DISABLED"
1093+
secret_arn = aws_secretsmanager_secret.test.arn
1094+
}
1095+
1096+
default_auth_scheme = "NONE"
1097+
}
1098+
`, rName))
1099+
}
1100+
9581101
func testAccProxyConfig_tags1(rName, tagKey1, tagValue1 string) string {
9591102
return acctest.ConfigCompose(testAccProxyConfig_base(rName), fmt.Sprintf(`
9601103
resource "aws_db_proxy" "test" {

website/docs/d/db_proxy.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This data source exports the following attributes in addition to the arguments a
3232
* `arn` - ARN of the DB Proxy.
3333
* `auth` - Configuration(s) with authorization mechanisms to connect to the associated instance or cluster.
3434
* `debug_logging` - Whether the proxy includes detailed information about SQL statements in its logs.
35+
* `default_auth_scheme` - Default authentication scheme that the proxy uses for client connections to the proxy and connections from the proxy to the underlying database.
3536
* `endpoint` - Endpoint that you can use to connect to the DB proxy.
3637
* `engine_family` - Kinds of databases that the proxy can connect to.
3738
* `idle_client_timeout` - Number of seconds a connection to the proxy can have no activity before the proxy drops the client connection.

website/docs/r/db_proxy.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ This resource supports the following arguments:
9898

9999
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
100100
* `name` - (Required) The identifier for the proxy. This name must be unique for all proxies owned by your AWS account in the specified AWS Region. An identifier must begin with a letter and must contain only ASCII letters, digits, and hyphens; it can't end with a hyphen or contain two consecutive hyphens.
101-
* `auth` - (Required) Configuration block(s) with authorization mechanisms to connect to the associated instances or clusters. Described below.
101+
* `auth` - (Optional) Configuration block(s) with authorization mechanisms to connect to the associated instances or clusters. Required when `default_auth_scheme` is `NONE` or unspecified. Described below.
102102
* `debug_logging` - (Optional) Whether the proxy includes detailed information about SQL statements in its logs. This information helps you to debug issues involving SQL behavior or the performance and scalability of the proxy connections. The debug information includes the text of SQL statements that you submit through the proxy. Thus, only enable this setting when needed for debugging, and only when you have security measures in place to safeguard any sensitive information that appears in the logs.
103+
* `default_auth_scheme` - (Optional) Default authentication scheme that the proxy uses for client connections to the proxy and connections from the proxy to the underlying database. Valid values are `NONE` and `IAM_AUTH`. Defaults to `NONE`.
103104
* `engine_family` - (Required, Forces new resource) The kinds of databases that the proxy can connect to. This value determines which database network protocol the proxy recognizes when it interprets network traffic to and from the database. For Aurora MySQL, RDS for MariaDB, and RDS for MySQL databases, specify `MYSQL`. For Aurora PostgreSQL and RDS for PostgreSQL databases, specify `POSTGRESQL`. For RDS for Microsoft SQL Server, specify `SQLSERVER`. Valid values are `MYSQL`, `POSTGRESQL`, and `SQLSERVER`.
104105
* `idle_client_timeout` - (Optional) The number of seconds that a connection to the proxy can be inactive before the proxy disconnects it. You can set this value higher or lower than the connection timeout limit for the associated database.
105106
* `require_tls` - (Optional) A Boolean parameter that specifies whether Transport Layer Security (TLS) encryption is required for connections to the proxy. By enabling this setting, you can enforce encrypted TLS connections to the proxy.

0 commit comments

Comments
 (0)