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

r/aws_elasticache_replication_group: Add support for transit_encryption_mode and enabling transit encryption on existing groups #30403

Merged
Merged
33 changes: 29 additions & 4 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func ResourceReplicationGroup() *schema.Resource {
"node_type",
"security_group_names",
"transit_encryption_enabled",
"transit_encryption_mode",
"at_rest_encryption_enabled",
"snapshot_arns",
"snapshot_name",
Expand Down Expand Up @@ -305,9 +306,13 @@ func ResourceReplicationGroup() *schema.Resource {
"transit_encryption_enabled": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Computed: true,
},
"transit_encryption_mode": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"preferred", "required"}, false),
},
"user_group_ids": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -348,6 +353,9 @@ func ResourceReplicationGroup() *schema.Resource {
diff.HasChange("num_node_groups") ||
diff.HasChange("replicas_per_node_group")
}),
customdiff.ForceNewIf("transit_encryption_enabled", func(_ context.Context, d *schema.ResourceDiff, meta interface{}) bool {
return verify.SemVerLessThan(d.Get("engine_version_actual").(string), "7.0.5")
}),
verify.SetTagsDiff,
),
}
Expand Down Expand Up @@ -463,6 +471,10 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData,
input.TransitEncryptionEnabled = aws.Bool(d.Get("transit_encryption_enabled").(bool))
}

if v, ok := d.GetOk("transit_encryption_mode"); ok {
input.TransitEncryptionMode = aws.String(v.(string))
}

if _, ok := d.GetOk("at_rest_encryption_enabled"); ok {
input.AtRestEncryptionEnabled = aws.Bool(d.Get("at_rest_encryption_enabled").(bool))
}
Expand Down Expand Up @@ -620,9 +632,11 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m
// Tags cannot be read when the replication group is not Available
log.Printf("[DEBUG] Waiting for ElastiCache Replication Group (%s) to become available", d.Id())

_, err = WaitReplicationGroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate))
if err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Replication Group to be available (%s): %s", aws.StringValue(rgp.ARN), err)
if aws.StringValue(rgp.Status) != "available" {
_, err = WaitReplicationGroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate))
if err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Replication Group to be available (%s): %s", aws.StringValue(rgp.ARN), err)
}
}

log.Printf("[DEBUG] ElastiCache Replication Group (%s): Checking underlying cache clusters", d.Id())
Expand Down Expand Up @@ -651,6 +665,7 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m

d.Set("at_rest_encryption_enabled", c.AtRestEncryptionEnabled)
d.Set("transit_encryption_enabled", c.TransitEncryptionEnabled)
d.Set("transit_encryption_mode", c.TransitEncryptionMode)

if c.AuthTokenEnabled != nil && !aws.BoolValue(c.AuthTokenEnabled) {
d.Set("auth_token", nil)
Expand Down Expand Up @@ -806,6 +821,16 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData,
}
}

if d.HasChange("transit_encryption_enabled") {
input.TransitEncryptionEnabled = aws.Bool(d.Get("transit_encryption_enabled").(bool))
requestUpdate = true
}

if d.HasChange("transit_encryption_mode") {
input.TransitEncryptionMode = aws.String(d.Get("transit_encryption_mode").(string))
requestUpdate = true
}

if requestUpdate {
_, err := conn.ModifyReplicationGroupWithContext(ctx, input)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ The following arguments are optional:
* `subnet_group_name` - (Optional) Name of the cache subnet group to be used for the replication group.
* `tags` - (Optional) Map of tags to assign to the resource. Adding tags to this resource will add or overwrite any existing tags on the clusters in the replication group and not to the group itself. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
* `transit_encryption_enabled` - (Optional) Whether to enable encryption in transit.
* `transit_encryption_mode` - (Optional) Valid values are `preferred` or `required`. When enabling encryption on an existing replication group, you must first set this to `preferred` before you can set it to `required`. Required when `transit_encryption_enabled` is `true`.
* `user_group_ids` - (Optional) User Group ID to associate with the replication group. Only a maximum of one (1) user group ID is valid. **NOTE:** This argument _is_ a set because the AWS specification allows for multiple IDs. However, in practice, AWS only allows a maximum size of one.

### Log Delivery Configuration
Expand Down