I am trying to create a tgw vpc attachments, but how ever i am not able to get the vpc_id and subnet_ids from the output. Below are the tfs:
main.tf
providers = {
aws = aws.generic
}
source = "terraform-aws-modules/vpc/aws"
for_each = local.vars.vpcs
name = each.value.name
cidr = each.value.cidr
azs = ["${data.aws_region.region.name}a", "${data.aws_region.region.name}b", "${data.aws_region.region.name}c"]
private_subnets = each.value.private_subnets
public_subnets = each.value.public_subnets
intra_subnets = each.value.intra_subnets
private_subnet_names = ["${each.value.name}-Private 1A", "${each.value.name}-Private 1B", "${each.value.name}-Private 1C"]
public_subnet_names = ["${each.value.name}-Public 1A", "${each.value.name}-Public 1B", "${each.value.name}-Public 1C"]
database_subnet_names = ["${each.value.name}-Transit 1A", "${each.value.name}-Transit 1B", "${each.value.name}-Transit 1C"]
enable_nat_gateway = true
single_nat_gateway = true
one_nat_gateway_per_az = false
}
output.tf
output "vpc_ids" {
value = tomap({
for k, vpc in module.us-east-2 : k => vpc.vpc_id
})
}
output "private_subnets" {
value = tomap({
for k, vpc in module.us-east-2 : k => vpc.private-subnets
})
}
tgw-attachement.tf
module "tgw" {
providers = {
aws = aws.generic
}
create_tgw = local.vars.create_tgw
share_tgw = "false"
source = "terraform-aws-modules/transit-gateway/aws"
vpc_attachments = {
vpc = {
tgw_id = "tgw-0b6fb46d17e2952d2"
vpc_id = < vpc_id >
subnet_ids = < private_subnets>
dns_support = true
}
}
}
terraform output result:
Changes to Outputs:
+ private_subnets = {
+ vpc-dev = [
+ (known after apply),
+ (known after apply),
+ (known after apply),
]
+ vpc-ops = [
+ (known after apply),
+ (known after apply),
+ (known after apply),
]
+ vpc-staging = [
+ (known after apply),
+ (known after apply),
+ (known after apply),
]
}
+ vpc_ids = {
+ vpc-dev = (known after apply)
+ vpc-ops = (known after apply)
+ vpc-staging = (known after apply)
}
I needed to create 3 tgw attachment with each vpc_id and private_subnets. How can i call the value in tgw-attachment.tf