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

Importing aws_cloudfront_distribution uses the deprecated cache_behavior instead of ordered_cache_behavior #4773

Closed
LHCGreg opened this issue Jun 7, 2018 · 4 comments · Fixed by #5586
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@LHCGreg
Copy link

LHCGreg commented Jun 7, 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.22.0

Affected Resource(s)

  • aws_cloudfront_distribution

Expected Behavior

Running terraform import on a cloudfront distribution with one default cache behavior and one non-default cache behavior should result in the state file having

"ordered_cache_behavior.#": "1",
"ordered_cache_behavior.0.allowed_methods.#": "2",
...

and

"default_cache_behavior.#": "1",
"default_cache_behavior.2334655761.allowed_methods.#": "2",
...

Actual Behavior

Running terraform import on a cloudfront distribution with one default cache behavior and one non-default cache behavior resulted in the state file having

"cache_behavior.#": "1",
"cache_behavior.2295505492.allowed_methods.#": "2",
...

and

"default_cache_behavior.#": "1",
"default_cache_behavior.2334655761.allowed_methods.#": "2",
...

Note that the import used "cache_behavior" for the non-default cache behavior instead of ordered_cache_behavior. https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html says cache_behavior is "Deprecated, use ordered_cache_behavior instead".

Steps to Reproduce

  1. Create a cloudfront distribution in AWS with one non-default cache behavior in addition to the default cache behavior.
  2. Write the terraform configuration for it, using ordered_cache_behavior for the non-default cache behavior.
  3. Use terraform import to import it
  4. Run a plan. Terraform wants to remove the non-default cache behavior and add it back.

Workaround

Do the import and then manually edit the state file, changing "cache_behavior.#" to "ordered_cache_behavior.#" and cache_behavior.XXXXXXXXXX.* to ordered_cache_behavior.0.*. If you have more than one non-default cache behavior, you can order them appropriately.

@radeksimko radeksimko added service/cloudfront Issues and PRs that pertain to the cloudfront service. bug Addresses a defect in current functionality. labels Jun 13, 2018
@bflad
Copy link
Contributor

bflad commented Aug 17, 2018

Bug fix pull request submitted: #5586

@bflad bflad added this to the v1.33.0 milestone Aug 20, 2018
@bflad
Copy link
Contributor

bflad commented Aug 20, 2018

The fix for this has been merged into master and will release with version 1.33.0 of the AWS provider, likely later this week.

@bflad
Copy link
Contributor

bflad commented Aug 22, 2018

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

@ghost
Copy link

ghost commented Apr 3, 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 3, 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
3 participants