Hi, I am trying to setup a transit gateway for multiple vpc in different region. But I am not able to add the VPC of different region . As in below code the vpc1 and vpc2 are in the same region while vpc3 is in another region. The error is shown below. How can I resolve this issue.
Error message:
Error: no matching VPC found
on main.tf line 14, in data "aws_vpc" "vpc3":
14: data "aws_vpc" "vpc3" {
main.tf
data "aws_vpc" "vpc1" {
filter {
name = "tag:Name"
values = ["vpc1"]
}
}
data "aws_vpc" "vpc2" {
filter {
name = "tag:Name"
values = ["vpc2"]
}
}
data "aws_vpc" "vpc3" {
filter {
name = "tag:Name"
values = ["vpc3"]
}
}
data "aws_subnet_ids" "vpc1" {
vpc_id = data.aws_vpc.vpc1.id
}
data "aws_subnet_ids" "vpc2" {
vpc_id = data.aws_vpc.vpc2.id
}
data "aws_subnet_ids" "vpc3" {
vpc_id = data.aws_vpc.vpc3.id
}
module "tgw" {
source = "terraform-aws-modules/transit-gateway/aws"
version = "~> 2.0"
name = "my-tgw"
description = "My TGW shared with several other AWS accounts"
enable_auto_accept_shared_attachments = true
vpc_attachments = {
vpc1 = {
#vpc_id = module.vpc.vpc_id
vpc_id = data.aws_vpc.vpc1.id
subnet_ids = data.aws_subnet_ids.vpc1.ids
dns_support = true
ipv6_support = true
tgw_routes = [
{
destination_cidr_block = "10.0.0.0/8"
},
{
blackhole = true
destination_cidr_block = "0.0.0.0/0"
}
]
},
vpc2 = {
vpc_id = data.aws_vpc.vpc2.id
subnet_ids = data.aws_subnet_ids.vpc2.ids
dns_support = true
ipv6_support = true
tgw_routes = [
{
destination_cidr_block = "10.2.0.0/16"
},
{
blackhole = true
destination_cidr_block = "30.0.0.0/8"
}
]
},
vpc3 = {
vpc_id = data.aws_vpc.vpc3.id
subnet_ids = data.aws_subnet_ids.vpc3.ids
dns_support = true
ipv6_support = true
tgw_routes = [
{
destination_cidr_block = "10.3.0.0/16"
},
{
blackhole = true
destination_cidr_block = "40.0.0.0/8"
}
]
}
}
ram_allow_external_principals = true
ram_principals = [307990089504]
tags = {
Purpose = "tgw-complete-example"
}
}
providers.tf
provider "aws" {
region = "us-east-1"
}