Skip to content

Commit

Permalink
Removes plan-time validation for automatic_failover_enabled (#18635)
Browse files Browse the repository at this point in the history
* Removes plan-time validation for `automatic_failover_enabled`

The plan-time validation also depends on whether the parameter group used enabled Redis cluster mode. If so, `automatic_failover_enabled` must be true, otherwise, the replication group must have at least two clusters

* Adds CHANGELOG
  • Loading branch information
gdavison authored Apr 8, 2021
1 parent 9af1172 commit aef94ab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .changelog/18635.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_elasticache_replication_group: Remmoves incorrect plan-time validation for `automatic_failover_enabled`
```
21 changes: 0 additions & 21 deletions aws/resource_aws_elasticache_replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down
108 changes: 56 additions & 52 deletions aws/resource_aws_elasticache_replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,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{
Expand All @@ -471,27 +471,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")
Expand Down Expand Up @@ -819,6 +798,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")
Expand Down Expand Up @@ -1951,36 +1966,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" {
Expand Down Expand Up @@ -2239,6 +2224,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" {
Expand Down

0 comments on commit aef94ab

Please sign in to comment.