Skip to content

Commit

Permalink
Merge pull request #27500 from hashicorp/f-elasticache-global-shards
Browse files Browse the repository at this point in the history
resource/aws_elasticache_global_replication_group: Allow configuring shards
  • Loading branch information
gdavison authored Oct 27, 2022
2 parents d28719d + 4d965f6 commit 5d465dd
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .changelog/27500.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_elasticache_global_replication_group: Add `global_node_groups` and `num_node_groups` arguments
```

```release-note:enhancement
resource/aws_elasticache_global_replication_group: Add timeouts.
```
206 changes: 188 additions & 18 deletions internal/service/elasticache/global_replication_group.go

Large diffs are not rendered by default.

323 changes: 318 additions & 5 deletions internal/service/elasticache/global_replication_group_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func resourceReplicationGroupCreate(d *schema.ResourceData, meta interface{}) er
// state, but the global replication group can still be in the "modifying" state. Wait for the replication group
// to be fully added to the global replication group.
// API calls to the global replication group can be made in any region.
if _, err := waitGlobalReplicationGroupAvailable(context.TODO(), conn, v.(string), GlobalReplicationGroupDefaultCreatedTimeout); err != nil {
if _, err := waitGlobalReplicationGroupAvailable(context.TODO(), conn, v.(string), globalReplicationGroupDefaultCreatedTimeout); err != nil {
return fmt.Errorf("error waiting for ElastiCache Global Replication Group (%s) to be available: %w", v, err)
}
}
Expand Down
12 changes: 4 additions & 8 deletions internal/service/elasticache/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,13 @@ func sweepGlobalReplicationGroups(region string) error {

disassociationErrors := DisassociateMembers(conn, globalReplicationGroup)
if disassociationErrors != nil {
sweeperErr := fmt.Errorf("failed to disassociate ElastiCache Global Replication Group (%s) members: %w", id, disassociationErrors)
log.Printf("[ERROR] %s", sweeperErr)
return sweeperErr
return fmt.Errorf("disassociating ElastiCache Global Replication Group (%s) members: %w", id, disassociationErrors)
}

log.Printf("[INFO] Deleting ElastiCache Global Replication Group: %s", id)
err := deleteGlobalReplicationGroup(ctx, conn, id, sweeperGlobalReplicationGroupDefaultUpdatedTimeout)
err := deleteGlobalReplicationGroup(ctx, conn, id, sweeperGlobalReplicationGroupDefaultUpdatedTimeout, globalReplicationGroupDefaultDeletedTimeout)
if err != nil {
sweeperErr := fmt.Errorf("error deleting ElastiCache Global Replication Group (%s): %w", id, err)
log.Printf("[ERROR] %s", sweeperErr)
return sweeperErr
return fmt.Errorf("deleting ElastiCache Global Replication Group (%s): %w", id, err)
}
return nil
})
Expand All @@ -173,7 +169,7 @@ func sweepGlobalReplicationGroups(region string) error {
}

if err != nil {
grgErrs = multierror.Append(grgErrs, fmt.Errorf("error listing ElastiCache Global Replication Groups: %w", err))
grgErrs = multierror.Append(grgErrs, fmt.Errorf("listing ElastiCache Global Replication Groups: %w", err))
}

return grgErrs.ErrorOrNil()
Expand Down
12 changes: 6 additions & 6 deletions internal/service/elasticache/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func WaitCacheClusterDeleted(conn *elasticache.ElastiCache, cacheClusterID strin
}

const (
GlobalReplicationGroupDefaultCreatedTimeout = 25 * time.Minute
GlobalReplicationGroupDefaultUpdatedTimeout = 40 * time.Minute
GlobalReplicationGroupDefaultDeletedTimeout = 20 * time.Minute
globalReplicationGroupDefaultCreatedTimeout = 60 * time.Minute
globalReplicationGroupDefaultUpdatedTimeout = 60 * time.Minute
globalReplicationGroupDefaultDeletedTimeout = 20 * time.Minute

globalReplicationGroupAvailableMinTimeout = 10 * time.Second
globalReplicationGroupAvailableDelay = 30 * time.Second
Expand Down Expand Up @@ -181,8 +181,8 @@ func waitGlobalReplicationGroupAvailable(ctx context.Context, conn *elasticache.
return nil, err
}

// WaitGlobalReplicationGroupDeleted waits for a Global Replication Group to be deleted
func WaitGlobalReplicationGroupDeleted(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID string) (*elasticache.GlobalReplicationGroup, error) {
// waitGlobalReplicationGroupDeleted waits for a Global Replication Group to be deleted
func waitGlobalReplicationGroupDeleted(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID string, timeout time.Duration) (*elasticache.GlobalReplicationGroup, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
GlobalReplicationGroupStatusAvailable,
Expand All @@ -192,7 +192,7 @@ func WaitGlobalReplicationGroupDeleted(ctx context.Context, conn *elasticache.El
},
Target: []string{},
Refresh: statusGlobalReplicationGroup(ctx, conn, globalReplicationGroupID),
Timeout: GlobalReplicationGroupDefaultDeletedTimeout,
Timeout: timeout,
MinTimeout: globalReplicationGroupDeletedMinTimeout,
Delay: globalReplicationGroupDeletedDelay,
}
Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/elasticache_global_replication_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The following arguments are supported:
* `global_replication_group_id_suffix` – (Required) The suffix name of a Global Datastore. If `global_replication_group_id_suffix` is changed, creates a new resource.
* `primary_replication_group_id` – (Required) The ID of the primary cluster that accepts writes and will replicate updates to the secondary cluster. If `primary_replication_group_id` is changed, creates a new resource.
* `global_replication_group_description` – (Optional) A user-created description for the global replication group.
* `num_node_groups` - (Optional) The number of node groups (shards) on the global replication group.
* `parameter_group_name` - (Optional) An ElastiCache Parameter Group to use for the Global Replication Group.
Required when upgrading a major engine version, but will be ignored if left configured after the upgrade is complete.
Specifying without a major version upgrade will fail.
Expand All @@ -133,8 +134,20 @@ In addition to all arguments above, the following attributes are exported:
* `cluster_enabled` - Indicates whether the Global Datastore is cluster enabled.
* `engine` - The name of the cache engine to be used for the clusters in this global replication group.
* `global_replication_group_id` - The full ID of the global replication group.
* `global_node_groups` - Set of node groups (shards) on the global replication group.
Has the values:
* `global_node_group_id` - The ID of the global node group.
* `slots` - The keyspace for this node group.
* `transit_encryption_enabled` - A flag that indicates whether the encryption in transit is enabled.

## Timeouts

[Configuration options](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts):

* `create` - (Default `60m`)
* `update` - (Default `60m`)
* `delete` - (Default `20m`)

## Import

ElastiCache Global Replication Groups can be imported using the `global_replication_group_id`, e.g.,
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/elasticache_replication_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,14 @@ The following arguments are optional:
* `notification_topic_arn` – (Optional) ARN of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic`
* `number_cache_clusters` - (Optional, **Deprecated** use `num_cache_clusters` instead) 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. Conflicts with `num_cache_clusters`, `num_node_groups`, or the deprecated `cluster_mode`. Defaults to `1`.
* `num_cache_clusters` - (Optional) 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. Conflicts with `num_node_groups`, the deprecated`number_cache_clusters`, or the deprecated `cluster_mode`. Defaults to `1`.
* `num_node_groups` - (Optional) Number of node groups (shards) for this Redis replication group.
Changing this number will trigger a resizing operation before other settings modifications.
* `parameter_group_name` - (Optional) Name of the parameter group to associate with this replication group. If this argument is omitted, the default cache parameter group for the specified engine is used. To enable "cluster mode", i.e., data sharding, use a parameter group that has the parameter `cluster-enabled` set to true.
* `port` – (Optional) Port number on which each of the cache nodes will accept connections. For Memcache the default is 11211, and for Redis the default port is 6379.
* `preferred_cache_cluster_azs` - (Optional) List of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is considered. The first item in the list will be the primary node. Ignored when updating.
* `replicas_per_node_group` - (Optional) Number of replica nodes in each node group.
Changing this number will trigger a resizing operation before other settings modifications.
Valid values are 0 to 5.
* `security_group_ids` - (Optional) One or more Amazon VPC security groups associated with this replication group. Use this parameter only when you are creating a replication group in an Amazon Virtual Private Cloud
* `security_group_names` - (Optional) List of cache security group names to associate with this replication group.
* `snapshot_arns` – (Optional) List of ARNs that identify Redis RDB snapshot files stored in Amazon S3. The names object names cannot contain any commas.
Expand Down

0 comments on commit 5d465dd

Please sign in to comment.