provider/aws: Support `snapshot_name` for ElastiCache Cluster and (#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

```

```
This commit is contained in:
Paul Stack 2016-08-24 10:55:20 +01:00 committed by GitHub
parent f21ec6ce9a
commit eec7b342c8
4 changed files with 21 additions and 6 deletions

View File

@ -81,6 +81,11 @@ func resourceAwsElastiCacheCommonSchema() map[string]*schema.Schema {
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"snapshot_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"maintenance_window": &schema.Schema{ "maintenance_window": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -220,8 +225,8 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
securityNames := expandStringList(securityNameSet.List()) securityNames := expandStringList(securityNameSet.List())
securityIds := expandStringList(securityIdSet.List()) securityIds := expandStringList(securityIdSet.List())
tags := tagsFromMapEC(d.Get("tags").(map[string]interface{})) tags := tagsFromMapEC(d.Get("tags").(map[string]interface{}))
req := &elasticache.CreateCacheClusterInput{ req := &elasticache.CreateCacheClusterInput{
CacheClusterId: aws.String(clusterId), CacheClusterId: aws.String(clusterId),
CacheNodeType: aws.String(nodeType), CacheNodeType: aws.String(nodeType),
@ -263,6 +268,10 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
log.Printf("[DEBUG] Restoring Redis cluster from S3 snapshot: %#v", s) 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 { if v, ok := d.GetOk("az_mode"); ok {
req.AZMode = aws.String(v.(string)) req.AZMode = aws.String(v.(string))
} }
@ -292,7 +301,7 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
// name contained uppercase characters. // name contained uppercase characters.
d.SetId(strings.ToLower(*resp.CacheCluster.CacheClusterId)) d.SetId(strings.ToLower(*resp.CacheCluster.CacheClusterId))
pending := []string{"creating"} pending := []string{"creating", "modifying", "restoring"}
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: pending, Pending: pending,
Target: []string{"available"}, Target: []string{"available"},

View File

@ -126,6 +126,10 @@ func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta i
params.SnapshotWindow = aws.String(v.(string)) 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) resp, err := conn.CreateReplicationGroup(params)
if err != nil { if err != nil {
return fmt.Errorf("Error creating Elasticache Replication Group: %s", err) return fmt.Errorf("Error creating Elasticache Replication Group: %s", err)
@ -133,7 +137,7 @@ func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta i
d.SetId(*resp.ReplicationGroup.ReplicationGroupId) d.SetId(*resp.ReplicationGroup.ReplicationGroupId)
pending := []string{"creating", "modifying"} pending := []string{"creating", "modifying", "restoring"}
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: pending, Pending: pending,
Target: []string{"available"}, Target: []string{"available"},

View File

@ -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. Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3.
Example: `arn:aws:s3:::my_bucket/snapshot1.rdb` 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 * `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 begin taking a daily snapshot of your cache cluster. Example: 05:00-09:00

View File

@ -31,7 +31,7 @@ resource "aws_elasticache_replication_group" "bar" {
The following arguments are supported: 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. * `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. * `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 If Multi-AZ is enabled , the value of this parameter must be at least 2. Changing this number will force a new resource
@ -46,6 +46,7 @@ The following arguments are supported:
* `snapshot_arns`  (Optional) A single-element string list containing an * `snapshot_arns`  (Optional) A single-element string list containing an
Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3.
Example: `arn:aws:s3:::my_bucket/snapshot1.rdb` 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 * `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). 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` The minimum maintenance window is a 60 minute period. Example: `sun:05:00-sun:09:00`
@ -67,4 +68,3 @@ Please note that setting a `snapshot_retention_limit` is not supported on cache.
The following attributes are exported: The following attributes are exported:
* `id` - The ID of the ElastiCache Replication Group * `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.