Skip to content

Commit

Permalink
Merge pull request #1 from QuiNovas/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
joseph-wortmann authored Feb 26, 2019
2 parents 1bfd1a8 + 3b327d9 commit ec2cd3e
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
*.iml
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# terraform-aws-vpc-peering

This module creates the requested VPC peering and routes required.

## Authors

Module managed by Quinovas (https://github.com/QuiNovas)

## License

Apache License, Version 2.0, January 2004 (http://www.apache.org/licenses/). See LICENSE for full details.
27 changes: 27 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
data "aws_caller_identity" "accepter" {
provider = "aws.accepter"
}

data "aws_region" "accepter" {
provider = "aws.accepter"
}

data "aws_vpc" "accepter" {
id = "${var.accepter_vpc_id}"
provider = "aws.accepter"
}

data "aws_vpc" "requester" {
id = "${var.requester_vpc_id}"
provider = "aws.requester"
}

data "aws_route_tables" "accepter" {
provider = "aws.accepter"
vpc_id = "${var.accepter_vpc_id}"
}

data "aws_route_tables" "requester" {
provider = "aws.requester"
vpc_id = "${var.requester_vpc_id}"
}
8 changes: 8 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locals {
accepter_route_table_ids = "${split(",", local.accepter_route_table_ids_join)}"
accepter_route_table_ids_join = "${var.accepter_route_table_ids_count > 0 ? join(",", var.accepter_route_table_ids) : join(",", data.aws_route_tables.accepter.ids)}"
accepter_route_table_ids_count = "${var.accepter_route_table_ids_count > 0 ? var.accepter_route_table_ids_count : length(data.aws_route_tables.accepter.ids)}"
requester_route_table_ids = "${split(",", local.requester_route_table_ids_join)}"
requester_route_table_ids_join = "${var.requester_route_table_ids_count > 0 ? join(",", var.requester_route_table_ids) : join(",", data.aws_route_tables.requester.ids)}"
requester_route_table_ids_count = "${var.requester_route_table_ids_count > 0 ? var.requester_route_table_ids_count : length(data.aws_route_tables.accepter.ids)}"
}
62 changes: 62 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
resource "aws_vpc_peering_connection" "connection" {
auto_accept = false
peer_owner_id = "${data.aws_caller_identity.accepter.account_id}"
peer_region = "${data.aws_region.accepter.name}"
peer_vpc_id = "${data.aws_vpc.accepter.id}"
provider = "aws.requester"
tags = "${var.requester_tags}"
vpc_id = "${data.aws_vpc.requester.id}"
}

resource "aws_vpc_peering_connection_accepter" "accepter" {
auto_accept = true
provider = "aws.accepter"
tags = "${var.accepter_tags}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}

resource "aws_vpc_peering_connection_options" "accepter" {
accepter = "${var.accepter_options}"
count = "${length(keys(var.accepter_options)) > 0 ? 1 : 0}"
provider = "aws.accepter"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}

resource "aws_vpc_peering_connection_options" "requester" {
accepter = "${var.requester_options}"
count = "${length(keys(var.requester_options)) > 0 ? 1 : 0}"
provider = "aws.requester"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}

resource "aws_route" "accepter_ipv4" {
count = "${local.accepter_route_table_ids_count}"
destination_cidr_block = "${data.aws_vpc.requester.cidr_block}"
provider = "aws.accepter"
route_table_id = "${local.accepter_route_table_ids[count.index]}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}

resource "aws_route" "accepter_ipv6" {
count = "${var.route_ipv6 ? local.accepter_route_table_ids_count : 0}"
destination_ipv6_cidr_block = "${data.aws_vpc.requester.ipv6_cidr_block}"
provider = "aws.accepter"
route_table_id = "${local.accepter_route_table_ids[count.index]}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}

resource "aws_route" "requester_ipv4" {
count = "${local.requester_route_table_ids_count}"
destination_cidr_block = "${data.aws_vpc.accepter.cidr_block}"
provider = "aws.requester"
route_table_id = "${local.requester_route_table_ids[count.index]}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}

resource "aws_route" "requester_ipv6" {
count = "${var.route_ipv6 ? local.requester_route_table_ids_count : 0}"
destination_ipv6_cidr_block = "${data.aws_vpc.accepter.ipv6_cidr_block}"
provider = "aws.requester"
route_table_id = "${local.requester_route_table_ids[count.index]}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.connection.id}"
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "accept_status" {
description = "The status of the VPC Peering Connection request."
value = "${aws_vpc_peering_connection.connection.accept_status}"
}

output "id" {
description = "The ID of the VPC Peering Connection."
value = "${aws_vpc_peering_connection.connection.id}"
}
7 changes: 7 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider "aws" {
alias = "accepter"
}

provider "aws" {
alias = "requester"
}
63 changes: 63 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
variable "accepter_options" {
default = {}
description = "An optional configuration block that allows for VPC Peering Connection options to be set for the VPC that accepts the peering connection (a maximum of one)."
type = "map"
}

variable "accepter_route_table_ids" {
default = []
description = "A list of route table ids within the accepter VPC to attach the peering route to. If not present all route tables in the VPC will be updated."
type = "list"
}

variable "accepter_route_table_ids_count" {
default = 0
description = "The number of route table ids in accepter_route_table_ids."
type = "string"
}

variable "accepter_tags" {
default = {}
description = "Tags to add to the accepter side resources of the connection."
type = "map"
}

variable "accepter_vpc_id" {
description = "The ID of the VPC with which you are creating the VPC Peering Connection."
type = "string"
}

variable "requester_options" {
default = {}
description = "A optional configuration block that allows for VPC Peering Connection options to be set for the VPC that requests the peering connection (a maximum of one)."
type = "map"
}

variable "requester_route_table_ids" {
default = []
description = "A list of route table ids within the requester VPC to attach the peering route to. If not present all route tables in the VPC will be updated."
type = "list"
}

variable "requester_route_table_ids_count" {
default = 0
description = "The number of route table ids in requester_route_table_ids."
type = "string"
}

variable "requester_tags" {
default = {}
description = "Tags to add to the requester side resources of the connection."
type = "map"
}

variable "requester_vpc_id" {
description = "The ID of the requester VPC."
type = "string"
}

variable "route_ipv6" {
default = false
description = "Creates ipv6 routes in addition to the standard ipv4 routes"
type = "string"
}

0 comments on commit ec2cd3e

Please sign in to comment.