Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes plan-time validation for automatic_failover_enabled #18635

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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{
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand Down