From eec7b342c8e6dd49cdb79b2a29d3137d98e5d343 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 24 Aug 2016 10:55:20 +0100 Subject: [PATCH] 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 ``` ``` --- .../aws/resource_aws_elasticache_cluster.go | 13 +++++++++++-- .../resource_aws_elasticache_replication_group.go | 6 +++++- .../aws/r/elasticache_cluster.html.markdown | 2 ++ .../r/elasticache_replication_group.html.markdown | 6 +++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index d24201457..10e62f9e6 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -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, @@ -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), @@ -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)) } @@ -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"}, diff --git a/builtin/providers/aws/resource_aws_elasticache_replication_group.go b/builtin/providers/aws/resource_aws_elasticache_replication_group.go index 317d37d9e..4bb42261a 100644 --- a/builtin/providers/aws/resource_aws_elasticache_replication_group.go +++ b/builtin/providers/aws/resource_aws_elasticache_replication_group.go @@ -126,6 +126,10 @@ 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) @@ -133,7 +137,7 @@ func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta i d.SetId(*resp.ReplicationGroup.ReplicationGroupId) - pending := []string{"creating", "modifying"} + pending := []string{"creating", "modifying", "restoring"} stateConf := &resource.StateChangeConf{ Pending: pending, Target: []string{"available"}, diff --git a/website/source/docs/providers/aws/r/elasticache_cluster.html.markdown b/website/source/docs/providers/aws/r/elasticache_cluster.html.markdown index 9f24185b8..68df6362b 100644 --- a/website/source/docs/providers/aws/r/elasticache_cluster.html.markdown +++ b/website/source/docs/providers/aws/r/elasticache_cluster.html.markdown @@ -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 diff --git a/website/source/docs/providers/aws/r/elasticache_replication_group.html.markdown b/website/source/docs/providers/aws/r/elasticache_replication_group.html.markdown index e986d89a5..bc520884b 100644 --- a/website/source/docs/providers/aws/r/elasticache_replication_group.html.markdown +++ b/website/source/docs/providers/aws/r/elasticache_replication_group.html.markdown @@ -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 @@ -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` @@ -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. \ No newline at end of file +* `id` - The ID of the ElastiCache Replication Group \ No newline at end of file