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

Updating aws_cloudfront_function and aws_cloudfront_distribution at the same time causes Precondition failure #22816

Closed
fularac opened this issue Jan 28, 2022 · 2 comments · Fixed by #24537
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@fularac
Copy link

fularac commented Jan 28, 2022

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 other comments that do not add relevant new information or questions, 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 CLI and Terraform AWS Provider Version

Terraform v1.1.4
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.74.0

Affected Resource(s)

  • aws_cloudfront_function
  • aws_cloudfront_distribution

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

provider "aws" {
  region = "us-east-1"
}
resource "aws_cloudfront_function" "example" {
  name    = "MyFunction"
  runtime = "cloudfront-js-1.0"
  publish = true
  code    = <<EOT
  function handler(event) {
    console.log('Look mom, I'm handling a viewer request event!')
    return event.request
  }
  EOT
}

resource "aws_cloudfront_distribution" "example" {
    function_association {
      event_type   = "viewer-request"
      function_arn = aws_cloudfront_function.example.arn
    }

  origin {
      custom_origin_config {
        http_port              = "80"
        https_port             = "443"
        origin_protocol_policy = "https-only"
        origin_ssl_protocols   = ["TLSv1.2", "TLSv1.1", "TLSv1"]
      }
      domain_name = "example.com"
      origin_id   = "example"
  }

  enabled             = true

  restrictions {
    geo_restriction {
      restriction_type = "whitelist"
      locations        = ["US", "CA", "GB", "DE"]
    }
  }

  viewer_certificate {
    cloudfront_default_certificate = true
  }

  default_cache_behavior {
    allowed_methods  = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
    cached_methods   = ["GET", "HEAD"]
    target_origin_id = "example"

    viewer_protocol_policy = "allow-all"
    forwarded_values {
      query_string = false
      cookies {
        forward = "none"
      }
    }
  }
}

Debug Output

https://gist.github.com/fularac/ad5982f7671adf5ff31b7b986c3011cd

Panic Output

Expected Behavior

Apply is successful

Actual Behavior

aws_cloudfront_function.example: Modifying... [id=MyFunction]
aws_cloudfront_function.example: Modifications complete after 5s [id=MyFunction]
aws_cloudfront_distribution.example: Modifying... [id=id]
╷
│ Error: error updating CloudFront Distribution (id): PreconditionFailed: The request failed because it didn't meet the preconditions in one or more request-header fields.
│       status code: 412, request id: 407517ec-5bbb-4088-acd8-243fb12a3fed
│ 
│   with aws_cloudfront_distribution.example,
│   on main.tf line 16, in resource "aws_cloudfront_distribution" "example":
│   16: resource "aws_cloudfront_distribution" "example" {
│ 
╵

Steps to Reproduce

  1. terraform apply
  2. Modify the both aws_cloudfront_distribution.example & aws_cloudfront_function.example
  3. terraform apply
  4. Observe Precondition Failure, this may need to be tried multiple times. It will sometimes succeed.

Important Factoids

References

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels Jan 28, 2022
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 16, 2022
@github-actions github-actions bot added this to the v4.13.0 milestone May 5, 2022
@github-actions
Copy link

github-actions bot commented May 5, 2022

This functionality has been released in v4.13.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Jun 5, 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 Jun 5, 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/cloudfront Issues and PRs that pertain to the cloudfront service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants