hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.18k forks source link

Unintentional force-replacement when 'request_interval' is not specified in 'aws_route53_health_check' #23514

Open adityadhole24 opened 2 years ago

adityadhole24 commented 2 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.31 AWS Provider v3.70.0

Affected Resource(s)

Terraform Configuration Files

resource "aws_route53_health_check" "test" {

  fqdn = "www.some-valid-domain.com"
  type = "HTTP"
  port = 80

}

Debug Output

Gist for the 2nd terraform apply debug output - https://gist.github.com/adityadhole24/e0416201dcd5b25b2d866d14b133cd6d

Expected Behavior

The first terraform apply command with the given configuration should lead to successful creation of the Route53 health check. A second terraform apply command (without making any changes to the configuration externally, of course), should detect no changes.

Actual Behavior

The behavior for the first terraform apply command matches with the expected behavior. The health check is created successfully.

However, for the 2nd terraform apply command, Terraform (wrongly) detects a change in the configuration - It detects that the value for request_interval has changed from null to 30 (default value for request_interval that is configured by AWS for HTTP/HTTPS/TCP Health Checks), and tries to force the value back to null.

Since the request_interval parameter cannot be updated once the health check has been created (as per AWS CLI docs), Terraform forces a replacement to change its value. 1

The replacement happens successfully, however it has no real effect. The request_interval parameter will (of course) continue to have the AWS-configured default value of 30.

Every subsequent terraform apply has the same behavior as above (force-replacements with no real effect).

Steps to Reproduce

  1. terraform apply
  2. terraform apply (without any modifications made to the configuration)

Important Factoids

  1. Specifying a value for RequestInterval is optional when creating a Route53 Health Check of 'type' = HTTP/HTTPS/TCP using the AWS CLI command create-health-check as well. A default value of 30 is configured by AWS for the parameter when creating such health checks.

  2. The same AWS-defaults are configured when the request_interval parameter is skipped in Terraform and the resource gets created successfully in the 1st terraform apply command. However, the problem lies in the fact that Terraform detects a change in the subsequent apply (when there is no real change) and tries to incorrectly revert it, resulting in a unnecessary forced replacement.

References

github-actions[bot] commented 8 months ago

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!

rmbolger commented 8 months ago

The obvious workaround is to explicitly include request_interval = "30" in your Terraform code. But I agree this shouldn't be necessary.