From 4e1488d132970012f0bc2cab6951f8fcef12cf15 Mon Sep 17 00:00:00 2001 From: tabito Date: Sat, 4 Oct 2025 23:20:57 +0900 Subject: [PATCH 1/4] Remove `Default` and mark `Computed` for `monitoring_interval` --- internal/service/rds/cluster_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/rds/cluster_instance.go b/internal/service/rds/cluster_instance.go index ae518f1d01d7..fb9020e712f4 100644 --- a/internal/service/rds/cluster_instance.go +++ b/internal/service/rds/cluster_instance.go @@ -161,7 +161,7 @@ func resourceClusterInstance() *schema.Resource { "monitoring_interval": { Type: schema.TypeInt, Optional: true, - Default: 0, + Computed: true, }, "monitoring_role_arn": { Type: schema.TypeString, From 1fefdd888ec12c9a9a555d02f94a3718240d0470 Mon Sep 17 00:00:00 2001 From: tabito Date: Sat, 4 Oct 2025 23:21:32 +0900 Subject: [PATCH 2/4] Add an acceptance test to verify inheritance of monitoring_interval from the cluster --- internal/service/rds/cluster_instance_test.go | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/internal/service/rds/cluster_instance_test.go b/internal/service/rds/cluster_instance_test.go index 5930ab95ef5f..71275a99b0f0 100644 --- a/internal/service/rds/cluster_instance_test.go +++ b/internal/service/rds/cluster_instance_test.go @@ -16,7 +16,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfrds "github.com/hashicorp/terraform-provider-aws/internal/service/rds" @@ -55,6 +58,7 @@ func TestAccRDSClusterInstance_basic(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, names.AttrEngineVersion), resource.TestCheckResourceAttr(resourceName, names.AttrIdentifier, rName), resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), + resource.TestCheckResourceAttr(resourceName, "monitoring_interval", "0"), resource.TestCheckResourceAttr(resourceName, "network_type", "IPV4"), resource.TestCheckResourceAttrSet(resourceName, "preferred_backup_window"), resource.TestCheckResourceAttrSet(resourceName, names.AttrPreferredMaintenanceWindow), @@ -1004,6 +1008,77 @@ func TestAccRDSClusterInstance_Replica_basic(t *testing.T) { }) } +func TestAccRDSClusterInstance_clusterLevelMonitoringInterval(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var v types.DBInstance + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_rds_cluster_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckClusterInstanceDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccClusterInstanceConfig_clusterLevelMonitoringInterval(rName, 60), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckClusterInstanceExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "monitoring_interval", "60"), + ), + }, + { + // Change monitoring_interval of aws_rds_cluster resource from 60 to 30. + // Since there are no changes in aws_rds_cluster_instance, aws_rds_cluster_instance resource will not be refreshed. + Config: testAccClusterInstanceConfig_clusterLevelMonitoringInterval(rName, 30), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckClusterInstanceExists(ctx, resourceName, &v), + ), + }, + { + // Force refresh aws_rds_cluster_instance resource to pick up monitoring_interval change from aws_rds_cluster resource. + // After refresh, no drift is expected in the plan and monitoring_interval in aws_rds_cluster_instance resource is expected to be 30. + RefreshState: true, + RefreshPlanChecks: resource.RefreshPlanChecks{ + PostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New("monitoring_interval"), knownvalue.Int32Exact(30)), + }, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckClusterInstanceExists(ctx, resourceName, &v), + ), + }, + { + // Change monitoring_interval of aws_rds_cluster resource from 30 to 0. + // Since there are no changes in aws_rds_cluster_instance, aws_rds_cluster_instance resource will not be refreshed. + Config: testAccClusterInstanceConfig_clusterLevelMonitoringInterval(rName, 0), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckClusterInstanceExists(ctx, resourceName, &v), + ), + }, + { + // Force refresh aws_rds_cluster_instance resource to pick up monitoring_interval change from aws_rds_cluster resource + // After refresh, no drift is expected in the plan and monitoring_interval in aws_rds_cluster instance resource is expected to be 0. + RefreshState: true, + RefreshPlanChecks: resource.RefreshPlanChecks{ + PostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + plancheck.ExpectKnownValue(resourceName, tfjsonpath.New("monitoring_interval"), knownvalue.Int32Exact(0)), + }, + }, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckClusterInstanceExists(ctx, resourceName, &v), + ), + }, + }, + }) +} + func testAccCheckClusterInstanceExistsWithProvider(ctx context.Context, n string, v *types.DBInstance, providerF func() *schema.Provider) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -1202,6 +1277,60 @@ resource "aws_rds_cluster" "test" { `, engine, rName)) } +func testAccClusterInstanceConfig_clusterLevelMonitoringIntervalBase(rName, engine string, monitoringInterval int) string { + return acctest.ConfigCompose( + acctest.ConfigAvailableAZsNoOptIn(), + testAccClusterInstanceConfig_orderableEngineBase(engine, false), + fmt.Sprintf(` +data "aws_partition" "current" {} + +resource "aws_iam_role" "test" { + name = %[1]q + + assume_role_policy = < Date: Sat, 4 Oct 2025 23:23:31 +0900 Subject: [PATCH 3/4] Add note about disabling enhance monitoring --- website/docs/r/rds_cluster_instance.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/rds_cluster_instance.html.markdown b/website/docs/r/rds_cluster_instance.html.markdown index 7527e3acec20..0b8d681a6b48 100644 --- a/website/docs/r/rds_cluster_instance.html.markdown +++ b/website/docs/r/rds_cluster_instance.html.markdown @@ -67,7 +67,7 @@ This resource supports the following arguments: * `identifier_prefix` - (Optional, Forces new resource) Creates a unique identifier beginning with the specified prefix. Conflicts with `identifier`. * `identifier` - (Optional, Forces new resource) Identifier for the RDS instance, if omitted, Terraform will assign a random, unique identifier. * `instance_class` - (Required) Instance class to use. For details on CPU and memory, see [Scaling Aurora DB Instances][4]. Aurora uses `db.*` instance classes/types. Please see [AWS Documentation][7] for currently available instance classes and complete details. For Aurora Serverless v2 use `db.serverless`. -* `monitoring_interval` - (Optional) Interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60. +* `monitoring_interval` - (Optional) Interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance. To disable collecting Enhanced Monitoring metrics, specify 0. The default is 0. Valid Values: 0, 1, 5, 10, 15, 30, 60. Note that Terraform detects drift for this argument only when it is explicitly specified in the configuration. Therefore, simply removing it from the configuration will not trigger a change. Once specified, the argument must be set to 0 to disable it, rather than removing it. * `monitoring_role_arn` - (Optional) ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs. You can find more information on the [AWS Documentation](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.html) what IAM permissions are needed to allow Enhanced Monitoring for RDS Instances. * `performance_insights_enabled` - (Optional) Specifies whether Performance Insights is enabled or not. **NOTE:** When Performance Insights is configured at the cluster level through `aws_rds_cluster`, this argument cannot be set to a value that conflicts with the cluster's configuration. * `performance_insights_kms_key_id` - (Optional) ARN for the KMS key to encrypt Performance Insights data. When specifying `performance_insights_kms_key_id`, `performance_insights_enabled` needs to be set to true. From f556267e72e2d563256bdc6ed88cd9e554c45c52 Mon Sep 17 00:00:00 2001 From: tabito Date: Sun, 5 Oct 2025 00:29:07 +0900 Subject: [PATCH 4/4] add changelog --- .changelog/44544.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/44544.txt diff --git a/.changelog/44544.txt b/.changelog/44544.txt new file mode 100644 index 000000000000..2e3b4b678575 --- /dev/null +++ b/.changelog/44544.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_rds_cluster_instance: Change `monitoring_interval` from `Default: 0` to `Computed` to allow inheritance from the cluster +```