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

Fix ASG mixed instance on demand capacity bug #8369

Merged
merged 2 commits into from
May 27, 2022
Merged
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
7 changes: 0 additions & 7 deletions aws/resource_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
@@ -94,13 +94,6 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
// Ignore missing configuration block
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "1" && new == "0" {
return true
}
return false
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"on_demand_allocation_strategy": {
122 changes: 122 additions & 0 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
@@ -1731,6 +1731,97 @@ func TestAccAWSAutoScalingGroup_MixedInstancesPolicy_LaunchTemplate_Override_Ins
})
}

func TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0(t *testing.T) {
var group autoscaling.Group
resourceName := "aws_autoscaling_group.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity(rName, "1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.0.on_demand_base_capacity", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"force_delete",
"initial_lifecycle_hook",
"name_prefix",
"tag",
"tags",
"wait_for_capacity_timeout",
"wait_for_elb_capacity",
},
},
{
Config: testAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity(rName, "0"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.0.on_demand_base_capacity", "0"),
),
},
},
})
}
func TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0(t *testing.T) {
var group autoscaling.Group
resourceName := "aws_autoscaling_group.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity(rName, "2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.0.on_demand_base_capacity", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"force_delete",
"initial_lifecycle_hook",
"name_prefix",
"tag",
"tags",
"wait_for_capacity_timeout",
"wait_for_elb_capacity",
},
},
{
Config: testAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity(rName, "0"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAutoScalingGroupExists(resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.#", "1"),
resource.TestCheckResourceAttr(resourceName, "mixed_instances_policy.0.instances_distribution.0.on_demand_base_capacity", "0"),
),
},
},
})
}

const testAccAWSAutoScalingGroupConfig_autoGeneratedName = `
data "aws_ami" "test_ami" {
most_recent = true
@@ -3429,3 +3520,34 @@ resource "aws_autoscaling_group" "test" {
}
`, rName, instanceType)
}

func testAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity(rName, instanceCount string) string {
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 = 2
min_size = 0
name = %q

mixed_instances_policy {
launch_template {
launch_template_specification {
launch_template_id = "${aws_launch_template.test.id}"
version = "$$Latest"
}

override {
instance_type = "t2.micro"
}
override {
instance_type = "t2.small"
}
}
instances_distribution {
on_demand_base_capacity = "%s"
}
}
}
`, rName, instanceCount)
}