diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index c7686f5f3f..7a1448c26b 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -120,6 +120,10 @@ func resourceAwsElasticacheCluster() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + "availability_zone": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -162,6 +166,13 @@ func resourceAwsElasticacheCluster() *schema.Resource { }, }, + "availability_zone": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "tags": tagsSchema(), // apply_immediately is used to determine when the update modifications @@ -234,6 +245,10 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Restoring Redis cluster from S3 snapshot: %#v", s) } + if v, ok := d.GetOk("availability_zone"); ok { + req.PreferredAvailabilityZone = aws.String(v.(string)) + } + resp, err := conn.CreateCacheCluster(req) if err != nil { return fmt.Errorf("Error creating Elasticache: %s", err) @@ -306,6 +321,7 @@ func resourceAwsElasticacheClusterRead(d *schema.ResourceData, meta interface{}) d.Set("notification_topic_arn", c.NotificationConfiguration.TopicArn) } } + d.Set("availability_zone", c.PreferredAvailabilityZone) if err := setCacheNodeData(d, c); err != nil { return err @@ -454,13 +470,14 @@ func setCacheNodeData(d *schema.ResourceData, c *elasticache.CacheCluster) error cacheNodeData := make([]map[string]interface{}, 0, len(sortedCacheNodes)) for _, node := range sortedCacheNodes { - if node.CacheNodeId == nil || node.Endpoint == nil || node.Endpoint.Address == nil || node.Endpoint.Port == nil { + if node.CacheNodeId == nil || node.Endpoint == nil || node.Endpoint.Address == nil || node.Endpoint.Port == nil || node.CustomerAvailabilityZone == nil { return fmt.Errorf("Unexpected nil pointer in: %s", node) } cacheNodeData = append(cacheNodeData, map[string]interface{}{ - "id": *node.CacheNodeId, - "address": *node.Endpoint.Address, - "port": int(*node.Endpoint.Port), + "id": *node.CacheNodeId, + "address": *node.Endpoint.Address, + "port": int(*node.Endpoint.Port), + "availability_zone": *node.CustomerAvailabilityZone, }) } diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster_test.go b/builtin/providers/aws/resource_aws_elasticache_cluster_test.go index f8372d2b9f..24442dbf50 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster_test.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster_test.go @@ -122,6 +122,8 @@ func TestAccAWSElasticacheCluster_vpc(t *testing.T) { testAccCheckAWSElasticacheSubnetGroupExists("aws_elasticache_subnet_group.bar", &csg), testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar", &ec), testAccCheckAWSElasticacheClusterAttributes(&ec), + resource.TestCheckResourceAttr( + "aws_elasticache_cluster.bar", "availability_zone", "us-west-2a"), ), }, }, @@ -414,6 +416,7 @@ resource "aws_elasticache_cluster" "bar" { security_group_ids = ["${aws_security_group.bar.id}"] parameter_group_name = "default.redis2.8" notification_topic_arn = "${aws_sns_topic.topic_example.arn}" + availability_zone = "us-west-2a" } resource "aws_sns_topic" "topic_example" { 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 707487c9eb..e32a70cf16 100644 --- a/website/source/docs/providers/aws/r/elasticache_cluster.html.markdown +++ b/website/source/docs/providers/aws/r/elasticache_cluster.html.markdown @@ -98,6 +98,8 @@ Can only be used for the Redis engine. SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic` +* `availability_zone` - (Optional) The AZ for the cache cluster. + * `tags` - (Optional) A mapping of tags to assign to the resource. ~> **NOTE:** Snapshotting functionality is not compatible with t2 instance types. @@ -106,7 +108,7 @@ SNS topic to send ElastiCache notifications to. Example: The following attributes are exported: -* `cache_nodes` - List of node objects including `id`, `address` and `port`. +* `cache_nodes` - List of node objects including `id`, `address`, `port` and `availability_zone`. Referenceable e.g. as `${aws_elasticache_cluster.bar.cache_nodes.0.address}` * `configuration_endpoint` - (Memcached only) The configuration endpoint to allow host discovery