Skip to content

Commit 25c5278

Browse files
authored
Merge pull request #44143 from tabito-hara/b-aws_rds_cluster_role_association-make_feature_name_optional
[bugfix] r/aws_rds_cluster_role_association: Change `feature_name` argument from required to optional
2 parents a7062a3 + 7e08601 commit 25c5278

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

.changelog/44143.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_rds_cluster_role_association: Make `feature_name` optional
3+
```

internal/service/rds/cluster_role_association.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func resourceClusterRoleAssociation() *schema.Resource {
5050
},
5151
"feature_name": {
5252
Type: schema.TypeString,
53-
Required: true,
53+
Optional: true,
5454
ForceNew: true,
5555
},
5656
names.AttrRoleARN: {
@@ -72,10 +72,13 @@ func resourceClusterRoleAssociationCreate(ctx context.Context, d *schema.Resourc
7272
id := clusterRoleAssociationCreateResourceID(dbClusterID, roleARN)
7373
input := rds.AddRoleToDBClusterInput{
7474
DBClusterIdentifier: aws.String(dbClusterID),
75-
FeatureName: aws.String(d.Get("feature_name").(string)),
7675
RoleArn: aws.String(roleARN),
7776
}
7877

78+
if v, ok := d.GetOk("feature_name"); ok {
79+
input.FeatureName = aws.String(v.(string))
80+
}
81+
7982
_, err := tfresource.RetryWhenIsA[any, *types.InvalidDBClusterStateFault](ctx, d.Timeout(schema.TimeoutCreate), func(ctx context.Context) (any, error) {
8083
return conn.AddRoleToDBCluster(ctx, &input)
8184
})

internal/service/rds/cluster_role_association_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,38 @@ func TestAccRDSClusterRoleAssociation_basic(t *testing.T) {
5252
})
5353
}
5454

55+
func TestAccRDSClusterRoleAssociation_mysqlWithoutFeatureName(t *testing.T) {
56+
ctx := acctest.Context(t)
57+
var dbClusterRole types.DBClusterRole
58+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
59+
dbClusterResourceName := "aws_rds_cluster.test"
60+
iamRoleResourceName := "aws_iam_role.test"
61+
resourceName := "aws_rds_cluster_role_association.test"
62+
63+
resource.ParallelTest(t, resource.TestCase{
64+
PreCheck: func() { acctest.PreCheck(ctx, t) },
65+
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
66+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
67+
CheckDestroy: testAccCheckClusterRoleAssociationDestroy(ctx),
68+
Steps: []resource.TestStep{
69+
{
70+
Config: testAccClusterRoleAssociationConfig_mysqlWithoutFeatureName(rName),
71+
Check: resource.ComposeTestCheckFunc(
72+
testAccCheckClusterRoleAssociationExists(ctx, resourceName, &dbClusterRole),
73+
resource.TestCheckResourceAttrPair(resourceName, "db_cluster_identifier", dbClusterResourceName, names.AttrID),
74+
resource.TestCheckResourceAttr(resourceName, "feature_name", ""),
75+
resource.TestCheckResourceAttrPair(resourceName, names.AttrRoleARN, iamRoleResourceName, names.AttrARN),
76+
),
77+
},
78+
{
79+
ResourceName: resourceName,
80+
ImportState: true,
81+
ImportStateVerify: true,
82+
},
83+
},
84+
})
85+
}
86+
5587
func TestAccRDSClusterRoleAssociation_disappears(t *testing.T) {
5688
ctx := acctest.Context(t)
5789
var dbClusterRole types.DBClusterRole
@@ -214,3 +246,44 @@ data "aws_iam_policy_document" "rds_assume_role_policy" {
214246
}
215247
`, rName))
216248
}
249+
250+
func testAccClusterRoleAssociationConfig_mysqlWithoutFeatureName(rName string) string {
251+
return acctest.ConfigCompose(
252+
acctest.ConfigAvailableAZsNoOptIn(),
253+
fmt.Sprintf(`
254+
resource "aws_rds_cluster_role_association" "test" {
255+
db_cluster_identifier = aws_rds_cluster.test.id
256+
role_arn = aws_iam_role.test.arn
257+
}
258+
259+
resource "aws_rds_cluster" "test" {
260+
cluster_identifier = %[1]q
261+
engine = "aurora-mysql"
262+
availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1], data.aws_availability_zones.available.names[2]]
263+
database_name = "mydb"
264+
master_username = "foo"
265+
master_password = "foobarfoobarfoobar"
266+
skip_final_snapshot = true
267+
}
268+
269+
resource "aws_iam_role" "test" {
270+
assume_role_policy = data.aws_iam_policy_document.rds_assume_role_policy.json
271+
name = %[1]q
272+
273+
# ensure IAM role is created just before association to exercise IAM eventual consistency
274+
depends_on = [aws_rds_cluster.test]
275+
}
276+
277+
data "aws_iam_policy_document" "rds_assume_role_policy" {
278+
statement {
279+
actions = ["sts:AssumeRole"]
280+
effect = "Allow"
281+
282+
principals {
283+
identifiers = ["rds.amazonaws.com"]
284+
type = "Service"
285+
}
286+
}
287+
}
288+
`, rName))
289+
}

website/docs/r/rds_cluster_role_association.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This resource supports the following arguments:
2929

3030
* `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).
3131
* `db_cluster_identifier` - (Required) DB Cluster Identifier to associate with the IAM Role.
32-
* `feature_name` - (Required) Name of the feature for association. This can be found in the AWS documentation relevant to the integration or a full list is available in the `SupportedFeatureNames` list returned by [AWS CLI rds describe-db-engine-versions](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-engine-versions.html).
32+
* `feature_name` - (Optional) Name of the feature for association. This can be found in the AWS documentation relevant to the integration or a full list is available in the `SupportedFeatureNames` list returned by [AWS CLI rds describe-db-engine-versions](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-engine-versions.html).
3333
* `role_arn` - (Required) Amazon Resource Name (ARN) of the IAM Role to associate with the DB Cluster.
3434

3535
## Attribute Reference

0 commit comments

Comments
 (0)