Add availability_zone parameter.

Signed-off-by: wata727 <watassbass@gmail.com>
This commit is contained in:
wata_mac 2016-01-11 23:33:21 +09:00
parent 6d1d46c47c
commit df56ef44f7
3 changed files with 27 additions and 5 deletions

View File

@ -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,
})
}

View File

@ -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" {

View File

@ -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