From 006cac56a2ff3f21a2507332101d631af347319b Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Fri, 30 Oct 2015 16:45:19 -0500 Subject: [PATCH 1/7] added placement group as an option for autoscaling groups --- .../providers/aws/resource_aws_autoscaling_group.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index f457e6dcd..b74b2b6cc 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -95,6 +95,13 @@ func resourceAwsAutoscalingGroup() *schema.Resource { Set: schema.HashString, }, + "placement_group": &schema.Schema{ + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + }, + "load_balancers": &schema.Schema{ Type: schema.TypeSet, Optional: true, @@ -175,6 +182,11 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) autoScalingGroupOpts.HealthCheckGracePeriod = aws.Int64(int64(v.(int))) } + if v, ok := d.GetOk("placement_group"); ok && v.(*schema.Set).Len() > 0 { + autoScalingGroupOpts.PlacementGroup = expandStringList( + v.(*schema.Set).List()) + } + if v, ok := d.GetOk("load_balancers"); ok && v.(*schema.Set).Len() > 0 { autoScalingGroupOpts.LoadBalancerNames = expandStringList( v.(*schema.Set).List()) From 0d2007e8bd788e434ed2d4c5ea907d8f7c0dbcdc Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Mon, 2 Nov 2015 09:26:25 -0600 Subject: [PATCH 2/7] as per advice from stack72, simplified --- builtin/providers/aws/resource_aws_autoscaling_group.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index b74b2b6cc..6c2716b54 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -96,10 +96,8 @@ func resourceAwsAutoscalingGroup() *schema.Resource { }, "placement_group": &schema.Schema{ - Type: schema.TypeSet, + Type: schema.TypeString, Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "load_balancers": &schema.Schema{ From 68c7baa20e870e1db3a92d89416c7f31de974617 Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Mon, 2 Nov 2015 09:33:35 -0600 Subject: [PATCH 3/7] as per advice from stack72 to stick to strings --- builtin/providers/aws/resource_aws_autoscaling_group.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 6c2716b54..626bd7b5d 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -180,9 +180,8 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) autoScalingGroupOpts.HealthCheckGracePeriod = aws.Int64(int64(v.(int))) } - if v, ok := d.GetOk("placement_group"); ok && v.(*schema.Set).Len() > 0 { - autoScalingGroupOpts.PlacementGroup = expandStringList( - v.(*schema.Set).List()) + if v, ok := d.GetOk("placement_group"); ok { + autoScalingGroupOpts.PlacementGroup = aws.String(v.(string)) } if v, ok := d.GetOk("load_balancers"); ok && v.(*schema.Set).Len() > 0 { From c7b02d9fdb8aa7b219fb814f45c55ddb5588c19b Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Mon, 2 Nov 2015 09:33:46 -0600 Subject: [PATCH 4/7] handling updates --- builtin/providers/aws/resource_aws_autoscaling_group.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 626bd7b5d..4f166ce50 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -231,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, ",")) @@ -285,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. From df41f10d1d09af6d5b217c4e3cdebfd94d5c0cd0 Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Mon, 2 Nov 2015 09:37:09 -0600 Subject: [PATCH 5/7] tests! yes! (thanks stack72) --- builtin/providers/aws/resource_aws_autoscaling_group_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index 1a25c9dea..bf8b56c08 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,6 +366,7 @@ 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}" From 16b0e0d6190541d21cb7b2bcbee5ce2237641bdd Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Mon, 2 Nov 2015 09:44:29 -0600 Subject: [PATCH 6/7] documentation, thanks again to stack72 --- .../docs/providers/aws/r/autoscaling_group.html.markdown | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 7cb166142..290bcabbe 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 { @@ -48,7 +54,7 @@ The following arguments are supported: * `availability_zones` - (Optional) A list of AZs to launch resources in. Required only if you do not specify any `vpc_zone_identifier` * `launch_configuration` - (Required) The name of the launch configuration to use. -* `health_check_grace_period` - (Optional) Time after instance comes into service before checking health. +* `health_check_grace_period` - (Optional) Time after instance comes into service before checking health. * `health_check_type` - (Optional) "EC2" or "ELB". Controls how health checking is done. * `desired_capacity` - (Optional) The number of Amazon EC2 instances that should be running in the group. (See also [Waiting for @@ -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 bf88ee8ddb07149d33628c26b9de981a8052a0a4 Mon Sep 17 00:00:00 2001 From: Sunil K Chopra Date: Fri, 13 Nov 2015 12:40:19 -0600 Subject: [PATCH 7/7] fix test to include creation of placement group --- .../providers/aws/resource_aws_autoscaling_group_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 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 bf8b56c08..43f5350be 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -356,6 +356,11 @@ resource "aws_launch_configuration" "foobar" { instance_type = "t1.micro" } +resource "aws_placement_group" "test" { + name = "test" + strategy = "cluster" +} + resource "aws_autoscaling_group" "bar" { availability_zones = ["us-west-2a"] name = "foobar3-terraform-test" @@ -366,7 +371,7 @@ resource "aws_autoscaling_group" "bar" { desired_capacity = 4 force_delete = true termination_policies = ["OldestInstance","ClosestToNextInstanceHour"] - placement_group = "test" + placement_group = "${aws_placement_group.test.name}" launch_configuration = "${aws_launch_configuration.foobar.name}"