diff --git a/.changelog/18635.txt b/.changelog/18635.txt new file mode 100644 index 000000000000..4bc2b1d8b138 --- /dev/null +++ b/.changelog/18635.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_elasticache_replication_group: Remmoves incorrect plan-time validation for `automatic_failover_enabled` +``` diff --git a/aws/resource_aws_elasticache_replication_group.go b/aws/resource_aws_elasticache_replication_group.go index ae54362f0023..774cf4b7542f 100644 --- a/aws/resource_aws_elasticache_replication_group.go +++ b/aws/resource_aws_elasticache_replication_group.go @@ -301,27 +301,6 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { } return nil }, - func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - if v := diff.Get("automatic_failover_enabled").(bool); !v { - return nil - } - - if v, ok := diff.GetOkExists("number_cache_clusters"); ok { - if v.(int) > 1 { - return nil - } - return errors.New(`if automatic_failover_enabled is true, number_cache_clusters must be greater than 1`) - } - - if v, ok := diff.GetOkExists("cluster_mode.0.replicas_per_node_group"); ok { - if v.(int) > 0 { - return nil - } - return errors.New(`if automatic_failover_enabled is true, cluster_mode[0].replicas_per_node_group must be greater than 0`) - } - - return nil - }, customdiff.ComputedIf("member_clusters", func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) bool { return diff.HasChange("number_cache_clusters") || diff.HasChange("cluster_mode.0.num_node_groups") || diff --git a/aws/resource_aws_elasticache_replication_group_test.go b/aws/resource_aws_elasticache_replication_group_test.go index 539c62faaa65..76a74b87f20f 100644 --- a/aws/resource_aws_elasticache_replication_group_test.go +++ b/aws/resource_aws_elasticache_replication_group_test.go @@ -433,7 +433,7 @@ func TestAccAWSElasticacheReplicationGroup_multiAzInVpc(t *testing.T) { }) } -func TestAccAWSElasticacheReplicationGroup_multiAz_NoAutomaticFailover(t *testing.T) { +func TestAccAWSElasticacheReplicationGroup_Validation_multiAz_NoAutomaticFailover(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") resource.ParallelTest(t, resource.TestCase{ @@ -450,27 +450,6 @@ func TestAccAWSElasticacheReplicationGroup_multiAz_NoAutomaticFailover(t *testin }) } -func TestAccAWSElasticacheReplicationGroup_AutomaticFailover_OneCacheCluster(t *testing.T) { - rName := acctest.RandomWithPrefix("tf-acc-test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, elasticache.EndpointsID), - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSElasticacheReplicationGroupConfig_MultiAZOneCacheCluster_SingleNodeGroup(rName), - ExpectError: regexp.MustCompile(`if automatic_failover_enabled is true, number_cache_clusters must be greater than 1`), - }, - { - Config: testAccAWSElasticacheReplicationGroupConfig_MultiAZOneCacheCluster_ClusterMode(rName), - ExpectError: regexp.MustCompile(`if automatic_failover_enabled is true, cluster_mode\[0\].replicas_per_node_group must be greater than 0`), - }, - }, - }) -} - func TestAccAWSElasticacheReplicationGroup_redisClusterInVpc2(t *testing.T) { var rg elasticache.ReplicationGroup rName := acctest.RandomWithPrefix("tf-acc-test") @@ -798,6 +777,42 @@ func TestAccAWSElasticacheReplicationGroup_ClusterMode_UpdateNumNodeGroupsAndRep }) } +func TestAccAWSElasticacheReplicationGroup_ClusterMode_SingleNode(t *testing.T) { + var rg elasticache.ReplicationGroup + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_elasticache_replication_group.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, elasticache.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSElasticacheReplicationGroupNativeRedisClusterConfig_SingleNode(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSElasticacheReplicationGroupExists(resourceName, &rg), + resource.TestCheckResourceAttr(resourceName, "cluster_enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "parameter_group_name", "default.redis6.x.cluster.on"), + resource.TestCheckResourceAttr(resourceName, "cluster_mode.#", "1"), + resource.TestCheckResourceAttr(resourceName, "cluster_mode.0.num_node_groups", "1"), + resource.TestCheckResourceAttr(resourceName, "cluster_mode.0.replicas_per_node_group", "0"), + resource.TestCheckResourceAttr(resourceName, "multi_az_enabled", "false"), + resource.TestCheckResourceAttr(resourceName, "automatic_failover_enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "number_cache_clusters", "1"), + resource.TestCheckResourceAttr(resourceName, "member_clusters.#", "1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"apply_immediately"}, + }, + }, + }) +} + func TestAccAWSElasticacheReplicationGroup_clusteringAndCacheNodesCausesError(t *testing.T) { rInt := acctest.RandInt() rName := acctest.RandomWithPrefix("tf-acc-test") @@ -1930,36 +1945,6 @@ resource "aws_elasticache_replication_group" "test" { `, rName) } -func testAccAWSElasticacheReplicationGroupConfig_MultiAZOneCacheCluster_SingleNodeGroup(rName string) string { - return fmt.Sprintf(` -resource "aws_elasticache_replication_group" "test" { - replication_group_id = %[1]q - replication_group_description = "test description" - number_cache_clusters = 1 - node_type = "cache.t3.small" - automatic_failover_enabled = true - multi_az_enabled = true -} -`, rName) -} - -func testAccAWSElasticacheReplicationGroupConfig_MultiAZOneCacheCluster_ClusterMode(rName string) string { - return fmt.Sprintf(` -resource "aws_elasticache_replication_group" "test" { - replication_group_id = %[1]q - replication_group_description = "test description" - node_type = "cache.t3.small" - automatic_failover_enabled = true - multi_az_enabled = true - - cluster_mode { - num_node_groups = 1 - replicas_per_node_group = 0 - } -} -`, rName) -} - func testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig(rName string) string { return fmt.Sprintf(` data "aws_availability_zones" "available" { @@ -2218,6 +2203,25 @@ resource "aws_elasticache_replication_group" "test" { `, rName)) } +func testAccAWSElasticacheReplicationGroupNativeRedisClusterConfig_SingleNode(rName string) string { + return composeConfig( + testAccAvailableAZsNoOptInConfig(), + fmt.Sprintf(` +resource "aws_elasticache_replication_group" "test" { + replication_group_id = %[1]q + replication_group_description = "test description" + node_type = "cache.t2.medium" + automatic_failover_enabled = true + + parameter_group_name = "default.redis6.x.cluster.on" + cluster_mode { + num_node_groups = 1 + replicas_per_node_group = 0 + } +} +`, rName)) +} + func testAccAWSElasticacheReplicationGroup_UseCmkKmsKeyId(rInt int, rString string) string { return fmt.Sprintf(` data "aws_availability_zones" "available" {