Resource: aws_cloudfront_continuous_deployment_policy

Terraform resource for managing an AWS CloudFront Continuous Deployment Policy.

Example Usage

Basic Usage

resource "aws_cloudfront_distribution" "staging" {
  enabled = true
  staging = true

  # ... other configuration ...
}

resource "aws_cloudfront_continuous_deployment_policy" "example" {
  enabled = true

  staging_distribution_dns_names {
    items    = [aws_cloudfront_distribution.staging.domain_name]
    quantity = 1
  }

  traffic_config {
    type = "SingleWeight"
    single_weight_config {
      weight = "0.01"
    }
  }
}

resource "aws_cloudfront_distribution" "production" {
  enabled = true

  # NOTE: A continuous deployment policy cannot be associated to distribution
  # on creation. Set this argument once the resource exists.
  continuous_deployment_policy_id = aws_cloudfront_continuous_deployment_policy.example.id

  # ... other configuration ...
}

Single Weight Config with Session Stickiness

resource "aws_cloudfront_continuous_deployment_policy" "example" {
  enabled = true

  staging_distribution_dns_names {
    items    = [aws_cloudfront_distribution.staging.domain_name]
    quantity = 1
  }

  traffic_config {
    type = "SingleWeight"
    single_weight_config {
      weight = "0.01"
      session_stickiness_config {
        idle_ttl    = 300
        maximum_ttl = 600
      }
    }
  }
}

Single Header Config

resource "aws_cloudfront_continuous_deployment_policy" "example" {
  enabled = true

  staging_distribution_dns_names {
    items    = [aws_cloudfront_distribution.staging.domain_name]
    quantity = 1
  }

  traffic_config {
    type = "SingleHeader"
    single_header_config {
      header = "aws-cf-cd-example"
      value  = "example"
    }
  }
}

Argument Reference

The following arguments are required:

staging_distribution_dns_names

traffic_config

single_header_config

single_weight_config

session_stickiness_config

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 Continuous Deployment Policy using the id. For example:

import {
  to = aws_cloudfront_continuous_deployment_policy.example
  id = "abcd-1234"
}

Using terraform import, import CloudFront Continuous Deployment Policy using the id. For example:

% terraform import aws_cloudfront_continuous_deployment_policy.example abcd-1234