Skip to content

Instantly share code, notes, and snippets.

@charity
Created April 14, 2016 01:18
Show Gist options
  • Save charity/2ceebb7e86318a9477178f454dc2c733 to your computer and use it in GitHub Desktop.
Save charity/2ceebb7e86318a9477178f454dc2c733 to your computer and use it in GitHub Desktop.
# file name: terraform/env-staging/peering.tf
# No peering / direct connectivity between staging and prod, for safety.
resource "terraform_remote_state" "dev_state" {
backend = "s3"
config {
bucket = "${var.tf_s3_bucket}"
region = "${var.region}"
key = "${var.dev_state_file}"
}
}
# lookup and reuse the same peering connection
# add a route to the public subnet
resource "aws_route" "staging_to_dev_route" {
route_table_id = "${module.staging_vpc.public_route_table_id}"
# depends_on = ["${module.dev_vpc.public_route_table_id}"]
destination_cidr_block = "${terraform_remote_state.dev_state.output.dev_cidr_block}"
vpc_peering_connection_id = "${terraform_remote_state.dev_state.output.aws_vpc_peering_dev_staging}"
}
# add the route to each of the private route tables. routing to the /16 is fineeeeee
resource "aws_route" "dev_to_staging_int_route" {
count = "${length(split(",", var.private_ranges))}"
route_table_id = "${element(split(",", module.staging_vpc.private_route_table_id), count.index)}"
destination_cidr_block = "${terraform_remote_state.dev_state.output.dev_cidr_block}"
vpc_peering_connection_id = "${terraform_remote_state.dev_state.output.aws_vpc_peering_dev_staging}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment