Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the placement_group to the AutoScalingGroup resource #3705

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions builtin/providers/aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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, ","))
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions builtin/providers/aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},

Expand Down Expand Up @@ -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}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down