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

Allow auth_token change without destroy and recreate #16203

Merged
merged 11 commits into from
Nov 24, 2021
3 changes: 3 additions & 0 deletions .changelog/16203.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_elasticache_replication_group: Allow `auth_token` argument to be rotated without destroy and create
```
15 changes: 14 additions & 1 deletion internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func ResourceReplicationGroup() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ForceNew: true,
ValidateFunc: validReplicationGroupAuthToken,
},
"auto_minor_version_upgrade": {
Expand Down Expand Up @@ -685,6 +684,20 @@ func resourceReplicationGroupUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("auth_token") {
params := &elasticache.ModifyReplicationGroupInput{
ApplyImmediately: aws.Bool(true),
ReplicationGroupId: aws.String(d.Id()),
AuthTokenUpdateStrategy: aws.String("ROTATE"),
AuthToken: aws.String(d.Get("auth_token").(string)),
}

_, err := conn.ModifyReplicationGroup(params)
if err != nil {
return fmt.Errorf("error changing auth_token for Elasticache Replication Group (%s): %w", d.Id(), err)
}
}

if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")
if err := UpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
Expand Down
38 changes: 36 additions & 2 deletions internal/service/elasticache/replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,40 @@ func TestAccElastiCacheReplicationGroup_updateParameterGroup(t *testing.T) {
})
}

func TestAccElastiCacheReplicationGroup_updateAuthToken(t *testing.T) {
var rg elasticache.ReplicationGroup
resourceName := "aws_elasticache_replication_group.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, elasticache.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckReplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccReplicationGroup_EnableAuthTokenTransitEncryptionConfig(1, "one", sdkacctest.RandString(16)),
Check: resource.ComposeTestCheckFunc(
testAccCheckReplicationGroupExists(resourceName, &rg),
resource.TestCheckResourceAttr(
resourceName, "transit_encryption_enabled", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately", "auth_token", "availability_zones"},
},
{
Config: testAccReplicationGroup_EnableAuthTokenTransitEncryptionConfig(1, "one", sdkacctest.RandString(16)),
Check: resource.ComposeTestCheckFunc(
testAccCheckReplicationGroupExists(resourceName, &rg),
),
},
},
})
}

func TestAccElastiCacheReplicationGroup_vpc(t *testing.T) {
var rg elasticache.ReplicationGroup
resourceName := "aws_elasticache_replication_group.test"
Expand Down Expand Up @@ -2640,9 +2674,9 @@ resource "aws_elasticache_replication_group" "test" {
port = 6379
subnet_group_name = aws_elasticache_subnet_group.test.name
security_group_ids = [aws_security_group.test.id]
parameter_group_name = "default.redis3.2"
parameter_group_name = "default.redis5.0"
availability_zones = [data.aws_availability_zones.available.names[0]]
engine_version = "3.2.6"
engine_version = "5.0.6"
transit_encryption_enabled = true
auth_token = "%s"
}
Expand Down