Resource: aws_cloudfront_cache_policy

Example Usage

Use the aws_cloudfront_cache_policy resource to create a cache policy for CloudFront.

resource "aws_cloudfront_cache_policy" "example" {
  name        = "example-policy"
  comment     = "test comment"
  default_ttl = 50
  max_ttl     = 100
  min_ttl     = 1
  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"]
      }
    }
  }
}

Argument Reference

This resource supports the following arguments:

Parameters In Cache Key And Forwarded To Origin

Cookies Config

Headers Config

Query String Config

Items

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import CloudFront cache policies using the id of the cache policy. For example:

import {
  to = aws_cloudfront_cache_policy.policy
  id = "658327ea-f89d-4fab-a63d-7e88639e58f6"
}

Using terraform import, import CloudFront cache policies using the id of the cache policy. For example:

% terraform import aws_cloudfront_cache_policy.policy 658327ea-f89d-4fab-a63d-7e88639e58f6