Last active
October 26, 2017 00:05
-
-
Save tom-butler/12bc9c8b315c03792e37a555a89796ea to your computer and use it in GitHub Desktop.
vpc-peer
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
#============================================================== | |
# Vpc.tf | |
#============================================================== | |
# Create a VPC Peering connection and setup routes on both sides | |
# Create a VPC peering connection | |
resource "aws_vpc_peering_connection" "admin_dblink_peer" { | |
peer_vpc_id = "${aws_vpc.vpc.id}" | |
vpc_id = "${var.dblink_vpc_id}" | |
requester { | |
allow_remote_vpc_dns_resolution = true | |
} | |
accepter { | |
allow_remote_vpc_dns_resolution = true | |
} | |
auto_accept = true | |
tags { | |
Name = "VPC Peer for DB Admin" | |
} | |
} | |
#-------------------------------------------------------------- | |
# Route our traffic to the DB VPC | |
#-------------------------------------------------------------- | |
# Add a route to our subnet | |
resource "aws_route_table" "admin_subnet_route_table" { | |
vpc_id = "${aws_vpc.vpc.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.admin_igw.id}" | |
} | |
route { | |
cidr_block = "${var.dblink_vpc_cidr_block}" | |
vpc_peering_connection_id = "${aws_vpc_peering_connection.admin_dblink_peer.id}" | |
} | |
tags { | |
Name = "${var.stack_name}-admin-subnet-${var.environment}-${var.availability_zone}" | |
owner = "${var.owner}" | |
stack_name = "${var.stack_name}" | |
environment = "${var.environment}" | |
created_by = "terraform" | |
} | |
} | |
resource "aws_route_table_association" "admin_subnet_route_assoc" { | |
subnet_id = "${aws_subnet.admin.id}" | |
route_table_id = "${aws_route_table.admin_subnet_route_table.id}" | |
} | |
# add the route to our vpc default route table | |
resource "aws_route" "admin_vpc_route" { | |
route_table_id = "${aws_vpc.vpc.default_route_table_id}" | |
destination_cidr_block = "${var.dblink_vpc_cidr_block}" | |
vpc_peering_connection_id = "${aws_vpc_peering_connection.admin_dblink_peer.id}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment