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

Cloudfront Distribution changes ForwardedValues Headers for Behaviours #7867

Closed
skorfmann opened this issue Mar 8, 2019 · 10 comments · Fixed by #8150
Closed

Cloudfront Distribution changes ForwardedValues Headers for Behaviours #7867

skorfmann opened this issue Mar 8, 2019 · 10 comments · Fixed by #8150
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@skorfmann
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 v0.11.11

Affected Resource(s)

  • aws_cloudfront_distribution

AWS Provider version: 2.1.0

Terraform Configuration Files

resource "aws_cloudfront_distribution" "self" {
  enabled         = true
  is_ipv6_enabled = true
  comment         = "public assets"
  price_class     = "PriceClass_100"
  aliases         = ["${aws_acm_certificate.cdn_cert.domain_name}"]
# ...
  ordered_cache_behavior {
    allowed_methods        = ["GET", "HEAD", "OPTIONS"]
    cached_methods         = ["GET", "HEAD"]
    target_origin_id       = "${local.s3_origin_id}"
    viewer_protocol_policy = "allow-all"
    compress               = true
    default_ttl            = 86400
    min_ttl                = 3600
    max_ttl                = 2592000

    path_pattern = "/foo/*"

    forwarded_values {
      query_string = false

      headers = [
        "Origin",
        "Access-Control-Request-Headers",
        "Access-Control-Request-Method",
      ]

      cookies {
        forward = "none"
      }
    }
  }
# ...
}

Expected Behavior

A clean diff, since the code wasn't changed.

Actual Behavior

There's always a diff for the forwarwarded values headers:

screenshot 2019-03-08 at 11 48 59

Steps to Reproduce

  1. terraform plan
  2. terraform apply
  3. terraform plan
@skorfmann
Copy link
Contributor Author

Tried a downgrade of the AWS provider to 2.0.0

apply output (apparently no actual change to the distribution, way to quick for that)

ordered_cache_behavior.0.forwarded_values.0.headers.0: "Access-Control-Request-Headers" => "Origin"
ordered_cache_behavior.0.forwarded_values.0.headers.1: "Access-Control-Request-Method" => "Access-Control-Request-Headers"
ordered_cache_behavior.0.forwarded_values.0.headers.2: "Origin" => "Access-Control-Request-Method"

state afterwards

"ordered_cache_behavior.0.forwarded_values.0.headers.0": "Access-Control-Request-Headers",
"ordered_cache_behavior.0.forwarded_values.0.headers.1": "Access-Control-Request-Method",
"ordered_cache_behavior.0.forwarded_values.0.headers.2": "Origin",

Hence, there's also a diff for each plan, but at least the apply doesn't do a full cloudfront distribution deployment now.

@bflad bflad added bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels Mar 8, 2019
@jrmuir
Copy link

jrmuir commented Mar 15, 2019

Some information that might be helpful.

This appears to be an issue with ordering of the item lists not matching up with what was specified, and we're seeing it with both the cookie list and header forward values.

If we have four values applied to cookie name whitelist, e.g. whitelisted_names = ["wp-*", "wordpress*", "MSISAuth*", "PHPSESSID"] then every time it runs, it tries to set them to whitelisted_names = ["MSISAuth*", "PHPSESSID", "wordpress*", "wp-*"]. If we adjust the source to match what it tries to set each time, it has no trouble with them because now they'll match what the provider is trying to do.

Terraform.tfstate prior to the change shows:

"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.#": "4",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.0": "wp-*",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.1": "wordpress*",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.2": "MSISAuth*",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.3": "PHPSESSID",

After re-ordering them in our .tf file and applying, shows:

"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.#": "4",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.0": "MSISAuth*",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.1": "PHPSESSID",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.2": "wordpress*",
"default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.3": "wp-*",

and from that point on it will run without trying to make any changes. But if we adjust our order in our .tf file, it will continue to try to put them back to the order with MSISAuth first.

@bflad bflad added this to the v2.5.0 milestone Mar 27, 2019
@yardensachs
Copy link
Contributor

I this an AWS provider issue or a terraform issue?

@bflad
Copy link
Contributor

bflad commented Apr 1, 2019

@yardensachs this is an issue in the Terraform AWS Provider where the resource is expecting explicit ordering while the API does not. We are planning on addressing this once #8116 is merged.

bflad added a commit that referenced this issue Apr 2, 2019
…che behavior forwarded values `headers` and cookies `whitelisted_names` arguments

Reference: #7867

Output from acceptance testing prior to code updates:

```
--- FAIL: TestAccAWSCloudFrontDistribution_DefaultCacheBehavior_ForwardedValues_Cookies_WhitelistedNames (528.44s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_cloudfront_distribution.test
          default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.0: "test1" => "test2"
          default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.1: "test2" => "test3"
          default_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.2: "test3" => "test1"

--- FAIL: TestAccAWSCloudFrontDistribution_DefaultCacheBehavior_ForwardedValues_Headers (528.49s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_cloudfront_distribution.test
          default_cache_behavior.0.forwarded_values.0.headers.0: "Access-Control-Request-Headers" => "Origin"
          default_cache_behavior.0.forwarded_values.0.headers.1: "Access-Control-Request-Method" => "Access-Control-Request-Headers"
          default_cache_behavior.0.forwarded_values.0.headers.2: "Origin" => "Access-Control-Request-Method"

--- FAIL: TestAccAWSCloudFrontDistribution_OrderedCacheBehavior_ForwardedValues_Cookies_WhitelistedNames (528.46s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_cloudfront_distribution.test
          ordered_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.0: "test1" => "test2"
          ordered_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.1: "test2" => "test3"
          ordered_cache_behavior.0.forwarded_values.0.cookies.0.whitelisted_names.2: "test3" => "test1"

--- FAIL: TestAccAWSCloudFrontDistribution_OrderedCacheBehavior_ForwardedValues_Headers (528.43s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_cloudfront_distribution.test
          ordered_cache_behavior.0.forwarded_values.0.headers.0: "Access-Control-Request-Headers" => "Origin"
          ordered_cache_behavior.0.forwarded_values.0.headers.1: "Access-Control-Request-Method" => "Access-Control-Request-Headers"
          ordered_cache_behavior.0.forwarded_values.0.headers.2: "Origin" => "Access-Control-Request-Method"
```

Output from acceptance testing:

```
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID (2.56s)
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName (2.56s)
--- PASS: TestAccAWSCloudFrontDistribution_OrderedCacheBehavior_ForwardedValues_Cookies_WhitelistedNames (543.49s)
--- PASS: TestAccAWSCloudFrontDistribution_DefaultCacheBehavior_ForwardedValues_Headers (544.62s)
--- PASS: TestAccAWSCloudFrontDistribution_OrderedCacheBehavior_ForwardedValues_Headers (546.32s)
--- PASS: TestAccAWSCloudFrontDistribution_disappears (550.45s)
--- PASS: TestAccAWSCloudFrontDistribution_DefaultCacheBehavior_ForwardedValues_Cookies_WhitelistedNames (580.39s)
--- PASS: TestAccAWSCloudFrontDistribution_IsIPV6EnabledConfig (1173.77s)
--- PASS: TestAccAWSCloudFrontDistribution_RetainOnDelete (1178.86s)
--- PASS: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (1181.80s)
--- PASS: TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig (1183.92s)
--- PASS: TestAccAWSCloudFrontDistribution_customOrigin (1270.14s)
--- PASS: TestAccAWSCloudFrontDistribution_S3Origin (1270.44s)
--- PASS: TestAccAWSCloudFrontDistribution_OriginGroups (1268.27s)
--- PASS: TestAccAWSCloudFrontDistribution_noOptionalItemsConfig (1271.35s)
--- PASS: TestAccAWSCloudFrontDistribution_multiOrigin (1272.23s)
--- PASS: TestAccAWSCloudFrontDistribution_WaitForDeployment (1269.96s)
--- PASS: TestAccAWSCloudFrontDistribution_HTTP11Config (1275.52s)
--- PASS: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn (1276.02s)
--- PASS: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn_ConflictsWithCloudFrontDefaultCertificate (1284.86s)
--- PASS: TestAccAWSCloudFrontDistribution_Enabled (1736.60s)
--- PASS: TestAccAWSCloudFrontDistribution_S3OriginWithTags (1886.36s)
```
@bflad
Copy link
Contributor

bflad commented Apr 2, 2019

Pull request submitted: #8150

@bflad
Copy link
Contributor

bflad commented Apr 4, 2019

The fix to ignore ordering for headers and cookies whitelisted_names has been merged and will release with version 2.5.0 of the Terraform AWS Provider, likely later today.

@nathanielks
Copy link
Contributor

Thanks for your work on this @bflad!

@yardensachs
Copy link
Contributor

Thanks @bflad!

@bflad
Copy link
Contributor

bflad commented Apr 5, 2019

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

@ghost
Copy link

ghost commented Mar 30, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
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
5 participants