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

Default values of max_ttl and default_ttl not working as expected in aws_cloudfront_cache_policy #24535

Open
ccsandhanshive opened this issue May 4, 2022 · 5 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudfront Issues and PRs that pertain to the cloudfront service.

Comments

@ccsandhanshive
Copy link

ccsandhanshive commented May 4, 2022

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 other comments that do not add relevant new information or questions, 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 CLI and Terraform AWS Provider Version

Terraform v0.12.31

  • provider.aws v3.70.0

Affected Resource(s)

  • aws_cloudfront_cache_policy

Terraform Configuration Files

resource "aws_cloudfront_cache_policy" "example01" {
  name        = "example-policy01"
  min_ttl     = 31536100
  default_ttl = 31536200

  parameters_in_cache_key_and_forwarded_to_origin {
    cookies_config {
      cookie_behavior = "whitelist"
      cookies {
        items = ["example"]
      }
    }
    headers_config {
      header_behavior = "whitelist"
      headers {
        items = ["example"]
      }
    }
    query_strings_config {
      query_string_behavior = "whitelist"
      query_strings {
        items = ["example"]
      }
    }
  }
}
resource "aws_cloudfront_cache_policy" "example02" {
  name        = "example-policy02"
  min_ttl     = 86500
  max_ttl     = 86700

  parameters_in_cache_key_and_forwarded_to_origin {
    cookies_config {
      cookie_behavior = "whitelist"
      cookies {
        items = ["example"]
      }
    }
    headers_config {
      header_behavior = "whitelist"
      headers {
        items = ["example"]
      }
    }
    query_strings_config {
      query_string_behavior = "whitelist"
      query_strings {
        items = ["example"]
      }
    }
  }
}
resource "aws_cloudfront_cache_policy" "example03" {
  name        = "example-policy03"
  min_ttl     = 31536100

  parameters_in_cache_key_and_forwarded_to_origin {
    cookies_config {
      cookie_behavior = "whitelist"
      cookies {
        items = ["example"]
      }
    }
    headers_config {
      header_behavior = "whitelist"
      headers {
        items = ["example"]
      }
    }
    query_strings_config {
      query_string_behavior = "whitelist"
      query_strings {
        items = ["example"]
      }
    }
  }
}
provider "aws" {
  version = "~> 3.70.0"
  region  = "ap-northeast-1"
}

Debug Output

PS C:\min_ttl_test> terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_cloudfront_cache_policy.example01 will be created
  + resource "aws_cloudfront_cache_policy" "example01" {
      + default_ttl = 31536200
      + etag        = (known after apply)
      + id          = (known after apply)
      + max_ttl     = 31536000
      + min_ttl     = 31536100
      + name        = "example-policy01"

      + parameters_in_cache_key_and_forwarded_to_origin {
          + cookies_config {
              + cookie_behavior = "whitelist"

              + cookies {
                  + items = [
                      + "example",
                    ]
                }
            }

          + headers_config {
              + header_behavior = "whitelist"

              + headers {
                  + items = [
                      + "example",
                    ]
                }
            }

          + query_strings_config {
              + query_string_behavior = "whitelist"

              + query_strings {
                  + items = [
                      + "example",
                    ]
                }
            }
        }
    }

  # aws_cloudfront_cache_policy.example02 will be created
  + resource "aws_cloudfront_cache_policy" "example02" {
      + default_ttl = 86400
      + etag        = (known after apply)
      + id          = (known after apply)
      + max_ttl     = 86700
      + min_ttl     = 86500
      + name        = "example-policy02"

      + parameters_in_cache_key_and_forwarded_to_origin {
          + cookies_config {
              + cookie_behavior = "whitelist"

              + cookies {
                  + items = [
                      + "example",
                    ]
                }
            }

          + headers_config {
              + header_behavior = "whitelist"

              + headers {
                  + items = [
                      + "example",
                    ]
                }
            }

          + query_strings_config {
              + query_string_behavior = "whitelist"

              + query_strings {
                  + items = [
                      + "example",
                    ]
                }
            }
        }
    }

  # aws_cloudfront_cache_policy.example03 will be created
  + resource "aws_cloudfront_cache_policy" "example03" {
      + default_ttl = 86400
      + etag        = (known after apply)
      + id          = (known after apply)
      + max_ttl     = 31536000
      + min_ttl     = 31536100
      + name        = "example-policy03"

      + parameters_in_cache_key_and_forwarded_to_origin {
          + cookies_config {
              + cookie_behavior = "whitelist"

              + cookies {
                  + items = [
                      + "example",
                    ]
                }
            }

          + headers_config {
              + header_behavior = "whitelist"

              + headers {
                  + items = [
                      + "example",
                    ]
                }
            }

          + query_strings_config {
              + query_string_behavior = "whitelist"

              + query_strings {
                  + items = [
                      + "example",
                    ]
                }
            }
        }
    }

Plan: 3 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_cloudfront_cache_policy.example01: Creating...
aws_cloudfront_cache_policy.example03: Creating...
aws_cloudfront_cache_policy.example02: Creating...

Error: error creating CloudFront Cache Policy (example-policy01): InvalidArgument: MinTTL, MaxTTL and DefaultTTL should follow order MinTTL less than or equal to DefaultTTL less than or equal to MaxTTL
        status code: 400, request id: 0384afed-a23d-49c4-92e3-20dc4db8135f

  on min_ttl_test.tf line 1, in resource "aws_cloudfront_cache_policy" "example01":
   1: resource "aws_cloudfront_cache_policy" "example01" {



Error: error creating CloudFront Cache Policy (example-policy02): InvalidArgument: MinTTL, MaxTTL and DefaultTTL should follow order MinTTL less than or equal to DefaultTTL less than or equal to MaxTTL
        status code: 400, request id: e111682c-379b-4905-bbf9-5b7dd690b646

  on min_ttl_test.tf line 27, in resource "aws_cloudfront_cache_policy" "example02":
  27: resource "aws_cloudfront_cache_policy" "example02" {



Error: error creating CloudFront Cache Policy (example-policy03): InvalidArgument: MinTTL, MaxTTL and DefaultTTL should follow order MinTTL less than or equal to DefaultTTL less than or equal to MaxTTL
        status code: 400, request id: a587a036-8a95-49fa-b82b-716ac5faad4c

  on min_ttl_test.tf line 53, in resource "aws_cloudfront_cache_policy" "example03":
  53: resource "aws_cloudfront_cache_policy" "example03" {
 

Expected Behavior

It should create resources successfully and by taking max_value = 31536200 for example01 ,default_ttl = 86500 for example02 and default_ttl=max_ttl=31536100 for example03

Actual Behavior

It taking there default values if we did not specify max_ttl and default_ttl and throwing error MinTTL, MaxTTL and DefaultTTL should follow order MinTTL less than or equal to DefaultTTL less than or equal to MaxTTL

Steps to Reproduce

  1. terraform apply

Reference:

aws_cli document for clouldfront cache policy:
https://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-cache-policy.html

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/cloudfront Issues and PRs that pertain to the cloudfront service. labels May 4, 2022
@ccsandhanshive ccsandhanshive changed the title Default values of max_ttl and default_ttl not working as expected Default values of max_ttl and default_ttl not working as expected in aws_cloudfront_cache_policy May 5, 2022
@ccsandhanshive
Copy link
Author

Are there any updates on this?

@justinretzolk
Copy link
Member

Hey @ccsandhanshive 👋 Thank you for taking the time to raise this! What you're seeing here is the default values for default_ttl and max_ttl, respectively. Terraform isn't calculating the min_ttl, default_ttl, and max_ttl based off of the values that are supplied to the other parameters; rather, when default_ttl or max_ttl are not set, their default values (86400 and 31536000 respectively) are used.

@justinretzolk justinretzolk added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels May 5, 2022
@ccsandhanshive
Copy link
Author

Exactly, Terraform should calculate the default_ttl or max_ttl values based on other parameters (min_ttl, max_ttl and default_ttl ) when default_ttl or max_ttl are not set.

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label May 6, 2022
@justinretzolk justinretzolk added the enhancement Requests to existing resources that expand the functionality or scope. label May 6, 2022
@justinretzolk
Copy link
Member

Hey @ccsandhanshive -- thank you for the additional context here. I've marked this as an enhancement so that we or the community can look at implementing that functionality when time allows.

@sskender
Copy link

I can confirm the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Projects
None yet
Development

No branches or pull requests

3 participants