Last active
October 18, 2017 13:56
-
-
Save AndrewFarley/c4b17aa52e5826f20bfcf42cd3a213d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "eu-west-1" | |
} | |
# These are inputs we need to define | |
variable "domain" { | |
default = "mydomain.com" | |
} | |
# For every VPC in here we'll associate with our internal zone | |
variable "vpcs" { | |
default = ["vpc-f2d19d95", "vpc-18c38f7f", "vpc-72056315"] | |
} | |
# These are the DNS records we'll create as subdomains, either a or cname records | |
locals { | |
private_a_records = { | |
alpha = ["10.10.10.1"] | |
beta = ["10.10.10.2"] | |
charlie = ["10.10.10.3", "10.10.10.4"] | |
} | |
private_cname_records = { | |
delta = ["someplace.myotherdomain.com"] | |
echo = ["someotherplace.myotherdomain.com"] | |
} | |
} | |
# This creates our private zone | |
resource "aws_route53_zone" "internal-zone" { | |
name = "${var.domain}" | |
comment = "Internal Zone" | |
vpc_id = "${element(var.vpcs, 0)}" | |
} | |
# This creates one or many secondary VPC association, defined in the list variable "vpcs" | |
resource "aws_route53_zone_association" "internal-zone-associations" { | |
count = "${length(var.vpcs) - 1}" | |
zone_id = "${aws_route53_zone.internal-zone.zone_id}" | |
vpc_id = "${var.vpcs[count.index + 1]}" | |
} | |
# This creates as many private a records as we define above | |
resource "aws_route53_record" "internal-a-records" { | |
count = "${length(local.private_a_records)}" | |
zone_id = "${aws_route53_zone.internal-zone.zone_id}" | |
name = "${element(keys(local.private_a_records), count.index)}.${var.domain}" | |
type = "A" | |
ttl = "300" | |
records = "${local.private_a_records[element(keys(local.private_a_records), count.index)]}" | |
} | |
# This creates as many private cname records as we define above | |
resource "aws_route53_record" "internal-cname-records" { | |
count = "${length(local.private_cname_records)}" | |
zone_id = "${aws_route53_zone.internal-zone.zone_id}" | |
name = "${element(keys(local.private_cname_records), count.index)}.${var.domain}" | |
type = "CNAME" | |
ttl = "300" | |
records = "${local.private_cname_records[element(keys(local.private_cname_records), count.index)]}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment