Data Source: aws_route53_traffic_policy_document

Generates an Route53 traffic policy document in JSON format for use with resources that expect policy documents such as aws_route53_traffic_policy.

Example Usage

Basic Example

data "aws_region" "current" {}

data "aws_route53_traffic_policy_document" "example" {
  record_type = "A"
  start_rule  = "site_switch"

  endpoint {
    id    = "my_elb"
    type  = "elastic-load-balancer"
    value = "elb-111111.${data.aws_region.current.name}.elb.amazonaws.com"
  }
  endpoint {
    id     = "site_down_banner"
    type   = "s3-website"
    region = data.aws_region.current.name
    value  = "www.example.com"
  }

  rule {
    id   = "site_switch"
    type = "failover"

    primary {
      endpoint_reference = "my_elb"
    }
    secondary {
      endpoint_reference = "site_down_banner"
    }
  }
}

resource "aws_route53_traffic_policy" "example" {
  name     = "example"
  comment  = "example comment"
  document = data.aws_route53_traffic_policy_document.example.json
}

Complex Example

The following example showcases the use of nested rules within the traffic policy document and introduces the geoproximity rule type.

data "aws_route53_traffic_policy_document" "example" {
  record_type = "A"
  start_rule  = "geoproximity_rule"

  # NA Region endpoints
  endpoint {
    id    = "na_endpoint_a"
    type  = "elastic-load-balancer"
    value = "elb-111111.us-west-1.elb.amazonaws.com"
  }

  endpoint {
    id    = "na_endpoint_b"
    type  = "elastic-load-balancer"
    value = "elb-222222.us-west-1.elb.amazonaws.com"
  }

  # EU Region endpoint
  endpoint {
    id    = "eu_endpoint"
    type  = "elastic-load-balancer"
    value = "elb-333333.eu-west-1.elb.amazonaws.com"
  }

  # AP Region endpoint
  endpoint {
    id    = "ap_endpoint"
    type  = "elastic-load-balancer"
    value = "elb-444444.ap-northeast-2.elb.amazonaws.com"
  }

  rule {
    id   = "na_rule"
    type = "failover"

    primary {
      endpoint_reference = "na_endpoint_a"
    }

    secondary {
      endpoint_reference = "na_endpoint_b"
    }

  }

  rule {
    id   = "geoproximity_rule"
    type = "geoproximity"

    geo_proximity_location {
      region                 = "aws:route53:us-west-1"
      bias                   = 10
      evaluate_target_health = true
      rule_reference         = "na_rule"
    }

    geo_proximity_location {
      region                 = "aws:route53:eu-west-1"
      bias                   = 10
      evaluate_target_health = true
      endpoint_reference     = "eu_endpoint"
    }

    geo_proximity_location {
      region                 = "aws:route53:ap-northeast-2"
      bias                   = 0
      evaluate_target_health = true
      endpoint_reference     = "ap_endpoint"
    }
  }

}

resource "aws_route53_traffic_policy" "example" {
  name     = "example"
  comment  = "example comment"
  document = data.aws_route53_traffic_policy_document.example.json
}

Argument Reference

The following arguments are optional:

endpoint

rule

primary and secondary

location

geo_proximity_location

region

item

Attribute Reference

This data source exports the following attributes in addition to the arguments above: