Open
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 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
terraform apply
Reference:
aws_cli document for clouldfront cache policy:
https://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-cache-policy.html