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 +``` 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, 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 = <