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

resource/aws_elasticache_replication_group: Prevent re-creation when encryption enabled #18361

Merged
merged 3 commits into from
Mar 24, 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/18361.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_elasticache_replication_group: Prevents re-creation of secondary replication groups when encryption is enabled
```
4 changes: 2 additions & 2 deletions aws/resource_aws_elasticache_replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
"at_rest_encryption_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
Computed: true,
},
"auth_token": {
Type: schema.TypeString,
Expand Down Expand Up @@ -263,8 +263,8 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
"transit_encryption_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
Computed: true,
},
"kms_key_id": {
Type: schema.TypeString,
Expand Down
99 changes: 95 additions & 4 deletions aws/resource_aws_elasticache_replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ func TestAccAWSElasticacheReplicationGroup_GlobalReplicationGroupId_Basic(t *tes
var rg elasticache.ReplicationGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_elasticache_replication_group.test"
primaryGroupResourceName := "aws_elasticache_replication_group.primary"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -1459,10 +1460,53 @@ func TestAccAWSElasticacheReplicationGroup_GlobalReplicationGroupId_Basic(t *tes
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheReplicationGroupExists(resourceName, &rg),
resource.TestCheckResourceAttrPair(resourceName, "global_replication_group_id", "aws_elasticache_global_replication_group.test", "global_replication_group_id"),
resource.TestCheckResourceAttrPair(resourceName, "node_type", "aws_elasticache_replication_group.primary", "node_type"),
resource.TestCheckResourceAttrPair(resourceName, "engine", "aws_elasticache_replication_group.primary", "engine"),
resource.TestCheckResourceAttrPair(resourceName, "engine_version", "aws_elasticache_replication_group.primary", "engine_version"),
resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", "aws_elasticache_replication_group.primary", "parameter_group_name"),
resource.TestCheckResourceAttrPair(resourceName, "node_type", primaryGroupResourceName, "node_type"),
resource.TestCheckResourceAttrPair(resourceName, "engine", primaryGroupResourceName, "engine"),
resource.TestCheckResourceAttrPair(resourceName, "engine_version", primaryGroupResourceName, "engine_version"),
resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", primaryGroupResourceName, "parameter_group_name"),
),
},
{
Config: testAccAWSElasticacheReplicationGroupConfig_GlobalReplicationGroupId_Basic(rName),
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately"},
},
},
})
}

func TestAccAWSElasticacheReplicationGroup_GlobalReplicationGroupId_Full(t *testing.T) {
var providers []*schema.Provider
var rg elasticache.ReplicationGroup
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_elasticache_replication_group.test"
primaryGroupResourceName := "aws_elasticache_replication_group.primary"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccMultipleRegionPreCheck(t, 2)
},
ErrorCheck: testAccErrorCheck(t, elasticache.EndpointsID),
ProviderFactories: testAccProviderFactoriesMultipleRegion(&providers, 2),
CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSElasticacheReplicationGroupConfig_GlobalReplicationGroupId_Full(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheReplicationGroupExists(resourceName, &rg),
resource.TestCheckResourceAttrPair(resourceName, "global_replication_group_id", "aws_elasticache_global_replication_group.test", "global_replication_group_id"),
resource.TestCheckResourceAttrPair(resourceName, "node_type", primaryGroupResourceName, "node_type"),
resource.TestCheckResourceAttrPair(resourceName, "engine", primaryGroupResourceName, "engine"),
resource.TestCheckResourceAttrPair(resourceName, "engine_version", primaryGroupResourceName, "engine_version"),
resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", primaryGroupResourceName, "parameter_group_name"),

resource.TestCheckResourceAttr(resourceName, "port", "16379"),

resource.TestCheckResourceAttrPair(resourceName, "at_rest_encryption_enabled", primaryGroupResourceName, "at_rest_encryption_enabled"),
resource.TestCheckResourceAttrPair(resourceName, "transit_encryption_enabled", primaryGroupResourceName, "transit_encryption_enabled"),
),
},
{
Expand Down Expand Up @@ -2624,6 +2668,53 @@ resource "aws_elasticache_replication_group" "primary" {
`, rName))
}

func testAccAWSElasticacheReplicationGroupConfig_GlobalReplicationGroupId_Full(rName string) string {
return composeConfig(
testAccMultipleRegionProviderConfig(2),
testAccElasticacheVpcBaseWithProvider(rName, "test", ProviderNameAws),
testAccElasticacheVpcBaseWithProvider(rName, "primary", ProviderNameAwsAlternate),
fmt.Sprintf(`
resource "aws_elasticache_replication_group" "test" {
replication_group_id = "%[1]s-s"
replication_group_description = "secondary"
global_replication_group_id = aws_elasticache_global_replication_group.test.global_replication_group_id

subnet_group_name = aws_elasticache_subnet_group.test.name

number_cache_clusters = 1

port = 16379
}

resource "aws_elasticache_global_replication_group" "test" {
provider = awsalternate

global_replication_group_id_suffix = %[1]q
primary_replication_group_id = aws_elasticache_replication_group.primary.id
}

resource "aws_elasticache_replication_group" "primary" {
provider = awsalternate

replication_group_id = "%[1]s-p"
replication_group_description = "primary"

subnet_group_name = aws_elasticache_subnet_group.primary.name

node_type = "cache.m5.large"

engine = "redis"
engine_version = "5.0.6"
number_cache_clusters = 1

port = 6379

at_rest_encryption_enabled = true
transit_encryption_enabled = true
}
`, rName))
}

func resourceAwsElasticacheReplicationGroupDisableAutomaticFailover(conn *elasticache.ElastiCache, replicationGroupID string, timeout time.Duration) error {
return resourceAwsElasticacheReplicationGroupModify(conn, timeout, &elasticache.ModifyReplicationGroupInput{
ReplicationGroupId: aws.String(replicationGroupID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ The following arguments are supported:

* `replication_group_id` – (Required) The replication group identifier. This parameter is stored as a lowercase string.
* `replication_group_description` – (Required) A user-created description for the replication group.
* ``global_replication_group_id` - (Optional) The ID of the global replication group to which this replication group should belong. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group; otherwise, the replication group is not part of any global replication group.
* `global_replication_group_id` - (Optional) The ID of the global replication group to which this replication group should belong. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group; otherwise, the replication group is not part of any global replication group.
* `number_cache_clusters` - (Optional) The number of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications. One of `number_cache_clusters` or `cluster_mode` is required.
* `node_type` - (Optional) The instance class to be used. See AWS documentation for information on [supported node types](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/CacheNodes.SupportedTypes.html) and [guidance on selecting node types](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/nodes-select-size.html). Required unless `global_replication_group_id` is set. Cannot be set if `global_replication_group_id` is set.
* `automatic_failover_enabled` - (Optional) Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If true, Multi-AZ is enabled for this replication group. If false, Multi-AZ is disabled for this replication group. Must be enabled for Redis (cluster mode enabled) replication groups. Defaults to `false`.
Expand Down