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

Cannot create aws_autoscaling_group with health_check_grace_period = 0 #4981

Closed
brodygov opened this issue Jun 25, 2018 · 3 comments
Closed
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@brodygov
Copy link

brodygov commented Jun 25, 2018

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 v0.11.7
+ provider.aws v1.24.0

Affected Resource(s)

  • aws_autoscaling_group

Terraform Configuration Files

provider "aws" {
  version = "1.24"
  region = "us-east-1"
}

variable "grace_period" {
  description = "ASG health check grace period"
  default = 0
}

resource aws_autoscaling_group "test" {
  name_prefix = "tmp-test-asg-"
  min_size = 0
  max_size = 0
  health_check_grace_period = "${var.grace_period}"
  health_check_type = "ELB"
  availability_zones = ["us-east-1a"]

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

resource "aws_launch_template" "test" {
  name_prefix = "tmp-test-asg-"
  instance_type = "t2.micro"
  image_id = "ami-5cc39523"
}

Debug Output

Log files for three terraform runs: (failing create, successful create to 1, successful modify to 0) https://gist.github.com/brodygov/bb82545169d72e97480c3768ead31a6d

Expected Behavior

Terraform should be able to create an aws_autoscaling_group with the health_check_grace_period set to 0, which is a valid value for the grace period.

Actual Behavior

Terraform treats 0 as a null/unset value instead of an integer. The HealthCheckGracePeriod parameter is not included in the request when health_check_grace_period = 0, even though it is mandatory.

* aws_autoscaling_group.test: Error creating AutoScaling Group: ValidationError: HealthCheckGracePeriod must be specified for ElasticLoadBalancer based health checks.
	status code: 400

Steps to Reproduce

  1. terraform apply

To verify that 0 is a valid value as far as AWS is concerned

Create the autoscaling group with a grace period of 1, then set it to 0 through a modify call.

  1. terraform apply -var grace_period=1
  2. terraform apply -var grace_period=0

Both of these steps succeed.

aws_autoscaling_group.test: Modifying... (ID: tmp-test-asg-20180625192643205500000001)
  health_check_grace_period: "1" => "0"
aws_autoscaling_group.test: Modifications complete after 0s (ID: tmp-test-asg-20180625192643205500000001)

Important Factoids

References

This is one instance of Terraform not having a way to identify null/unset values, which is a general core issue.

@bflad bflad added bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service. labels Jun 26, 2018
@bleachbyte
Copy link

I have a few ideas about this, based on my limited understanding of Go and the resource definition for Auto Scaling Groups.

The issue seems to be that health_check_grace_period is conditionally optional, and it currently follows some degree of optional checking only. The schema definition says:

			"health_check_grace_period": {
				Type:     schema.TypeInt,
				Optional: true,
				Default:  300,
			},

It will set it to 300 if it is not explicitly set, but will otherwise set it to a blank/null value if 0 is the provided value, due to the behavior of d.GetOk:

  if v, ok := d.GetOk("health_check_grace_period"); ok {
    createOpts.HealthCheckGracePeriod = aws.Int64(int64(v.(int)))
  }

Based on the other examples in the schema, I would think the options here could be:

  1. adding Computed: True to the health_check_grace_period schema
  2. setting createOpts.HealthCheckGracePeriod at 0 initially, as the MinSize and MaxSize values are if twoPhases is set, and then updating it to either the defined health_check_grace_period value or the default of 300
  3. both?

A possible example:

  createOpts.HealthCheckGracePeriod = aws.Int64(int64(0))
  if v, ok := d.GetOk("health_check_grace_period"); ok {
    updateOpts.HealthCheckGracePeriod = aws.Int64(int64(v.(int)))
  } else {
    updateOpts.HealthCheckGracePeriod = aws.Int64(int64(300))
  }

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Jan 7, 2022
@github-actions github-actions bot closed this as completed Feb 7, 2022
@github-actions
Copy link

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 May 16, 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. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

3 participants