Skip to content

Commit

Permalink
Merge pull request #4 from QuiNovas/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vchinnakotla authored Jul 5, 2019
2 parents ec2cd3e + 36b7270 commit 8c3f2cd
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
*.iml
.terraform
23 changes: 12 additions & 11 deletions data.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
data "aws_caller_identity" "accepter" {
provider = "aws.accepter"
provider = aws.accepter
}

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

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

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

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

data "aws_route_tables" "requester" {
provider = "aws.requester"
vpc_id = "${var.requester_vpc_id}"
}
provider = aws.requester
vpc_id = var.requester_vpc_id
}

15 changes: 8 additions & 7 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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)}"
}
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)
}

83 changes: 46 additions & 37 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,62 +1,71 @@
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}"
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}"
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}"
accepter {
allow_classic_link_to_remote_vpc = lookup(var.accepter_options, "allow_classic_link_to_remote_vpc", false)
allow_remote_vpc_dns_resolution = lookup(var.accepter_options, "allow_remote_vpc_dns_resolution", false)
allow_vpc_to_remote_classic_link = lookup(var.accepter_options, "allow_vpc_to_remote_classic_link", false)
}
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}"
accepter {
allow_classic_link_to_remote_vpc = lookup(var.requester_options, "allow_classic_link_to_remote_vpc", false)
allow_remote_vpc_dns_resolution = lookup(var.requester_options, "allow_remote_vpc_dns_resolution", false)
allow_vpc_to_remote_classic_link = lookup(var.requester_options, "allow_vpc_to_remote_classic_link", false)
}
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}"
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}"
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}"
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}"
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
}

7 changes: 4 additions & 3 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
output "accept_status" {
description = "The status of the VPC Peering Connection request."
value = "${aws_vpc_peering_connection.connection.accept_status}"
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}"
}
value = aws_vpc_peering_connection.connection.id
}

27 changes: 14 additions & 13 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
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"
type = map(string)
}

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"
type = list(string)
}

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

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

variable "accepter_vpc_id" {
description = "The ID of the VPC with which you are creating the VPC Peering Connection."
type = "string"
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"
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(string)
}

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"
type = list(string)
}

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

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

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

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

4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 8c3f2cd

Please sign in to comment.