Sets up a basic continuous deployment policy for AWS CloudFront with separate staging and production distributions.

Terraform Template

resource "aws_cloudfront_continuous_deployment_policy" "example" {
  enabled = true

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

  traffic_config {

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

resource "aws_cloudfront_distribution" "production" {
  continuous_deployment_policy_id = aws_cloudfront_continuous_deployment_policy.example.id
  enabled = true
}

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