From 3d3221b026f43ce292a506536f82e5b48e0eead5 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Tue, 3 Jun 2025 16:19:15 -0400 Subject: [PATCH 01/12] try this --- .history/main_20250603161025.tf | 76 +++++++++++++++++++++++++ .history/main_20250603161622.tf | 77 ++++++++++++++++++++++++++ .history/main_20250603161747.tf | 79 ++++++++++++++++++++++++++ .history/variables_20250603161025.tf | 83 ++++++++++++++++++++++++++++ .history/variables_20250603161909.tf | 83 ++++++++++++++++++++++++++++ .history/versions_20250603161025.tf | 10 ++++ .history/versions_20250603161409.tf | 11 ++++ .history/versions_20250603161437.tf | 11 ++++ .history/versions_20250603161445.tf | 11 ++++ .history/versions_20250603161547.tf | 11 ++++ .vscode/settings.json | 3 + main.tf | 9 ++- versions.tf | 1 + 13 files changed, 462 insertions(+), 3 deletions(-) create mode 100644 .history/main_20250603161025.tf create mode 100644 .history/main_20250603161622.tf create mode 100644 .history/main_20250603161747.tf create mode 100644 .history/variables_20250603161025.tf create mode 100644 .history/variables_20250603161909.tf create mode 100644 .history/versions_20250603161025.tf create mode 100644 .history/versions_20250603161409.tf create mode 100644 .history/versions_20250603161437.tf create mode 100644 .history/versions_20250603161445.tf create mode 100644 .history/versions_20250603161547.tf create mode 100644 .vscode/settings.json diff --git a/.history/main_20250603161025.tf b/.history/main_20250603161025.tf new file mode 100644 index 0000000..7c6f352 --- /dev/null +++ b/.history/main_20250603161025.tf @@ -0,0 +1,76 @@ +resource "aws_vpc_peering_connection" "default" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.requestor[*].id) + peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) + + auto_accept = var.auto_accept + + accepter { + 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 + } + + tags = module.this.tags + + timeouts { + create = var.create_timeout + update = var.update_timeout + delete = var.delete_timeout + } +} + +# Lookup requestor VPC so that we can reference the CIDR +data "aws_vpc" "requestor" { + count = module.this.enabled ? 1 : 0 + id = var.requestor_vpc_id + tags = var.requestor_vpc_tags +} + +# Lookup acceptor VPC so that we can reference the CIDR +data "aws_vpc" "acceptor" { + count = module.this.enabled ? 1 : 0 + id = var.acceptor_vpc_id + tags = var.acceptor_vpc_tags +} + +data "aws_route_tables" "requestor" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.requestor[*].id) + tags = var.requestor_route_table_tags +} + +data "aws_route_tables" "acceptor" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.acceptor[*].id) + tags = var.acceptor_route_table_tags +} + +locals { + requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ + for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block + ], var.requestor_ignore_cidrs)) : [] + acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ + for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block + ], var.acceptor_ignore_cidrs)) : [] +} + +# Create routes from requestor to acceptor +resource "aws_route" "requestor" { + count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 + route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) + destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] + vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) + depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default] +} + +# Create routes from acceptor to requestor +resource "aws_route" "acceptor" { + count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 + route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) + destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] + vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) + depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default] +} diff --git a/.history/main_20250603161622.tf b/.history/main_20250603161622.tf new file mode 100644 index 0000000..ab5150f --- /dev/null +++ b/.history/main_20250603161622.tf @@ -0,0 +1,77 @@ +resource "aws_vpc_peering_connection" "default" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.requestor[*].id) + peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) + + auto_accept = var.auto_accept + + accepter { + 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 + } + + tags = module.this.tags + + timeouts { + create = var.create_timeout + update = var.update_timeout + delete = var.delete_timeout + } +} + +# Lookup requestor VPC so that we can reference the CIDR +data "aws_vpc" "requestor" { + count = module.this.enabled ? 1 : 0 + id = var.requestor_vpc_id + tags = var.requestor_vpc_tags +} + +# Lookup acceptor VPC so that we can reference the CIDR +data "aws_vpc" "acceptor" { + provider = aws.acceptor + count = module.this.enabled ? 1 : 0 + id = var.acceptor_vpc_id + tags = var.acceptor_vpc_tags +} + +data "aws_route_tables" "requestor" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.requestor[*].id) + tags = var.requestor_route_table_tags +} + +data "aws_route_tables" "acceptor" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.acceptor[*].id) + tags = var.acceptor_route_table_tags +} + +locals { + requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ + for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block + ], var.requestor_ignore_cidrs)) : [] + acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ + for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block + ], var.acceptor_ignore_cidrs)) : [] +} + +# Create routes from requestor to acceptor +resource "aws_route" "requestor" { + count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 + route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) + destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] + vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) + depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default] +} + +# Create routes from acceptor to requestor +resource "aws_route" "acceptor" { + count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 + route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) + destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] + vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) + depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default] +} diff --git a/.history/main_20250603161747.tf b/.history/main_20250603161747.tf new file mode 100644 index 0000000..da35057 --- /dev/null +++ b/.history/main_20250603161747.tf @@ -0,0 +1,79 @@ +resource "aws_vpc_peering_connection" "default" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.requestor[*].id) + peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) + + auto_accept = var.auto_accept + + accepter { + 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 + } + + tags = module.this.tags + + timeouts { + create = var.create_timeout + update = var.update_timeout + delete = var.delete_timeout + } +} + +# Lookup requestor VPC so that we can reference the CIDR +data "aws_vpc" "requestor" { + count = module.this.enabled ? 1 : 0 + id = var.requestor_vpc_id + tags = var.requestor_vpc_tags +} + +# Lookup acceptor VPC so that we can reference the CIDR +data "aws_vpc" "acceptor" { + provider = aws.acceptor + count = module.this.enabled ? 1 : 0 + id = var.acceptor_vpc_id + tags = var.acceptor_vpc_tags +} + +data "aws_route_tables" "requestor" { + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.requestor[*].id) + tags = var.requestor_route_table_tags +} + +data "aws_route_tables" "acceptor" { + provider = aws.acceptor + count = module.this.enabled ? 1 : 0 + vpc_id = join("", data.aws_vpc.acceptor[*].id) + tags = var.acceptor_route_table_tags +} + +locals { + requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ + for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block + ], var.requestor_ignore_cidrs)) : [] + acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ + for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block + ], var.acceptor_ignore_cidrs)) : [] +} + +# Create routes from requestor to acceptor +resource "aws_route" "requestor" { + count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 + route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) + destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] + vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) + depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default] +} + +# Create routes from acceptor to requestor +resource "aws_route" "acceptor" { + provider = aws.acceptor + count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 + route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) + destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] + vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) + depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default] +} diff --git a/.history/variables_20250603161025.tf b/.history/variables_20250603161025.tf new file mode 100644 index 0000000..c53135b --- /dev/null +++ b/.history/variables_20250603161025.tf @@ -0,0 +1,83 @@ +variable "requestor_vpc_id" { + type = string + description = "Requestor VPC ID" + default = "" +} + +variable "requestor_vpc_tags" { + type = map(string) + description = "Requestor VPC tags" + default = {} +} + +variable "requestor_route_table_tags" { + type = map(string) + description = "Only add peer routes to requestor VPC route tables matching these tags" + default = {} +} + +variable "acceptor_vpc_id" { + type = string + description = "Acceptor VPC ID" + default = "" +} + +variable "acceptor_vpc_tags" { + type = map(string) + description = "Acceptor VPC tags" + default = {} +} + +variable "acceptor_route_table_tags" { + type = map(string) + description = "Only add peer routes to acceptor VPC route tables matching these tags" + default = {} +} + +variable "auto_accept" { + type = bool + default = true + description = "Automatically accept the peering (both VPCs need to be in the same AWS account)" +} + +variable "acceptor_allow_remote_vpc_dns_resolution" { + type = bool + default = true + description = "Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC" +} + +variable "requestor_allow_remote_vpc_dns_resolution" { + type = bool + default = true + description = "Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC" +} + +variable "create_timeout" { + type = string + description = "VPC peering connection create timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" + default = "3m" +} + +variable "update_timeout" { + type = string + description = "VPC peering connection update timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" + default = "3m" +} + +variable "delete_timeout" { + type = string + description = "VPC peering connection delete timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" + default = "5m" +} + +variable "requestor_ignore_cidrs" { + type = list(string) + description = "A list of CIDR blocks from the requestor VPC to ignore" + default = [] +} + +variable "acceptor_ignore_cidrs" { + type = list(string) + description = "A list of CIDR blocks from the acceptor VPC to ignore" + default = [] +} diff --git a/.history/variables_20250603161909.tf b/.history/variables_20250603161909.tf new file mode 100644 index 0000000..c53135b --- /dev/null +++ b/.history/variables_20250603161909.tf @@ -0,0 +1,83 @@ +variable "requestor_vpc_id" { + type = string + description = "Requestor VPC ID" + default = "" +} + +variable "requestor_vpc_tags" { + type = map(string) + description = "Requestor VPC tags" + default = {} +} + +variable "requestor_route_table_tags" { + type = map(string) + description = "Only add peer routes to requestor VPC route tables matching these tags" + default = {} +} + +variable "acceptor_vpc_id" { + type = string + description = "Acceptor VPC ID" + default = "" +} + +variable "acceptor_vpc_tags" { + type = map(string) + description = "Acceptor VPC tags" + default = {} +} + +variable "acceptor_route_table_tags" { + type = map(string) + description = "Only add peer routes to acceptor VPC route tables matching these tags" + default = {} +} + +variable "auto_accept" { + type = bool + default = true + description = "Automatically accept the peering (both VPCs need to be in the same AWS account)" +} + +variable "acceptor_allow_remote_vpc_dns_resolution" { + type = bool + default = true + description = "Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC" +} + +variable "requestor_allow_remote_vpc_dns_resolution" { + type = bool + default = true + description = "Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC" +} + +variable "create_timeout" { + type = string + description = "VPC peering connection create timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" + default = "3m" +} + +variable "update_timeout" { + type = string + description = "VPC peering connection update timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" + default = "3m" +} + +variable "delete_timeout" { + type = string + description = "VPC peering connection delete timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" + default = "5m" +} + +variable "requestor_ignore_cidrs" { + type = list(string) + description = "A list of CIDR blocks from the requestor VPC to ignore" + default = [] +} + +variable "acceptor_ignore_cidrs" { + type = list(string) + description = "A list of CIDR blocks from the acceptor VPC to ignore" + default = [] +} diff --git a/.history/versions_20250603161025.tf b/.history/versions_20250603161025.tf new file mode 100644 index 0000000..29ec41d --- /dev/null +++ b/.history/versions_20250603161025.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + } + } +} diff --git a/.history/versions_20250603161409.tf b/.history/versions_20250603161409.tf new file mode 100644 index 0000000..7480818 --- /dev/null +++ b/.history/versions_20250603161409.tf @@ -0,0 +1,11 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + configuration_aliases = [ aws.acceptor ] + } + } +} diff --git a/.history/versions_20250603161437.tf b/.history/versions_20250603161437.tf new file mode 100644 index 0000000..59a7c9a --- /dev/null +++ b/.history/versions_20250603161437.tf @@ -0,0 +1,11 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + configuration_aliases = [ aws.acceptor ] + } + } +} \ No newline at end of file diff --git a/.history/versions_20250603161445.tf b/.history/versions_20250603161445.tf new file mode 100644 index 0000000..7480818 --- /dev/null +++ b/.history/versions_20250603161445.tf @@ -0,0 +1,11 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + configuration_aliases = [ aws.acceptor ] + } + } +} diff --git a/.history/versions_20250603161547.tf b/.history/versions_20250603161547.tf new file mode 100644 index 0000000..7480818 --- /dev/null +++ b/.history/versions_20250603161547.tf @@ -0,0 +1,11 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + configuration_aliases = [ aws.acceptor ] + } + } +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..082b194 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.configureOnOpen": false +} \ No newline at end of file diff --git a/main.tf b/main.tf index 7c6f352..da35057 100644 --- a/main.tf +++ b/main.tf @@ -31,9 +31,10 @@ data "aws_vpc" "requestor" { # Lookup acceptor VPC so that we can reference the CIDR data "aws_vpc" "acceptor" { - count = module.this.enabled ? 1 : 0 - id = var.acceptor_vpc_id - tags = var.acceptor_vpc_tags + provider = aws.acceptor + count = module.this.enabled ? 1 : 0 + id = var.acceptor_vpc_id + tags = var.acceptor_vpc_tags } data "aws_route_tables" "requestor" { @@ -43,6 +44,7 @@ data "aws_route_tables" "requestor" { } data "aws_route_tables" "acceptor" { + provider = aws.acceptor count = module.this.enabled ? 1 : 0 vpc_id = join("", data.aws_vpc.acceptor[*].id) tags = var.acceptor_route_table_tags @@ -68,6 +70,7 @@ resource "aws_route" "requestor" { # Create routes from acceptor to requestor resource "aws_route" "acceptor" { + provider = aws.acceptor count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] diff --git a/versions.tf b/versions.tf index 29ec41d..7480818 100644 --- a/versions.tf +++ b/versions.tf @@ -5,6 +5,7 @@ terraform { aws = { source = "hashicorp/aws" version = ">= 5.0" + configuration_aliases = [ aws.acceptor ] } } } From cd05a0a7bba1562a91ee88b8564af27086f68673 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Tue, 3 Jun 2025 16:19:38 -0400 Subject: [PATCH 02/12] try this --- .history/main_20250603161025.tf | 76 ------------------------- .history/main_20250603161622.tf | 77 -------------------------- .history/main_20250603161747.tf | 79 -------------------------- .history/variables_20250603161025.tf | 83 ---------------------------- .history/variables_20250603161909.tf | 83 ---------------------------- .history/versions_20250603161025.tf | 10 ---- .history/versions_20250603161409.tf | 11 ---- .history/versions_20250603161437.tf | 11 ---- .history/versions_20250603161445.tf | 11 ---- .history/versions_20250603161547.tf | 11 ---- 10 files changed, 452 deletions(-) delete mode 100644 .history/main_20250603161025.tf delete mode 100644 .history/main_20250603161622.tf delete mode 100644 .history/main_20250603161747.tf delete mode 100644 .history/variables_20250603161025.tf delete mode 100644 .history/variables_20250603161909.tf delete mode 100644 .history/versions_20250603161025.tf delete mode 100644 .history/versions_20250603161409.tf delete mode 100644 .history/versions_20250603161437.tf delete mode 100644 .history/versions_20250603161445.tf delete mode 100644 .history/versions_20250603161547.tf diff --git a/.history/main_20250603161025.tf b/.history/main_20250603161025.tf deleted file mode 100644 index 7c6f352..0000000 --- a/.history/main_20250603161025.tf +++ /dev/null @@ -1,76 +0,0 @@ -resource "aws_vpc_peering_connection" "default" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.requestor[*].id) - peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) - - auto_accept = var.auto_accept - - accepter { - 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 - } - - tags = module.this.tags - - timeouts { - create = var.create_timeout - update = var.update_timeout - delete = var.delete_timeout - } -} - -# Lookup requestor VPC so that we can reference the CIDR -data "aws_vpc" "requestor" { - count = module.this.enabled ? 1 : 0 - id = var.requestor_vpc_id - tags = var.requestor_vpc_tags -} - -# Lookup acceptor VPC so that we can reference the CIDR -data "aws_vpc" "acceptor" { - count = module.this.enabled ? 1 : 0 - id = var.acceptor_vpc_id - tags = var.acceptor_vpc_tags -} - -data "aws_route_tables" "requestor" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.requestor[*].id) - tags = var.requestor_route_table_tags -} - -data "aws_route_tables" "acceptor" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.acceptor[*].id) - tags = var.acceptor_route_table_tags -} - -locals { - requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ - for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block - ], var.requestor_ignore_cidrs)) : [] - acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ - for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block - ], var.acceptor_ignore_cidrs)) : [] -} - -# Create routes from requestor to acceptor -resource "aws_route" "requestor" { - count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 - route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) - destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] - vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) - depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default] -} - -# Create routes from acceptor to requestor -resource "aws_route" "acceptor" { - count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 - route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) - destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] - vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) - depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default] -} diff --git a/.history/main_20250603161622.tf b/.history/main_20250603161622.tf deleted file mode 100644 index ab5150f..0000000 --- a/.history/main_20250603161622.tf +++ /dev/null @@ -1,77 +0,0 @@ -resource "aws_vpc_peering_connection" "default" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.requestor[*].id) - peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) - - auto_accept = var.auto_accept - - accepter { - 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 - } - - tags = module.this.tags - - timeouts { - create = var.create_timeout - update = var.update_timeout - delete = var.delete_timeout - } -} - -# Lookup requestor VPC so that we can reference the CIDR -data "aws_vpc" "requestor" { - count = module.this.enabled ? 1 : 0 - id = var.requestor_vpc_id - tags = var.requestor_vpc_tags -} - -# Lookup acceptor VPC so that we can reference the CIDR -data "aws_vpc" "acceptor" { - provider = aws.acceptor - count = module.this.enabled ? 1 : 0 - id = var.acceptor_vpc_id - tags = var.acceptor_vpc_tags -} - -data "aws_route_tables" "requestor" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.requestor[*].id) - tags = var.requestor_route_table_tags -} - -data "aws_route_tables" "acceptor" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.acceptor[*].id) - tags = var.acceptor_route_table_tags -} - -locals { - requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ - for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block - ], var.requestor_ignore_cidrs)) : [] - acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ - for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block - ], var.acceptor_ignore_cidrs)) : [] -} - -# Create routes from requestor to acceptor -resource "aws_route" "requestor" { - count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 - route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) - destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] - vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) - depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default] -} - -# Create routes from acceptor to requestor -resource "aws_route" "acceptor" { - count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 - route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) - destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] - vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) - depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default] -} diff --git a/.history/main_20250603161747.tf b/.history/main_20250603161747.tf deleted file mode 100644 index da35057..0000000 --- a/.history/main_20250603161747.tf +++ /dev/null @@ -1,79 +0,0 @@ -resource "aws_vpc_peering_connection" "default" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.requestor[*].id) - peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) - - auto_accept = var.auto_accept - - accepter { - 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 - } - - tags = module.this.tags - - timeouts { - create = var.create_timeout - update = var.update_timeout - delete = var.delete_timeout - } -} - -# Lookup requestor VPC so that we can reference the CIDR -data "aws_vpc" "requestor" { - count = module.this.enabled ? 1 : 0 - id = var.requestor_vpc_id - tags = var.requestor_vpc_tags -} - -# Lookup acceptor VPC so that we can reference the CIDR -data "aws_vpc" "acceptor" { - provider = aws.acceptor - count = module.this.enabled ? 1 : 0 - id = var.acceptor_vpc_id - tags = var.acceptor_vpc_tags -} - -data "aws_route_tables" "requestor" { - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.requestor[*].id) - tags = var.requestor_route_table_tags -} - -data "aws_route_tables" "acceptor" { - provider = aws.acceptor - count = module.this.enabled ? 1 : 0 - vpc_id = join("", data.aws_vpc.acceptor[*].id) - tags = var.acceptor_route_table_tags -} - -locals { - requestor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ - for k, v in data.aws_vpc.requestor[0].cidr_block_associations : v.cidr_block - ], var.requestor_ignore_cidrs)) : [] - acceptor_cidr_blocks = module.this.enabled ? tolist(setsubtract([ - for k, v in data.aws_vpc.acceptor[0].cidr_block_associations : v.cidr_block - ], var.acceptor_ignore_cidrs)) : [] -} - -# Create routes from requestor to acceptor -resource "aws_route" "requestor" { - count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 - route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) - destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] - vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) - depends_on = [data.aws_route_tables.requestor, aws_vpc_peering_connection.default] -} - -# Create routes from acceptor to requestor -resource "aws_route" "acceptor" { - provider = aws.acceptor - count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.acceptor[0].ids))) * length(local.requestor_cidr_blocks) : 0 - route_table_id = element(distinct(sort(data.aws_route_tables.acceptor[0].ids)), ceil(count.index / length(local.requestor_cidr_blocks))) - destination_cidr_block = local.requestor_cidr_blocks[count.index % length(local.requestor_cidr_blocks)] - vpc_peering_connection_id = join("", aws_vpc_peering_connection.default[*].id) - depends_on = [data.aws_route_tables.acceptor, aws_vpc_peering_connection.default] -} diff --git a/.history/variables_20250603161025.tf b/.history/variables_20250603161025.tf deleted file mode 100644 index c53135b..0000000 --- a/.history/variables_20250603161025.tf +++ /dev/null @@ -1,83 +0,0 @@ -variable "requestor_vpc_id" { - type = string - description = "Requestor VPC ID" - default = "" -} - -variable "requestor_vpc_tags" { - type = map(string) - description = "Requestor VPC tags" - default = {} -} - -variable "requestor_route_table_tags" { - type = map(string) - description = "Only add peer routes to requestor VPC route tables matching these tags" - default = {} -} - -variable "acceptor_vpc_id" { - type = string - description = "Acceptor VPC ID" - default = "" -} - -variable "acceptor_vpc_tags" { - type = map(string) - description = "Acceptor VPC tags" - default = {} -} - -variable "acceptor_route_table_tags" { - type = map(string) - description = "Only add peer routes to acceptor VPC route tables matching these tags" - default = {} -} - -variable "auto_accept" { - type = bool - default = true - description = "Automatically accept the peering (both VPCs need to be in the same AWS account)" -} - -variable "acceptor_allow_remote_vpc_dns_resolution" { - type = bool - default = true - description = "Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC" -} - -variable "requestor_allow_remote_vpc_dns_resolution" { - type = bool - default = true - description = "Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC" -} - -variable "create_timeout" { - type = string - description = "VPC peering connection create timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" - default = "3m" -} - -variable "update_timeout" { - type = string - description = "VPC peering connection update timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" - default = "3m" -} - -variable "delete_timeout" { - type = string - description = "VPC peering connection delete timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" - default = "5m" -} - -variable "requestor_ignore_cidrs" { - type = list(string) - description = "A list of CIDR blocks from the requestor VPC to ignore" - default = [] -} - -variable "acceptor_ignore_cidrs" { - type = list(string) - description = "A list of CIDR blocks from the acceptor VPC to ignore" - default = [] -} diff --git a/.history/variables_20250603161909.tf b/.history/variables_20250603161909.tf deleted file mode 100644 index c53135b..0000000 --- a/.history/variables_20250603161909.tf +++ /dev/null @@ -1,83 +0,0 @@ -variable "requestor_vpc_id" { - type = string - description = "Requestor VPC ID" - default = "" -} - -variable "requestor_vpc_tags" { - type = map(string) - description = "Requestor VPC tags" - default = {} -} - -variable "requestor_route_table_tags" { - type = map(string) - description = "Only add peer routes to requestor VPC route tables matching these tags" - default = {} -} - -variable "acceptor_vpc_id" { - type = string - description = "Acceptor VPC ID" - default = "" -} - -variable "acceptor_vpc_tags" { - type = map(string) - description = "Acceptor VPC tags" - default = {} -} - -variable "acceptor_route_table_tags" { - type = map(string) - description = "Only add peer routes to acceptor VPC route tables matching these tags" - default = {} -} - -variable "auto_accept" { - type = bool - default = true - description = "Automatically accept the peering (both VPCs need to be in the same AWS account)" -} - -variable "acceptor_allow_remote_vpc_dns_resolution" { - type = bool - default = true - description = "Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC" -} - -variable "requestor_allow_remote_vpc_dns_resolution" { - type = bool - default = true - description = "Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC" -} - -variable "create_timeout" { - type = string - description = "VPC peering connection create timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" - default = "3m" -} - -variable "update_timeout" { - type = string - description = "VPC peering connection update timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" - default = "3m" -} - -variable "delete_timeout" { - type = string - description = "VPC peering connection delete timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts" - default = "5m" -} - -variable "requestor_ignore_cidrs" { - type = list(string) - description = "A list of CIDR blocks from the requestor VPC to ignore" - default = [] -} - -variable "acceptor_ignore_cidrs" { - type = list(string) - description = "A list of CIDR blocks from the acceptor VPC to ignore" - default = [] -} diff --git a/.history/versions_20250603161025.tf b/.history/versions_20250603161025.tf deleted file mode 100644 index 29ec41d..0000000 --- a/.history/versions_20250603161025.tf +++ /dev/null @@ -1,10 +0,0 @@ -terraform { - required_version = ">= 1.3" - - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 5.0" - } - } -} diff --git a/.history/versions_20250603161409.tf b/.history/versions_20250603161409.tf deleted file mode 100644 index 7480818..0000000 --- a/.history/versions_20250603161409.tf +++ /dev/null @@ -1,11 +0,0 @@ -terraform { - required_version = ">= 1.3" - - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 5.0" - configuration_aliases = [ aws.acceptor ] - } - } -} diff --git a/.history/versions_20250603161437.tf b/.history/versions_20250603161437.tf deleted file mode 100644 index 59a7c9a..0000000 --- a/.history/versions_20250603161437.tf +++ /dev/null @@ -1,11 +0,0 @@ -terraform { - required_version = ">= 1.3" - - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 5.0" - configuration_aliases = [ aws.acceptor ] - } - } -} \ No newline at end of file diff --git a/.history/versions_20250603161445.tf b/.history/versions_20250603161445.tf deleted file mode 100644 index 7480818..0000000 --- a/.history/versions_20250603161445.tf +++ /dev/null @@ -1,11 +0,0 @@ -terraform { - required_version = ">= 1.3" - - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 5.0" - configuration_aliases = [ aws.acceptor ] - } - } -} diff --git a/.history/versions_20250603161547.tf b/.history/versions_20250603161547.tf deleted file mode 100644 index 7480818..0000000 --- a/.history/versions_20250603161547.tf +++ /dev/null @@ -1,11 +0,0 @@ -terraform { - required_version = ">= 1.3" - - required_providers { - aws = { - source = "hashicorp/aws" - version = ">= 5.0" - configuration_aliases = [ aws.acceptor ] - } - } -} From 1df33d16b232b5d2be06e65e7ee8a6ac8bab5b0c Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Tue, 3 Jun 2025 16:20:02 -0400 Subject: [PATCH 03/12] try this --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 082b194..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "makefile.configureOnOpen": false -} \ No newline at end of file From 9c7eed11713681383786092aa9ce3e971d2ba37c Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Tue, 3 Jun 2025 16:20:26 -0400 Subject: [PATCH 04/12] try this --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index a5ecc30..c95edfb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,7 @@ .build-harness build-harness/ + +# IDE files +.vscode +.history From 6b262237bc97bb87ed86d489b7142bf52ac1f7d7 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 13:59:39 -0400 Subject: [PATCH 05/12] alias both aws providers --- main.tf | 4 ++++ versions.tf | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index da35057..596df2f 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,5 @@ resource "aws_vpc_peering_connection" "default" { + provider = aws.requestor count = module.this.enabled ? 1 : 0 vpc_id = join("", data.aws_vpc.requestor[*].id) peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) @@ -24,6 +25,7 @@ resource "aws_vpc_peering_connection" "default" { # Lookup requestor VPC so that we can reference the CIDR data "aws_vpc" "requestor" { + provider = aws.requestor count = module.this.enabled ? 1 : 0 id = var.requestor_vpc_id tags = var.requestor_vpc_tags @@ -38,6 +40,7 @@ data "aws_vpc" "acceptor" { } data "aws_route_tables" "requestor" { + provider = aws.requestor count = module.this.enabled ? 1 : 0 vpc_id = join("", data.aws_vpc.requestor[*].id) tags = var.requestor_route_table_tags @@ -61,6 +64,7 @@ locals { # Create routes from requestor to acceptor resource "aws_route" "requestor" { + provider = aws.requestor count = module.this.enabled ? length(distinct(sort(data.aws_route_tables.requestor[0].ids))) * length(local.acceptor_cidr_blocks) : 0 route_table_id = element(distinct(sort(data.aws_route_tables.requestor[0].ids)), ceil(count.index / length(local.acceptor_cidr_blocks))) destination_cidr_block = local.acceptor_cidr_blocks[count.index % length(local.acceptor_cidr_blocks)] diff --git a/versions.tf b/versions.tf index 7480818..1c18412 100644 --- a/versions.tf +++ b/versions.tf @@ -5,7 +5,7 @@ terraform { aws = { source = "hashicorp/aws" version = ">= 5.0" - configuration_aliases = [ aws.acceptor ] + configuration_aliases = [ aws.requestor, aws.acceptor ] } } } From 533ef44c8ebb9a4dda5b11c8454bcff9f0e75d45 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 14:56:47 -0400 Subject: [PATCH 06/12] fixing the pcx --- main.tf | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 596df2f..976412a 100644 --- a/main.tf +++ b/main.tf @@ -3,8 +3,9 @@ resource "aws_vpc_peering_connection" "default" { count = module.this.enabled ? 1 : 0 vpc_id = join("", data.aws_vpc.requestor[*].id) peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) - - auto_accept = var.auto_accept + peer_owner_id = data.aws_caller_identity.requestor.account_id + peer_region = data.aws_region.requestor.name + auto_accept = false accepter { allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution @@ -23,6 +24,23 @@ resource "aws_vpc_peering_connection" "default" { } } +# Accepter's side of the connection. +resource "aws_vpc_peering_connection_accepter" "default" { + provider = aws.acceptor + vpc_peering_connection_id = aws_vpc_peering_connection.default.id + auto_accept = true + + tags = var.acceptor_vpc_tags +} + +data "aws_region" "requestor" { + provider = aws.requestor +} + +data "aws_caller_identity" "requestor" { + provider = aws.requestor +} + # Lookup requestor VPC so that we can reference the CIDR data "aws_vpc" "requestor" { provider = aws.requestor From 3e99d2de04fc46d3cf8b8a64acde52d37982c404 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 15:04:02 -0400 Subject: [PATCH 07/12] fixing the pcx --- main.tf | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 976412a..9d2d629 100644 --- a/main.tf +++ b/main.tf @@ -3,8 +3,8 @@ resource "aws_vpc_peering_connection" "default" { count = module.this.enabled ? 1 : 0 vpc_id = join("", data.aws_vpc.requestor[*].id) peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) - peer_owner_id = data.aws_caller_identity.requestor.account_id - peer_region = data.aws_region.requestor.name + peer_owner_id = data.aws_caller_identity.requestor[0].account_id + peer_region = data.aws_region.requestor[0].name auto_accept = false accepter { @@ -27,17 +27,20 @@ resource "aws_vpc_peering_connection" "default" { # Accepter's side of the connection. resource "aws_vpc_peering_connection_accepter" "default" { provider = aws.acceptor - vpc_peering_connection_id = aws_vpc_peering_connection.default.id + count = module.this.enabled ? 1 : 0 + vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id auto_accept = true tags = var.acceptor_vpc_tags } data "aws_region" "requestor" { + count = module.this.enabled ? 1 : 0 provider = aws.requestor } data "aws_caller_identity" "requestor" { + count = module.this.enabled ? 1 : 0 provider = aws.requestor } From 0cf06f138e28f5223cb944388a55a2d985e62721 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 15:10:31 -0400 Subject: [PATCH 08/12] fixing the pcx --- main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 9d2d629..fe362fc 100644 --- a/main.tf +++ b/main.tf @@ -3,8 +3,8 @@ resource "aws_vpc_peering_connection" "default" { count = module.this.enabled ? 1 : 0 vpc_id = join("", data.aws_vpc.requestor[*].id) peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) - peer_owner_id = data.aws_caller_identity.requestor[0].account_id - peer_region = data.aws_region.requestor[0].name + peer_owner_id = data.aws_caller_identity.acceptor[0].account_id + peer_region = data.aws_region.acceptor[0].name auto_accept = false accepter { @@ -34,14 +34,14 @@ resource "aws_vpc_peering_connection_accepter" "default" { tags = var.acceptor_vpc_tags } -data "aws_region" "requestor" { +data "aws_region" "acceptor" { count = module.this.enabled ? 1 : 0 - provider = aws.requestor + provider = aws.acceptor } -data "aws_caller_identity" "requestor" { +data "aws_caller_identity" "acceptor" { count = module.this.enabled ? 1 : 0 - provider = aws.requestor + provider = aws.acceptor } # Lookup requestor VPC so that we can reference the CIDR From d11f499c41521b0c0bd38741eb918420421899ef Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 15:30:51 -0400 Subject: [PATCH 09/12] fixing the pcx --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index fe362fc..45cd945 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ resource "aws_vpc_peering_connection" "default" { peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) peer_owner_id = data.aws_caller_identity.acceptor[0].account_id peer_region = data.aws_region.acceptor[0].name - auto_accept = false + auto_accept = var.auto_accept accepter { allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution @@ -29,7 +29,7 @@ resource "aws_vpc_peering_connection_accepter" "default" { provider = aws.acceptor count = module.this.enabled ? 1 : 0 vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id - auto_accept = true + auto_accept = var.auto_accept tags = var.acceptor_vpc_tags } From 61ded73f792b3aa7e0ee0f1007aa901ec7aad31d Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 15:41:36 -0400 Subject: [PATCH 10/12] fixing the pcx --- main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 45cd945..8426418 100644 --- a/main.tf +++ b/main.tf @@ -5,11 +5,7 @@ resource "aws_vpc_peering_connection" "default" { peer_vpc_id = join("", data.aws_vpc.acceptor[*].id) peer_owner_id = data.aws_caller_identity.acceptor[0].account_id peer_region = data.aws_region.acceptor[0].name - auto_accept = var.auto_accept - - accepter { - allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution - } + auto_accept = false requester { allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution @@ -31,7 +27,11 @@ resource "aws_vpc_peering_connection_accepter" "default" { vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id auto_accept = var.auto_accept - tags = var.acceptor_vpc_tags + accepter { + allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution + } + + tags = module.this.tags } data "aws_region" "acceptor" { From 448fee16340d9009d79c91ec833410d2d99b3651 Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 15:52:14 -0400 Subject: [PATCH 11/12] fixing the pcx --- main.tf | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/main.tf b/main.tf index 8426418..456358a 100644 --- a/main.tf +++ b/main.tf @@ -7,10 +7,6 @@ resource "aws_vpc_peering_connection" "default" { peer_region = data.aws_region.acceptor[0].name auto_accept = false - requester { - allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution - } - tags = module.this.tags timeouts { @@ -20,16 +16,28 @@ resource "aws_vpc_peering_connection" "default" { } } -# Accepter's side of the connection. -resource "aws_vpc_peering_connection_accepter" "default" { - provider = aws.acceptor +# Options must be added after PCX is active +resource "aws_vpc_peering_connection_options" "default" { + provider = aws.requestor count = module.this.enabled ? 1 : 0 vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id - auto_accept = var.auto_accept + + requester { + allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution + } accepter { allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution } + depends_on = [aws_vpc_peering_connection_accepter.default] +} + +# Accepter's side of the connection. +resource "aws_vpc_peering_connection_accepter" "default" { + provider = aws.acceptor + count = module.this.enabled ? 1 : 0 + vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id + auto_accept = var.auto_accept tags = module.this.tags } From 6839ebc223dc07238fc2316eab39295e6bafa64d Mon Sep 17 00:00:00 2001 From: Eric Thompson Date: Wed, 4 Jun 2025 15:58:30 -0400 Subject: [PATCH 12/12] fixing the pcx --- main.tf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 456358a..aec7486 100644 --- a/main.tf +++ b/main.tf @@ -26,9 +26,6 @@ resource "aws_vpc_peering_connection_options" "default" { allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution } - accepter { - allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution - } depends_on = [aws_vpc_peering_connection_accepter.default] } @@ -39,6 +36,10 @@ resource "aws_vpc_peering_connection_accepter" "default" { vpc_peering_connection_id = aws_vpc_peering_connection.default[0].id auto_accept = var.auto_accept + accepter { + allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution + } + tags = module.this.tags }