Skip to content

Commit

Permalink
Merge pull request #4 from dreamteam-gg/PEERING
Browse files Browse the repository at this point in the history
Added support to add route with already created peering connection
  • Loading branch information
grem11n authored Jul 23, 2018
2 parents c06bf36 + 704a001 commit afacc3a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ module "vpc-peering" {
auto_accept_peering = true
}
```

Usage with already created peering connection:
```hc1
module "vpc-peering" {
source = "./terraform-aws-vpc-peering"
owner_account_id = "000000000000"
vpc_peer_id = "vpc-00000000"
this_vpc_id = "${module.vpc.vpc_id}"
private_route_table_ids = ["${module.vpc.private_route_table_ids}"]
public_route_table_ids = ["${module.vpc.public_route_table_ids}"]
peer_cidr_block = "10.1.0.1/24"
auto_accept_peering = true
create_peering = 0
peering_id = "pcx-00000000"
}
```
Examples
--------
Complete example is shown above
Expand Down
11 changes: 4 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# VPC peering connection #
##########################
resource "aws_vpc_peering_connection" "this" {
count = "${var.create_peering ? 1 : 0}"
peer_owner_id = "${var.owner_account_id}"
peer_vpc_id = "${var.vpc_peer_id}"
vpc_id = "${var.this_vpc_id}"
Expand All @@ -13,21 +14,17 @@ resource "aws_vpc_peering_connection" "this" {
##################
resource "aws_route" "private_route_table" {
count = "${length(var.private_route_table_ids)}"

route_table_id = "${element(var.private_route_table_ids, count.index)}"
destination_cidr_block = "${var.peer_cidr_block}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.this.id}"
depends_on = ["aws_vpc_peering_connection.this"]
vpc_peering_connection_id = "${var.peering_id == "" ? element(concat(aws_vpc_peering_connection.this.*.id, list("")), 0) : var.peering_id}"
}

#################
# Public routes #
#################
resource "aws_route" "public_route_table" {
count = "${length(var.public_route_table_ids) > 0 ? 1: 0}"

count = "${length(var.public_route_table_ids)}"
route_table_id = "${element(var.public_route_table_ids, count.index)}"
destination_cidr_block = "${var.peer_cidr_block}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.this.id}"
depends_on = ["aws_vpc_peering_connection.this"]
vpc_peering_connection_id = "${var.peering_id == "" ? element(concat(aws_vpc_peering_connection.this.*.id, list("")), 0) : var.peering_id}"
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output "vpc_peering_id" {
description = "Peering connection ID"
value = "${aws_vpc_peering_connection.this.id}"
value = "${var.peering_id == "" ? element(concat(aws_vpc_peering_connection.this.*.id, list("")), 0) : var.peering_id}"
}

output "private_route_tables" {
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ variable "auto_accept_peering" {
description = "Auto accept peering connection"
default = false
}

variable "create_peering" {
description = "Create peering connection, 0 to not create"
default = 1
}

variable "peering_id" {
description = "Provide already existing peering connection id"
default = ""
}

0 comments on commit afacc3a

Please sign in to comment.