From 65c9350f22b87e965e4cfb39a61f720f48e90cb4 Mon Sep 17 00:00:00 2001 From: stack72 Date: Fri, 30 Oct 2015 22:16:48 +0000 Subject: [PATCH 1/2] Adding the placement_group to the AutoScalingGroup resource --- .../aws/resource_aws_autoscaling_group.go | 14 ++++++++++++++ .../aws/resource_aws_autoscaling_group_test.go | 5 ++++- .../aws/r/autoscaling_group.html.markdown | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index f457e6dcd1bf..643bf5394e43 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -102,6 +102,11 @@ func resourceAwsAutoscalingGroup() *schema.Resource { Set: schema.HashString, }, + "placement_group": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "vpc_zone_identifier": &schema.Schema{ Type: schema.TypeSet, Optional: true, @@ -188,6 +193,10 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) autoScalingGroupOpts.TerminationPolicies = expandStringList(v.([]interface{})) } + if v, ok := d.GetOk("placement_group"); ok { + autoScalingGroupOpts.PlacementGroup = aws.String(v.(string)) + } + log.Printf("[DEBUG] AutoScaling Group create configuration: %#v", autoScalingGroupOpts) _, err := conn.CreateAutoScalingGroup(&autoScalingGroupOpts) if err != nil { @@ -222,6 +231,7 @@ func resourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) e d.Set("load_balancers", g.LoadBalancerNames) d.Set("min_size", g.MinSize) d.Set("max_size", g.MaxSize) + d.Set("placement_group", g.PlacementGroup) d.Set("name", g.AutoScalingGroupName) d.Set("tag", g.Tags) d.Set("vpc_zone_identifier", strings.Split(*g.VPCZoneIdentifier, ",")) @@ -276,6 +286,10 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) } } + if d.HasChange("placement_group") { + opts.PlacementGroup = aws.String(d.Get("placement_group").(string)) + } + if d.HasChange("termination_policies") { // If the termination policy is set to null, we need to explicitly set // it back to "Default", or the API won't reset it for us. diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index 1a25c9dea9dd..e3171a5062c5 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -48,6 +48,8 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) { "aws_autoscaling_group.bar", "termination_policies.0", "OldestInstance"), resource.TestCheckResourceAttr( "aws_autoscaling_group.bar", "termination_policies.1", "ClosestToNextInstanceHour"), + resource.TestCheckResourceAttr( + "aws_autoscaling_group.bar", "placement_group", "test"), ), }, @@ -364,8 +366,9 @@ resource "aws_autoscaling_group" "bar" { desired_capacity = 4 force_delete = true termination_policies = ["OldestInstance","ClosestToNextInstanceHour"] + placement_group = "test" - launch_configuration = "${aws_launch_configuration.foobar.name}" + launch_configuration = "${aws_launch_configuration.foobar.id}" tag { key = "Foo" diff --git a/website/source/docs/providers/aws/r/autoscaling_group.html.markdown b/website/source/docs/providers/aws/r/autoscaling_group.html.markdown index 7cb1661426c6..902439dc0bc9 100644 --- a/website/source/docs/providers/aws/r/autoscaling_group.html.markdown +++ b/website/source/docs/providers/aws/r/autoscaling_group.html.markdown @@ -13,6 +13,11 @@ Provides an AutoScaling Group resource. ## Example Usage ``` +resource "aws_placement_group" "test" { + name = "test" + strategy = "cluster" +} + resource "aws_autoscaling_group" "bar" { availability_zones = ["us-east-1a"] name = "foobar3-terraform-test" @@ -22,6 +27,7 @@ resource "aws_autoscaling_group" "bar" { health_check_type = "ELB" desired_capacity = 4 force_delete = true + placement_group = "${aws_placement_group.test.id}" launch_configuration = "${aws_launch_configuration.foobar.name}" tag { @@ -66,6 +72,7 @@ The following arguments are supported: * `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. * `termination_policies` (Optional) A list of policies to decide how the instances in the auto scale group should be terminated. * `tag` (Optional) A list of tag blocks. Tags documented below. +* `placement_group` (Optional) The name of the placement group into which you'll launch your instances, if any. * `wait_for_capacity_timeout` (Default: "10m") A maximum [duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should wait for ASG instances to be healthy before timing out. (See also [Waiting From 7ac8f548fd0a90609aa920ffb54fbc388ef632d0 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Fri, 30 Oct 2015 22:20:12 +0000 Subject: [PATCH 2/2] Update resource_aws_autoscaling_group_test.go --- builtin/providers/aws/resource_aws_autoscaling_group_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index e3171a5062c5..bf8b56c08ef8 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -368,7 +368,7 @@ resource "aws_autoscaling_group" "bar" { termination_policies = ["OldestInstance","ClosestToNextInstanceHour"] placement_group = "test" - launch_configuration = "${aws_launch_configuration.foobar.id}" + launch_configuration = "${aws_launch_configuration.foobar.name}" tag { key = "Foo"