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/elasticache_replication_group: deprecations/addition of args to align with API #22666

Merged
merged 3 commits into from
Feb 2, 2022
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
23 changes: 23 additions & 0 deletions .changelog/22666.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```release-note:note
resource/aws_elasticache_replication_group: The `number_cache_clusters` argument has been deprecated. All configurations using `number_cache_clusters` should be updated to use the `num_cache_clusters` argument instead
```

```release-note:enhancement
resource/aws_elasticache_replication_group: Add `num_cache_clusters` argument
```

```release-note:note
resource/aws_elasticache_replication_group: The `replication_group_description` argument has been deprecated. All configurations using `replication_group_description` should be updated to use the `description` argument instead
```

```release-note:enhancement
resource/aws_elasticache_replication_group: Add `description` argument
```

```release-note:note
resource/aws_elasticache_replication_group: The `cluster_mode` argument has been deprecated. All configurations using `cluster_mode` should be updated to use the root-level `num_node_groups` and `replicas_per_node_group` arguments instead
```

```release-note:enhancement
resource/aws_elasticache_replication_group: Add `num_node_groups` and `replicas_per_node_group` arguments
```
149 changes: 123 additions & 26 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,27 @@ func ResourceReplicationGroup() *schema.Resource {
Computed: true,
},
"cluster_mode": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
ConflictsWith: []string{"num_node_groups", "replicas_per_node_group"},
Deprecated: "Use num_node_groups and replicas_per_node_group instead",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"num_node_groups": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"number_cache_clusters", "global_replication_group_id"},
ConflictsWith: []string{"num_node_groups", "number_cache_clusters", "num_cache_clusters", "global_replication_group_id"},
Deprecated: "Use root-level num_node_groups instead",
},
"replicas_per_node_group": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"replicas_per_node_group"},
Deprecated: "Use root-level replicas_per_node_group instead",
},
},
},
Expand All @@ -109,6 +115,12 @@ func ResourceReplicationGroup() *schema.Resource {
Computed: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"replication_group_description"},
},
"engine": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -132,7 +144,8 @@ func ResourceReplicationGroup() *schema.Resource {
ForceNew: true,
Computed: true,
ConflictsWith: []string{
"cluster_mode.0.num_node_groups", // should/will be top-level "num_node_groups"
"cluster_mode.0.num_node_groups",
"num_node_groups",
"parameter_group_name",
"engine",
"engine_version",
Expand Down Expand Up @@ -175,11 +188,24 @@ func ResourceReplicationGroup() *schema.Resource {
Optional: true,
ValidateFunc: verify.ValidARN,
},
"num_cache_clusters": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ConflictsWith: []string{"cluster_mode.0.num_node_groups", "num_node_groups", "number_cache_clusters"},
},
"num_node_groups": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"cluster_mode", "number_cache_clusters", "num_cache_clusters", "global_replication_group_id"},
},
"number_cache_clusters": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ConflictsWith: []string{"cluster_mode.0.num_node_groups"},
ConflictsWith: []string{"cluster_mode.0.num_node_groups", "num_cache_clusters", "num_node_groups"},
Deprecated: "Use num_cache_clusters instead",
},
"parameter_group_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -209,9 +235,18 @@ func ResourceReplicationGroup() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"replicas_per_node_group": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"cluster_mode"},
},
"replication_group_description": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"description"},
Deprecated: "Use description instead",
},
"replication_group_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -318,8 +353,11 @@ func ResourceReplicationGroup() *schema.Resource {
CustomizeDiffElastiCacheEngineVersion,
customdiff.ComputedIf("member_clusters", func(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
return diff.HasChange("number_cache_clusters") ||
diff.HasChange("num_cache_clusters") ||
diff.HasChange("cluster_mode.0.num_node_groups") ||
diff.HasChange("cluster_mode.0.replicas_per_node_group")
diff.HasChange("cluster_mode.0.replicas_per_node_group") ||
diff.HasChange("num_node_groups") ||
diff.HasChange("replicas_per_node_group")
}),
verify.SetTagsDiff,
),
Expand All @@ -332,10 +370,21 @@ func resourceReplicationGroupCreate(d *schema.ResourceData, meta interface{}) er
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{})))

params := &elasticache.CreateReplicationGroupInput{
ReplicationGroupId: aws.String(d.Get("replication_group_id").(string)),
ReplicationGroupDescription: aws.String(d.Get("replication_group_description").(string)),
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
Tags: Tags(tags.IgnoreAWS()),
ReplicationGroupId: aws.String(d.Get("replication_group_id").(string)),
AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)),
Tags: Tags(tags.IgnoreAWS()),
}

if v, ok := d.GetOk("description"); ok {
params.ReplicationGroupDescription = aws.String(v.(string))
}

if v, ok := d.GetOk("replication_group_description"); ok {
params.ReplicationGroupDescription = aws.String(v.(string))
}

if params.ReplicationGroupDescription == nil {
return errors.New("one of replication_group_description or description must be configured")
}

if v, ok := d.GetOk("data_tiering_enabled"); ok {
Expand Down Expand Up @@ -440,10 +489,22 @@ func resourceReplicationGroupCreate(d *schema.ResourceData, meta interface{}) er
}
}

if v, ok := d.GetOk("num_node_groups"); ok && v != 0 {
params.NumNodeGroups = aws.Int64(int64(v.(int)))
}

if v, ok := d.GetOk("replicas_per_node_group"); ok {
params.ReplicasPerNodeGroup = aws.Int64(int64(v.(int)))
}

if cacheClusters, ok := d.GetOk("number_cache_clusters"); ok {
params.NumCacheClusters = aws.Int64(int64(cacheClusters.(int)))
}

if numCacheClusters, ok := d.GetOk("num_cache_clusters"); ok {
params.NumCacheClusters = aws.Int64(int64(numCacheClusters.(int)))
}

if userGroupIds := d.Get("user_group_ids").(*schema.Set); userGroupIds.Len() > 0 {
params.UserGroupIds = flex.ExpandStringSet(userGroupIds)
}
Expand Down Expand Up @@ -521,14 +582,20 @@ func resourceReplicationGroupRead(d *schema.ResourceData, meta interface{}) erro
}

d.Set("kms_key_id", rgp.KmsKeyId)
d.Set("description", rgp.Description)
d.Set("replication_group_description", rgp.Description)
d.Set("number_cache_clusters", len(rgp.MemberClusters))
d.Set("num_cache_clusters", len(rgp.MemberClusters))
if err := d.Set("member_clusters", flex.FlattenStringSet(rgp.MemberClusters)); err != nil {
return fmt.Errorf("error setting member_clusters: %w", err)
}
if err := d.Set("cluster_mode", flattenElasticacheNodeGroupsToClusterMode(rgp.NodeGroups)); err != nil {
return fmt.Errorf("error setting cluster_mode attribute: %w", err)
}

d.Set("num_node_groups", len(rgp.NodeGroups))
d.Set("replicas_per_node_group", len(rgp.NodeGroups[0].NodeGroupMembers)-1)

d.Set("cluster_enabled", rgp.ClusterEnabled)
d.Set("replication_group_id", rgp.ReplicationGroupId)
d.Set("arn", rgp.ARN)
Expand Down Expand Up @@ -610,13 +677,24 @@ func resourceReplicationGroupRead(d *schema.ResourceData, meta interface{}) erro
func resourceReplicationGroupUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*conns.AWSClient).ElastiCacheConn

if d.HasChanges("cluster_mode.0.num_node_groups", "cluster_mode.0.replicas_per_node_group") {
if d.HasChanges(
"cluster_mode.0.num_node_groups",
"cluster_mode.0.replicas_per_node_group",
"num_node_groups",
"replicas_per_node_group",
) {
err := elasticacheReplicationGroupModifyShardConfiguration(conn, d)
if err != nil {
return fmt.Errorf("error modifying ElastiCache Replication Group (%s) shard configuration: %w", d.Id(), err)
}
} else if d.HasChange("number_cache_clusters") {
err := elasticacheReplicationGroupModifyNumCacheClusters(conn, d)
// TODO: remove when number_cache_clusters is removed from resource schema
err := elasticacheReplicationGroupModifyNumCacheClusters(conn, d, "number_cache_clusters")
if err != nil {
return fmt.Errorf("error modifying ElastiCache Replication Group (%s) clusters: %w", d.Id(), err)
}
} else if d.HasChange("num_cache_clusters") {
err := elasticacheReplicationGroupModifyNumCacheClusters(conn, d, "num_cache_clusters")
if err != nil {
return fmt.Errorf("error modifying ElastiCache Replication Group (%s) clusters: %w", d.Id(), err)
}
Expand All @@ -628,6 +706,11 @@ func resourceReplicationGroupUpdate(d *schema.ResourceData, meta interface{}) er
ReplicationGroupId: aws.String(d.Id()),
}

if d.HasChange("description") {
params.ReplicationGroupDescription = aws.String(d.Get("description").(string))
requestUpdate = true
}

if d.HasChange("replication_group_description") {
params.ReplicationGroupDescription = aws.String(d.Get("replication_group_description").(string))
requestUpdate = true
Expand Down Expand Up @@ -877,14 +960,28 @@ func flattenElasticacheNodeGroupsToClusterMode(nodeGroups []*elasticache.NodeGro

func elasticacheReplicationGroupModifyShardConfiguration(conn *elasticache.ElastiCache, d *schema.ResourceData) error {
if d.HasChange("cluster_mode.0.num_node_groups") {
err := elasticacheReplicationGroupModifyShardConfigurationNumNodeGroups(conn, d)
err := elasticacheReplicationGroupModifyShardConfigurationNumNodeGroups(conn, d, "cluster_mode.0.num_node_groups")
if err != nil {
return err
}
}

if d.HasChange("cluster_mode.0.replicas_per_node_group") {
err := elasticacheReplicationGroupModifyShardConfigurationReplicasPerNodeGroup(conn, d)
err := elasticacheReplicationGroupModifyShardConfigurationReplicasPerNodeGroup(conn, d, "cluster_mode.0.replicas_per_node_group")
if err != nil {
return err
}
}

if d.HasChange("num_node_groups") {
err := elasticacheReplicationGroupModifyShardConfigurationNumNodeGroups(conn, d, "num_node_groups")
if err != nil {
return err
}
}

if d.HasChange("replicas_per_node_group") {
err := elasticacheReplicationGroupModifyShardConfigurationReplicasPerNodeGroup(conn, d, "replicas_per_node_group")
if err != nil {
return err
}
Expand All @@ -893,8 +990,8 @@ func elasticacheReplicationGroupModifyShardConfiguration(conn *elasticache.Elast
return nil
}

func elasticacheReplicationGroupModifyShardConfigurationNumNodeGroups(conn *elasticache.ElastiCache, d *schema.ResourceData) error {
o, n := d.GetChange("cluster_mode.0.num_node_groups")
func elasticacheReplicationGroupModifyShardConfigurationNumNodeGroups(conn *elasticache.ElastiCache, d *schema.ResourceData, argument string) error {
o, n := d.GetChange(argument)
oldNumNodeGroups := o.(int)
newNumNodeGroups := n.(int)

Expand Down Expand Up @@ -929,8 +1026,8 @@ func elasticacheReplicationGroupModifyShardConfigurationNumNodeGroups(conn *elas
return nil
}

func elasticacheReplicationGroupModifyShardConfigurationReplicasPerNodeGroup(conn *elasticache.ElastiCache, d *schema.ResourceData) error {
o, n := d.GetChange("cluster_mode.0.replicas_per_node_group")
func elasticacheReplicationGroupModifyShardConfigurationReplicasPerNodeGroup(conn *elasticache.ElastiCache, d *schema.ResourceData, argument string) error {
o, n := d.GetChange(argument)
oldReplicas := o.(int)
newReplicas := n.(int)

Expand Down Expand Up @@ -967,8 +1064,8 @@ func elasticacheReplicationGroupModifyShardConfigurationReplicasPerNodeGroup(con
return nil
}

func elasticacheReplicationGroupModifyNumCacheClusters(conn *elasticache.ElastiCache, d *schema.ResourceData) error {
o, n := d.GetChange("number_cache_clusters")
func elasticacheReplicationGroupModifyNumCacheClusters(conn *elasticache.ElastiCache, d *schema.ResourceData, argument string) error {
o, n := d.GetChange(argument)
oldNumberCacheClusters := o.(int)
newNumberCacheClusters := n.(int)

Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/elasticache_replication_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ The following arguments are optional:
* `transit_encryption_enabled` - (Optional) Whether to enable encryption in transit.
* `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.

### cluster_mode
### cluster_mode (**DEPRECATED**)

* `num_node_groups` - (Optional) Number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications. Required unless `global_replication_group_id` is set.
* `replicas_per_node_group` - (Required) Number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will trigger an online resizing operation before other settings modifications.
* `num_node_groups` - (Optional, **Deprecated** use root-level `num_node_groups` instead) Number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications. Required unless `global_replication_group_id` is set.
* `replicas_per_node_group` - (Optional, Required with `cluster_mode` `num_node_groups`, **Deprecated** use root-level `replicas_per_node_group` instead) Number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will trigger an online resizing operation before other settings modifications.

## Attributes Reference

Expand Down