From 6ae1473a977ff95bcde5f1505b090e601bf72863 Mon Sep 17 00:00:00 2001 From: Konstantin Kopachev Date: Wed, 18 Dec 2019 14:38:21 -0800 Subject: [PATCH] aws_autoscaling_group waits for enough WeightedCapacity if instance weight specified --- aws/resource_aws_autoscaling_group_test.go | 14 +++++++------- aws/resource_aws_autoscaling_group_waiting.go | 11 ++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/aws/resource_aws_autoscaling_group_test.go b/aws/resource_aws_autoscaling_group_test.go index 9d228ea9cb3..af839a7f0e2 100644 --- a/aws/resource_aws_autoscaling_group_test.go +++ b/aws/resource_aws_autoscaling_group_test.go @@ -2036,9 +2036,9 @@ func TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_Wei resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.#", "1"), resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.#", "2"), resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.0.instance_type", "t2.micro"), - resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.0.weighted_capacity", "1"), + resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.0.weighted_capacity", "2"), resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.1.instance_type", "t3.small"), - resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.1.weighted_capacity", "2"), + resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.launch_template.0.override.1.weighted_capacity", "4"), ), }, { @@ -3980,9 +3980,9 @@ func testAccAWSAutoScalingGroupConfig_MixedInstancesPolicy_LaunchTemplate_Overri return testAccAWSAutoScalingGroupConfig_MixedInstancesPolicy_Base(rName) + fmt.Sprintf(` resource "aws_autoscaling_group" "test" { availability_zones = ["${data.aws_availability_zones.available.names[0]}"] - desired_capacity = 0 - max_size = 0 - min_size = 0 + desired_capacity = 4 + max_size = 6 + min_size = 2 name = %q mixed_instances_policy { @@ -3993,11 +3993,11 @@ resource "aws_autoscaling_group" "test" { override { instance_type = "t2.micro" - weighted_capacity = "1" + weighted_capacity = "2" } override { instance_type = "t3.small" - weighted_capacity = "2" + weighted_capacity = "4" } } } diff --git a/aws/resource_aws_autoscaling_group_waiting.go b/aws/resource_aws_autoscaling_group_waiting.go index d2178adfaa2..247bd1f0fc0 100644 --- a/aws/resource_aws_autoscaling_group_waiting.go +++ b/aws/resource_aws_autoscaling_group_waiting.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "strconv" "strings" "time" @@ -121,7 +122,15 @@ func isELBCapacitySatisfied(d *schema.ResourceData, meta interface{}, g *autosca continue } - haveASG++ + capacity := 1 + if i.WeightedCapacity != nil { + capacity, err = strconv.Atoi(*i.WeightedCapacity) + if err != nil { + capacity = 1 + } + } + + haveASG += capacity inAllLbs := true for _, states := range elbis {