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 an "aws_cloudfront_distribution" sets "cache_behavior" rather than "ordered_cache_behavior" in the state. #5580

Closed
ghost opened this issue Aug 16, 2018 · 5 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

@ghost
Copy link

ghost commented Aug 16, 2018

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.
@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 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.

@james-robson
Copy link

Excellent, thanks for the quick turnaround @bflad

@ghost
Copy link
Author

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
2 participants