Skip to content

Instantly share code, notes, and snippets.

@charity
Created April 14, 2016 01:18
Show Gist options
  • Select an option

  • Save charity/2ceebb7e86318a9477178f454dc2c733 to your computer and use it in GitHub Desktop.

Select an option

Save charity/2ceebb7e86318a9477178f454dc2c733 to your computer and use it in GitHub Desktop.

Revisions

  1. charity created this gist Apr 14, 2016.
    28 changes: 28 additions & 0 deletions peering.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # 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}"
    }