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

ASG with mixed_instance_policy cannot have on_demand_base_capacity set to 0 #7938

Closed
MarcusNoble opened this issue Mar 14, 2019 · 13 comments · Fixed by #8369
Closed

ASG with mixed_instance_policy cannot have on_demand_base_capacity set to 0 #7938

MarcusNoble opened this issue Mar 14, 2019 · 13 comments · Fixed by #8369
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.

Comments

@MarcusNoble
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

➜ terraform -v
Terraform v0.11.13
+ provider.aws v2.1.0

Affected Resource(s)

  • aws_autoscaling_group

Terraform Configuration Files

resource "aws_autoscaling_group" "example-asg" {
  desired_capacity     = "${var.asg_desired_capacity}"
  min_size             = "${var.asg_min_size}"
  max_size             = "${var.asg_max_size}"
  name                 = "example"
  vpc_zone_identifier  = ["${split(",", var.worker_subnets)}"]

  mixed_instances_policy {
    launch_template {
      launch_template_specification {
        launch_template_id = "${aws_launch_template.example-lt.id}"
        version = "$$Latest"
      }

      override {
        instance_type = "m5.large"
      }

      override {
        instance_type = "m5.xlarge"
      }
    }
    instances_distribution {
      on_demand_base_capacity = "1"
      on_demand_percentage_above_base_capacity = "0"
    }
  }
}

Expected Behavior

The on_demand_base_capacity should always be used to set the base capacity.

Actual Behavior

When changing from a positive number to a 0 the change is ignored.

Steps to Reproduce

  1. terraform apply
  2. Change on_demand_base_capacity to 0
  3. terraform apply

Important Factoids

Tested the tame change with the AWS CLI and the value can be successfully set to 0

@aretakisv
Copy link

I can confirm the same. Even changing it from 0 to positive number, doesn't update the ASG!

Same version on terraform pieces

@bflad bflad added the service/autoscaling Issues and PRs that pertain to the autoscaling service. label Mar 14, 2019
@bflad
Copy link
Contributor

bflad commented Mar 14, 2019

Hmm. Version 2.1.0 specifically should have fixed the original issue report via #7821. Does terraform plan after the apply show the change needing to reoccur still?

@MarcusNoble
Copy link
Contributor Author

Plan still shows no changes. Give me 5 min and I'll put up a self-contained example that can be run.

@MarcusNoble
Copy link
Contributor Author

https://gist.github.com/MarcusNoble/3ab6f49a86a5c4c2b24b74f7f6a12d74

You just need to provide the private_subnets variable.

Once applied change the on_demand_base_capacity value to 0 and try applying again.

@MarcusNoble
Copy link
Contributor Author

I have also tried by compiling the latest from the master branch on GitHub and it has the same issue.

@MarcusNoble
Copy link
Contributor Author

@bflad Did you manage to verify it also wasn't working for you?

@clarkdave
Copy link

I can confirm this too.

When creating the autoscaling group, on_demand_base_capacity can be set to 0 and TF will create it correctly. However, if the autoscaling group is created with on_demand_base_capacity set to positive integer then Terraform will ignore any attempts to change it down to 0.

Versions:

Terraform v0.11.13
+ provider.aws v2.6.0

As a workaround we're adjusting the value by hand in AWS and then modifying the terraform state to match.

@MarcusNoble
Copy link
Contributor Author

So I did a bit more testing and this actually gets weirder. It only fails to set back to 0 when it's currently set to 1. If set to 2 then terraform will pick up the change to 0 fine.

I have added two tests to cover this on my fork here: https://github.com/MarcusNoble/terraform-provider-aws/commit/86c4ecf78bfe513b42a15feae2a84b1e1ae298aa

1 -> 0

➜ make testacc TESTARGS='-run=TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0 -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0
=== PAUSE TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0
=== CONT  TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0
--- FAIL: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_1to0 (48.31s)
    testing.go:538: Step 2 error: Check failed: Check 4/4 error: aws_autoscaling_group.test: Attribute 'mixed_instances_policy.0.instances_distribution.0.on_demand_base_capacity' expected "0", got "1"
FAIL
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       49.324s
make: *** [testacc] Error 1

2 -> 0

➜ make testacc TESTARGS='-run=TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0 -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0
=== PAUSE TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0
=== CONT  TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0
--- PASS: TestAccAWSAutoScalingGroup_MixedInstancesPolicy_InstanceDistribution_OnDemandQuantity_2to0 (44.88s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       45.310s

@MarcusNoble
Copy link
Contributor Author

More digging led me to this fix: #8369

@bflad I couldn't figure out what purpose the diff suppression was doing here. I think you were the one to add it in, do you think you could take a look and see if removing it causes problems elsewhere?

@aeschright aeschright added the needs-triage Waiting for first response or review from a maintainer. label Jun 24, 2019
@andredasilvapinto
Copy link

For me it doesn't let me set it to 1

Error: Error creating AutoScaling Group: ValidationError: Max bound, 0, must be greater than or equal to OnDemandBaseCapacity, 1.

min_size, max_size and and on_demand_base_capacity are set to 1. on_demand_percentage_above_base_capacity and spot_instance_pools set to 0

This is using TFE 0.12.2 and aws provider 2.40.0

@aeschright aeschright added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 9, 2019
@chancez
Copy link

chancez commented Jul 29, 2020

This seems like a pretty old bug and seems like this should get prioritized. Does this require someone to shepherd these changes?

@ewbankkit
Copy link
Contributor

Closed via #13623.

@github-actions
Copy link

github-actions bot commented Jul 1, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants