grem11n / terraform-aws-vpc-peering

Terraform module to setup VPC peering connection
https://registry.terraform.io/modules/grem11n/vpc-peering/aws/latest
Apache License 2.0
126 stars 91 forks source link

[BUG] Module fails when subnet with unassociated rt is specified in (this|peer)_subnet_ids variable #108

Open herrbpl opened 11 months ago

herrbpl commented 11 months ago

Describe the bug When user specifies any subnet that is not associated with route table in vpc as value in variables:

then module is unable to find route tables for these subnets and fails to peer vpcs

Terraform version: 1.5.6

Module version: 6.0.0

Error message:

Error: query returned no results. Please change your search criteria and try again
│ 
│   with module.partial_subnets.data.aws_route_table.peer_subnet_rts[0],

Terraform code that produces the error:

module "partial_subnets" {

  source  = "../../"
  #version = "6.0.0"

  providers = {
    aws.this = aws.this
    aws.peer = aws.peer
  }

  this_vpc_id = var.this_vpc_id
  peer_vpc_id = var.peer_vpc_id

  auto_accept_peering = true
  peer_dns_resolution = true
  this_dns_resolution = true  
  peer_subnets_ids = ["subnet-unassociated-with-any-rt", "subnet-associated-with-rt-x"]
  this_subnets_ids = var.this_subnets_ids
  this_rts_ids = var.this_rts_ids
  peer_rts_ids = ["peer_main_rt", "peer_rt-x"]

  tags = {
    Name        = "tf-partial-subnets"
    Environment = "Test"
  }

}

Additional context Will provide a fix via PR