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

resource/cloudfront_distribution: Added ordered cache behaviors #4117

Merged
merged 1 commit into from
Apr 18, 2018

Conversation

Ninir
Copy link
Contributor

@Ninir Ninir commented Apr 8, 2018

Description

This allows configuring CloudFront cache behavior precedence.
This is an alternative approach to #1269 and heavily inspired by it.

While the other PR is a breaking change and thus does not allow a quick merge, this approach introduces a new attribute called ordered_cache_behavior, deprecating cache_behavior.
This work is backward-compatible as it keeps the old behaviour and adds a new one, mainly benefiting from new methods. The previous methods are marked and named as XXXDeprecated.

It also fixes the sub-options allowed_methods and cached_methods which were lists whereas it should have been set.

Alternative & better names for the new attribute are welcomed :)

Sidenote: panic when running tests after 2hours, main tests + ordered cache behaviors are passing but might be a good idea to run a TC test.

Related issues

#188
#1269

Test

$ TF_LOG=DEBUG TF_LOG_PATH=terraform.log make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudFrontDistribution_'                    
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCloudFrontDistribution_ -timeout 120m
=== RUN   TestAccAWSCloudFrontDistribution_importBasic
--- PASS: TestAccAWSCloudFrontDistribution_importBasic (1247.34s)
=== RUN   TestAccAWSCloudFrontDistribution_S3Origin
--- PASS: TestAccAWSCloudFrontDistribution_S3Origin (1323.08s)
=== RUN   TestAccAWSCloudFrontDistribution_S3OriginWithTags
--- PASS: TestAccAWSCloudFrontDistribution_S3OriginWithTags (1382.72s)
=== RUN   TestAccAWSCloudFrontDistribution_customOrigin
--- PASS: TestAccAWSCloudFrontDistribution_customOrigin (1373.03s)
=== RUN   TestAccAWSCloudFrontDistribution_multiOrigin
--- PASS: TestAccAWSCloudFrontDistribution_multiOrigin (1042.85s)
=== RUN   TestAccAWSCloudFrontDistribution_orderedCacheBehavior
--- PASS: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (798.87s)
=== RUN   TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName (2.29s)
=== RUN   TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID (2.01s)
=== RUN   TestAccAWSCloudFrontDistribution_noOptionalItemsConfig
panic: test timed out after 2h0m0s

@Ninir Ninir added enhancement Requests to existing resources that expand the functionality or scope. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels Apr 8, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Apr 8, 2018
if v, ok := d.GetOk("ordered_cache_behavior"); ok {
distributionConfig.CacheBehaviors = expandCacheBehaviors(v.([]interface{}))
} else {
distributionConfig.CacheBehaviors = expandCacheBehaviorsDeprecated(d.Get("cache_behavior").(*schema.Set))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old behavior is kept under a expandCacheBehaviorsDeprecated function, which contains the exact same previous code.

cb.SmoothStreaming = aws.Bool(v.(bool))
}
if v, ok := m["allowed_methods"]; ok {
cb.AllowedMethods = expandAllowedMethodsDeprecated(v.([]interface{}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also has the old behavior. The new behavior is a Set rather than lists for allowed_methods & cached_method

@Ninir Ninir requested a review from bflad April 12, 2018 12:38
@bflad
Copy link
Contributor

bflad commented Apr 17, 2018

@Ninir hmm I wonder if you caught this right before the CloudFront SDK changed, but can you ensure this is rebased to handle field_level_encryption_id? #4102

I'm currently getting test failures for everything in TC using refs/pull/4117/merge (so merged with the SDK update in master):

--- FAIL: TestAccAWSCloudFrontDistribution_HTTP11Config (14.03s)
    testing.go:579: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: Error applying: 1 error(s) occurred:
        
        * aws_cloudfront_distribution.http_1_1 (destroy): 1 error(s) occurred:
        
        * aws_cloudfront_distribution.http_1_1: InvalidArgument: The parameter Field level encryption id is required.
            status code: 400, request id: f688ddfe-4258-11e8-9d0c-4baa8bbf9e0d

@Ninir
Copy link
Contributor Author

Ninir commented Apr 17, 2018

@bflad just rebased and currently running tests (which are passing right now)

@Ninir
Copy link
Contributor Author

Ninir commented Apr 17, 2018

@bflad Would it be possible to trigger tests in TC?

still has the panic: test timed out after 2h0m0s after:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudFrontDistribution_'           
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCloudFrontDistribution_ -timeout 120m
=== RUN   TestAccAWSCloudFrontDistribution_importBasic
--- PASS: TestAccAWSCloudFrontDistribution_importBasic (1472.03s)
=== RUN   TestAccAWSCloudFrontDistribution_S3Origin
--- PASS: TestAccAWSCloudFrontDistribution_S3Origin (1433.31s)
=== RUN   TestAccAWSCloudFrontDistribution_S3OriginWithTags
--- PASS: TestAccAWSCloudFrontDistribution_S3OriginWithTags (1444.00s)
=== RUN   TestAccAWSCloudFrontDistribution_customOrigin
--- PASS: TestAccAWSCloudFrontDistribution_customOrigin (1313.38s)
=== RUN   TestAccAWSCloudFrontDistribution_multiOrigin
--- PASS: TestAccAWSCloudFrontDistribution_multiOrigin (1501.19s)
=== RUN   TestAccAWSCloudFrontDistribution_orderedCacheBehavior
panic: test timed out after 2h0m0s

Thanks!

@bflad
Copy link
Contributor

bflad commented Apr 17, 2018

@Ninir can you push up the rebase commit? 😄 Its not showing up in Github and still throwing the same error in TC.

@Ninir Ninir force-pushed the f-cloudfront-ordered-cache-behavior branch from 1fc3865 to 1791517 Compare April 18, 2018 07:48
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Apr 18, 2018
@Ninir
Copy link
Contributor Author

Ninir commented Apr 18, 2018

@bflad Yep done. Tried a few things to tweak that setting without success. Is there anything you do on TC to fix this panic?

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! 🚀 LGTM

12 tests passed (all tests)
=== RUN   TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID (1.55s)
=== RUN   TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName (1.73s)
=== RUN   TestAccAWSCloudFrontDistribution_HTTP11Config
--- PASS: TestAccAWSCloudFrontDistribution_HTTP11Config (1535.58s)
=== RUN   TestAccAWSCloudFrontDistribution_S3OriginWithTags
--- PASS: TestAccAWSCloudFrontDistribution_S3OriginWithTags (1536.80s)
=== RUN   TestAccAWSCloudFrontDistribution_orderedCacheBehavior
--- PASS: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (1538.30s)
=== RUN   TestAccAWSCloudFrontDistribution_S3Origin
--- PASS: TestAccAWSCloudFrontDistribution_S3Origin (1539.00s)
=== RUN   TestAccAWSCloudFrontDistribution_IsIPV6EnabledConfig
--- PASS: TestAccAWSCloudFrontDistribution_IsIPV6EnabledConfig (1539.26s)
=== RUN   TestAccAWSCloudFrontDistribution_multiOrigin
--- PASS: TestAccAWSCloudFrontDistribution_multiOrigin (1540.74s)
=== RUN   TestAccAWSCloudFrontDistribution_customOrigin
--- PASS: TestAccAWSCloudFrontDistribution_customOrigin (1541.16s)
=== RUN   TestAccAWSCloudFrontDistribution_noOptionalItemsConfig
--- PASS: TestAccAWSCloudFrontDistribution_noOptionalItemsConfig (1542.22s)
=== RUN   TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig
--- PASS: TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig (1543.61s)
=== RUN   TestAccAWSCloudFrontDistribution_importBasic
--- PASS: TestAccAWSCloudFrontDistribution_importBasic (1543.98s)

@bflad bflad added this to the v1.15.0 milestone Apr 18, 2018
@bflad bflad merged commit da4a177 into hashicorp:master Apr 18, 2018
bflad added a commit that referenced this pull request Apr 18, 2018
@bflad
Copy link
Contributor

bflad commented Apr 18, 2018

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

@danielfm
Copy link

danielfm commented Apr 18, 2018

@Ninir First of all, thanks for this fix! 🎉

I did a test by importing an existing CloudFront distribution with v1.15.0, but apparently it still uses the now deprecated cache_behavior, instead of the new ordered_cache_behavior. Are there any plans of changing the import code as well to leverage the new ordered_cache_behavior directive?

Also, is it safe to update a Terraform-managed distribution by replacing all cache_behavior by ordered_cache_behavior? Will Terraform delete and then re-create all cache behaviors (which might cause a brief unavailability), or just reorder the existing cache behaviors (much less disruptive)?

@Ninir
Copy link
Contributor Author

Ninir commented Apr 18, 2018

Hey @danielfm

It indeed still uses the old behaviour. I tried to come up with solutions about migrating the old behaviour to the new one without success: migrating the schema is a tough task that was nearly impossible to handle in some cases, hence the "opt-in" proposal.

Since both of these 2 attributes are conflicting with the other one, you can only set one or the other, meaning if you try to set ordered ones in place of obsolete ones, there will just be a replacement & Distribution update.

Hope it's clear enough! :)

@ghost
Copy link

ghost commented Apr 6, 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 Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudfront Issues and PRs that pertain to the cloudfront service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants