diff --git a/.gitignore b/.gitignore index 1062418..b10b5da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ *.iml +.terraform \ No newline at end of file diff --git a/data.tf b/data.tf index 8a289eb..3ba7ba2 100644 --- a/data.tf +++ b/data.tf @@ -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}" -} \ No newline at end of file + provider = aws.requester + vpc_id = var.requester_vpc_id +} + diff --git a/locals.tf b/locals.tf index a2e1aa9..565c2a3 100644 --- a/locals.tf +++ b/locals.tf @@ -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)}" -} \ No newline at end of file + 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) +} + diff --git a/main.tf b/main.tf index 7ea4580..7aa4881 100644 --- a/main.tf +++ b/main.tf @@ -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 } + diff --git a/outputs.tf b/outputs.tf index 1a513bd..583d3a3 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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}" -} \ No newline at end of file + value = aws_vpc_peering_connection.connection.id +} + diff --git a/variables.tf b/variables.tf index fedc65e..86073df 100644 --- a/variables.tf +++ b/variables.tf @@ -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" -} \ No newline at end of file + type = string +} + diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}