forked from cloudposse/terraform-aws-vpc-peering
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgraded to terraform 0.12 syntax using the upgrade tool.
- Loading branch information
Showing
4 changed files
with
84 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,111 @@ | ||
module "label" { | ||
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3" | ||
enabled = "${var.enabled}" | ||
namespace = "${var.namespace}" | ||
name = "${var.name}" | ||
stage = "${var.stage}" | ||
delimiter = "${var.delimiter}" | ||
attributes = "${var.attributes}" | ||
tags = "${var.tags}" | ||
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.1" | ||
enabled = var.enabled | ||
namespace = var.namespace | ||
name = var.name | ||
stage = var.stage | ||
delimiter = var.delimiter | ||
attributes = var.attributes | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_vpc_peering_connection" "default" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
vpc_id = "${join("", data.aws_vpc.requestor.*.id)}" | ||
peer_vpc_id = "${join("", data.aws_vpc.acceptor.*.id)}" | ||
count = var.enabled == "true" ? 1 : 0 | ||
vpc_id = join("", data.aws_vpc.requestor.*.id) | ||
peer_vpc_id = join("", data.aws_vpc.acceptor.*.id) | ||
|
||
auto_accept = "${var.auto_accept}" | ||
auto_accept = var.auto_accept | ||
|
||
accepter { | ||
allow_remote_vpc_dns_resolution = "${var.acceptor_allow_remote_vpc_dns_resolution}" | ||
allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution | ||
} | ||
|
||
requester { | ||
allow_remote_vpc_dns_resolution = "${var.requestor_allow_remote_vpc_dns_resolution}" | ||
allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution | ||
} | ||
|
||
tags = "${module.label.tags}" | ||
tags = module.label.tags | ||
} | ||
|
||
# Lookup requestor VPC so that we can reference the CIDR | ||
data "aws_vpc" "requestor" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
id = "${var.requestor_vpc_id}" | ||
tags = "${var.requestor_vpc_tags}" | ||
count = var.enabled == "true" ? 1 : 0 | ||
id = var.requestor_vpc_id | ||
tags = var.requestor_vpc_tags | ||
} | ||
|
||
# Lookup requestor route tables | ||
data "aws_route_table" "requestor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.requestor.ids))) : 0}" | ||
subnet_id = "${element(distinct(sort(data.aws_subnet_ids.requestor.ids)), count.index)}" | ||
count = var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.requestor[0].ids))) : 0 | ||
subnet_id = element( | ||
distinct(sort(data.aws_subnet_ids.requestor[0].ids)), | ||
count.index, | ||
) | ||
} | ||
|
||
# Lookup requestor subnets | ||
data "aws_subnet_ids" "requestor" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
vpc_id = "${data.aws_vpc.requestor.id}" | ||
count = var.enabled == "true" ? 1 : 0 | ||
vpc_id = data.aws_vpc.requestor[0].id | ||
} | ||
|
||
# Lookup acceptor VPC so that we can reference the CIDR | ||
data "aws_vpc" "acceptor" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
id = "${var.acceptor_vpc_id}" | ||
tags = "${var.acceptor_vpc_tags}" | ||
count = var.enabled == "true" ? 1 : 0 | ||
id = var.acceptor_vpc_id | ||
tags = var.acceptor_vpc_tags | ||
} | ||
|
||
# Lookup acceptor subnets | ||
data "aws_subnet_ids" "acceptor" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
vpc_id = "${data.aws_vpc.acceptor.id}" | ||
count = var.enabled == "true" ? 1 : 0 | ||
vpc_id = data.aws_vpc.acceptor[0].id | ||
} | ||
|
||
# Lookup acceptor route tables | ||
data "aws_route_table" "acceptor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.acceptor.ids))) : 0}" | ||
subnet_id = "${element(distinct(sort(data.aws_subnet_ids.acceptor.ids)), count.index)}" | ||
count = var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.acceptor[0].ids))) : 0 | ||
subnet_id = element( | ||
distinct(sort(data.aws_subnet_ids.acceptor[0].ids)), | ||
count.index, | ||
) | ||
} | ||
|
||
# Create routes from requestor to acceptor | ||
resource "aws_route" "requestor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.requestor.*.route_table_id))) * length(data.aws_vpc.acceptor.cidr_block_associations) : 0}" | ||
route_table_id = "${element(distinct(sort(data.aws_route_table.requestor.*.route_table_id)), (ceil(count.index / (length(data.aws_vpc.acceptor.cidr_block_associations)))))}" | ||
destination_cidr_block = "${lookup(data.aws_vpc.acceptor.cidr_block_associations[count.index % (length(data.aws_vpc.acceptor.cidr_block_associations))], "cidr_block")}" | ||
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.id}" | ||
depends_on = ["data.aws_route_table.requestor", "aws_vpc_peering_connection.default"] | ||
count = var.enabled == "true" ? length( | ||
distinct(sort(data.aws_route_table.requestor.*.route_table_id)), | ||
) * length(data.aws_vpc.acceptor[0].cidr_block_associations) : 0 | ||
route_table_id = element( | ||
distinct(sort(data.aws_route_table.requestor.*.route_table_id)), | ||
ceil( | ||
count.index / length(data.aws_vpc.acceptor[0].cidr_block_associations), | ||
), | ||
) | ||
destination_cidr_block = data.aws_vpc.acceptor.0.cidr_block_associations[count.index % length(data.aws_vpc.acceptor[0].cidr_block_associations)]["cidr_block"] | ||
vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id | ||
depends_on = [ | ||
data.aws_route_table.requestor, | ||
aws_vpc_peering_connection.default, | ||
] | ||
} | ||
|
||
# Create routes from acceptor to requestor | ||
resource "aws_route" "acceptor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.acceptor.*.route_table_id))) * length(data.aws_vpc.requestor.cidr_block_associations) : 0}" | ||
route_table_id = "${element(distinct(sort(data.aws_route_table.acceptor.*.route_table_id)), ceil(count.index / (length(data.aws_vpc.requestor.cidr_block_associations))))}" | ||
destination_cidr_block = "${lookup(data.aws_vpc.requestor.cidr_block_associations[count.index % (length(data.aws_vpc.requestor.cidr_block_associations))], "cidr_block")}" | ||
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.id}" | ||
depends_on = ["data.aws_route_table.acceptor", "aws_vpc_peering_connection.default"] | ||
count = var.enabled == "true" ? length( | ||
distinct(sort(data.aws_route_table.acceptor.*.route_table_id)), | ||
) * length(data.aws_vpc.requestor[0].cidr_block_associations) : 0 | ||
route_table_id = element( | ||
distinct(sort(data.aws_route_table.acceptor.*.route_table_id)), | ||
ceil( | ||
count.index / length(data.aws_vpc.requestor[0].cidr_block_associations), | ||
), | ||
) | ||
destination_cidr_block = data.aws_vpc.requestor.0.cidr_block_associations[count.index % length(data.aws_vpc.requestor[0].cidr_block_associations)]["cidr_block"] | ||
vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id | ||
depends_on = [ | ||
data.aws_route_table.acceptor, | ||
aws_vpc_peering_connection.default, | ||
] | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
output "connection_id" { | ||
value = "${join("", aws_vpc_peering_connection.default.*.id)}" | ||
value = join("", aws_vpc_peering_connection.default.*.id) | ||
description = "VPC peering connection ID" | ||
} | ||
|
||
output "accept_status" { | ||
value = "${join("", aws_vpc_peering_connection.default.*.accept_status)}" | ||
value = join("", aws_vpc_peering_connection.default.*.accept_status) | ||
description = "The status of the VPC peering connection request" | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |