Terraform-provider-aws: Importing an "aws_cloudfront_distribution" sets "cache_behavior" rather than "ordered_cache_behavior" in the state.

Created on 16 Aug 2018  ยท  5Comments  ยท  Source: hashicorp/terraform-provider-aws

_This issue was originally opened by @james-robson as hashicorp/terraform#18693. It was migrated here as a result of the provider split. The original body of the issue is below._


Terraform Version

0.11.7

Terraform Configuration Files

resource "aws_cloudfront_distribution" "example_distribution" {
     // ...other distribution config
    default_cache_behavior {
        allowed_methods  = ["HEAD", "GET", "OPTIONS"]
        cached_methods   = ["HEAD", "GET", "OPTIONS"]
        compress         = true
        default_ttl      = 86400
        forwarded_values {
            query_string = false
            cookies {
                forward  = "none"
            }
        }
        max_ttl                = 31536000
        min_ttl                = 0
        smooth_streaming       = false
        target_origin_id       = "${local.some_origin_id}"
        viewer_protocol_policy = "redirect-to-https"
    }

    ordered_cache_behavior {
        allowed_methods  = ["GET", "HEAD"]
        cached_methods   = ["GET", "HEAD"]
        compress         = false
        default_ttl      = 86400
        forwarded_values {
            query_string = false
            cookies {
                forward = "none"
            }
        }
        max_ttl = 31536000
        min_ttl = 0
        path_pattern = "*"
        smooth_streaming = false
        target_origin_id = "${local.another_origin_id}"
        viewer_protocol_policy = "redirect-to-https"
    }
    // ...the rest of the distribution config

}

Debug Output


Here is an example plan output which shows the issue:

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  ~ aws_cloudfront_distribution.example_distribution
      cache_behavior.#:                                    "1" => "0"
      cache_behavior.1293109696.allowed_methods.#:         "2" => "0"
      cache_behavior.1293109696.allowed_methods.0:         "HEAD" => ""
      cache_behavior.1293109696.allowed_methods.1:         "GET" => ""
      // etc...
      ordered_cache_behavior.#:                            "0" => "1"
      ordered_cache_behavior.0.allowed_methods.#:          "0" => "2"
      ordered_cache_behavior.0.allowed_methods.1040875975: "" => "GET"
      ordered_cache_behavior.0.allowed_methods.1445840968: "" => "HEAD"
      // etc...

Crash Output

N/A

Expected Behavior


When importing an "aws_cloudfront_distribution" using:
terraform import aws_cloudfront_distribution.example_distribution <DISTRIBUTION_ID>
the correct values should be saved to the state.

Actual Behavior


The cache behaviour is stored as the deprecated cache_behavior rather than ordered_cache_behavior. This causes the first plan after import to show a change from cache_behaviour to ordered_cache_behaviour.

Steps to Reproduce

  1. terraform import aws_cloudfront_distribution.example_distribution <DISTRIBUTION_ID>
  2. Create an "aws_cloudfront_distribution" object in a Terraform script which uses the correct ordered_cache_behaviour key and matching values to the import.
  3. Run terraform apply.
bug serviccloudfront

Most helpful comment

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.

All 5 comments

Bug fix pull request submitted: #5586

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

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.

Excellent, thanks for the quick turnaround @bflad

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!

Was this page helpful?
0 / 5 - 0 ratings