Skip to content

Commit

Permalink
provider/aws: Support snapshot_name for ElastiCache Cluster and (ha…
Browse files Browse the repository at this point in the history
…shicorp#8419)

Replication Groups

In order to be able to restore a named snapshot as ElastiCache Cluster
or a Replication Group, the `snapshot_name` parameter was needed to be
passed. Changing the `snapshot_name` will force a new resource to be
created

```

```
  • Loading branch information
stack72 authored and Richard Bowden committed Aug 27, 2016
1 parent a4e1aff commit c25932e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
13 changes: 11 additions & 2 deletions builtin/providers/aws/resource_aws_elasticache_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func resourceAwsElastiCacheCommonSchema() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"snapshot_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"maintenance_window": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -220,8 +225,8 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{

securityNames := expandStringList(securityNameSet.List())
securityIds := expandStringList(securityIdSet.List())

tags := tagsFromMapEC(d.Get("tags").(map[string]interface{}))

req := &elasticache.CreateCacheClusterInput{
CacheClusterId: aws.String(clusterId),
CacheNodeType: aws.String(nodeType),
Expand Down Expand Up @@ -263,6 +268,10 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
log.Printf("[DEBUG] Restoring Redis cluster from S3 snapshot: %#v", s)
}

if v, ok := d.GetOk("snapshot_name"); ok {
req.SnapshotName = aws.String(v.(string))
}

if v, ok := d.GetOk("az_mode"); ok {
req.AZMode = aws.String(v.(string))
}
Expand Down Expand Up @@ -292,7 +301,7 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
// name contained uppercase characters.
d.SetId(strings.ToLower(*resp.CacheCluster.CacheClusterId))

pending := []string{"creating"}
pending := []string{"creating", "modifying", "restoring"}
stateConf := &resource.StateChangeConf{
Pending: pending,
Target: []string{"available"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta i
params.SnapshotWindow = aws.String(v.(string))
}

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

resp, err := conn.CreateReplicationGroup(params)
if err != nil {
return fmt.Errorf("Error creating Elasticache Replication Group: %s", err)
}

d.SetId(*resp.ReplicationGroup.ReplicationGroupId)

pending := []string{"creating", "modifying"}
pending := []string{"creating", "modifying", "restoring"}
stateConf := &resource.StateChangeConf{
Pending: pending,
Target: []string{"available"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ names to associate with this cache cluster
Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3.
Example: `arn:aws:s3:::my_bucket/snapshot1.rdb`

* `snapshot_name` - (Optional) The name of a snapshot from which to restore data into the new node group. Changing the `snapshot_name` forces a new resource.

* `snapshot_window` - (Optional, Redis only) The daily time range (in UTC) during which ElastiCache will
begin taking a daily snapshot of your cache cluster. Example: 05:00-09:00

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "aws_elasticache_replication_group" "bar" {

The following arguments are supported:

* `replication_group_id` – (Required) The replication group identifier.
* `replication_group_id` – (Required) The replication group identifier. This parameter is stored as a lowercase string.
* `replication_group_description` – (Required) A user-created description for the replication group.
* `number_cache_clusters` - (Required) The number of cache clusters this replication group will have.
If Multi-AZ is enabled , the value of this parameter must be at least 2. Changing this number will force a new resource
Expand All @@ -46,6 +46,7 @@ The following arguments are supported:
* `snapshot_arns` – (Optional) A single-element string list containing an
Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3.
Example: `arn:aws:s3:::my_bucket/snapshot1.rdb`
* `snapshot_name` - (Optional) The name of a snapshot from which to restore data into the new node group. Changing the `snapshot_name` forces a new resource.
* `maintenance_window` – (Optional) Specifies the weekly time range for when maintenance
on the cache cluster is performed. The format is `ddd:hh24:mi-ddd:hh24:mi` (24H Clock UTC).
The minimum maintenance window is a 60 minute period. Example: `sun:05:00-sun:09:00`
Expand All @@ -66,5 +67,4 @@ Please note that setting a `snapshot_retention_limit` is not supported on cache.

The following attributes are exported:

* `id` - The ID of the ElastiCache Replication Group
* `primary_endpoint_address` - The Address of the Primary Node in the replication group. Doesn't include the port.
* `id` - The ID of the ElastiCache Replication Group

0 comments on commit c25932e

Please sign in to comment.