Description
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
- Create a cloudfront distribution in AWS with one non-default cache behavior in addition to the default cache behavior.
- Write the terraform configuration for it, using ordered_cache_behavior for the non-default cache behavior.
- Use
terraform import
to import it - 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.