Skip to content

Commit

Permalink
Merge pull request #20406 from jamesglennan/elasticacheUsergroup
Browse files Browse the repository at this point in the history
Add user_group_ids field to elasticache replication group
  • Loading branch information
YakDriver authored Jan 26, 2022
2 parents c47375e + d2fd521 commit a91804e
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .changelog/20406.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_elasticache_replication_group: Add `user_group_ids` to associate `aws_elasticache_user_group` with `aws_elasticache_replication_group`
```
44 changes: 39 additions & 5 deletions internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ func ResourceReplicationGroup() *schema.Resource {
Computed: true,
},
"auth_token": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validReplicationGroupAuthToken,
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validReplicationGroupAuthToken,
ConflictsWith: []string{"user_group_ids"},
},
"auto_minor_version_upgrade": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -280,6 +281,13 @@ func ResourceReplicationGroup() *schema.Resource {
ForceNew: true,
Computed: true,
},
"user_group_ids": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
ConflictsWith: []string{"auth_token"},
},
"kms_key_id": {
Type: schema.TypeString,
ForceNew: true,
Expand Down Expand Up @@ -435,6 +443,11 @@ func resourceReplicationGroupCreate(d *schema.ResourceData, meta interface{}) er
if cacheClusters, ok := d.GetOk("number_cache_clusters"); ok {
params.NumCacheClusters = aws.Int64(int64(cacheClusters.(int)))
}

if userGroupIds := d.Get("user_group_ids").(*schema.Set); userGroupIds.Len() > 0 {
params.UserGroupIds = flex.ExpandStringSet(userGroupIds)
}

resp, err := conn.CreateReplicationGroup(params)
if err != nil {
return fmt.Errorf("error creating ElastiCache Replication Group (%s): %w", d.Get("replication_group_id").(string), err)
Expand Down Expand Up @@ -580,8 +593,10 @@ func resourceReplicationGroupRead(d *schema.ResourceData, meta interface{}) erro
d.Set("reader_endpoint_address", rgp.NodeGroups[0].ReaderEndpoint.Address)
}

d.Set("auto_minor_version_upgrade", c.AutoMinorVersionUpgrade)
d.Set("user_group_ids", rgp.UserGroupIds)

d.Set("at_rest_encryption_enabled", c.AtRestEncryptionEnabled)
d.Set("auto_minor_version_upgrade", c.AutoMinorVersionUpgrade)
d.Set("transit_encryption_enabled", c.TransitEncryptionEnabled)

if c.AuthTokenEnabled != nil && !aws.BoolValue(c.AuthTokenEnabled) {
Expand Down Expand Up @@ -688,6 +703,25 @@ func resourceReplicationGroupUpdate(d *schema.ResourceData, meta interface{}) er
requestUpdate = true
}

if d.HasChange("user_group_ids") {
old, new := d.GetChange("user_group_ids")
newSet := new.(*schema.Set)
oldSet := old.(*schema.Set)
add := newSet.Difference(oldSet)
remove := oldSet.Difference(newSet)

if add.Len() > 0 {
params.UserGroupIdsToAdd = flex.ExpandStringSet(add)
requestUpdate = true
}

if remove.Len() > 0 {
params.UserGroupIdsToRemove = flex.ExpandStringSet(remove)
requestUpdate = true
}

}

if requestUpdate {
_, err := conn.ModifyReplicationGroup(params)
if err != nil {
Expand Down
Loading

0 comments on commit a91804e

Please sign in to comment.