Hi there,
Appreciate any help I can get to understand what’s going wrong here.
So, this is what I have - a child-module, called vpc
and there I’m doing a TGW vpc_attachment
:
child-module: modules/vpc/tgw.tf
##---- Transit Gateway VPC Attachments ---------####
resource "aws_ec2_transit_gateway_vpc_attachment" "default" {
count = length(var.s_zones)
vpc_id = element(aws_vpc.vpcs[*].id, count.index)
subnet_ids = data.aws_subnet_ids.tgw[count.index].ids
transit_gateway_id = var.tgw_id
transit_gateway_default_route_table_association = var.tgw_auto_association
transit_gateway_default_route_table_propagation = var.tgw_auto_association
}
In the root-module directory, I have a data.tf
to get the already running TransitGateway (done by a completely separate plan) id
:
root-module: services/ENVS/data.tf
data "aws_ec2_transit_gateway" "tgwz" {
filter {
name = "options.amazon-side-asn"
values = ["4200064${substr(var.mgmt_ccenter,1,3)}"]
}
filter {
name = "state"
values = ["available"]
}
filter {
name ="tag:Name"
values = ["${var.mgmt_project}site-tgw"]
}
}
And that data is supplied as the tgw_id
in the vpc
root-module:
root-module: services/ENVS/vpc.tf
module "vpc" {
source = "../../modules/vpc"
......
......
tgw_auto_association = var.tgw_auto_association
tgw_id = data.aws_ec2_transit_gateway.tgwz.id
}
If I do a targeted (e.g. -target=module.vpc
) plan/apply , it fails with this:
Error: "transit_gateway_id": required field is not set
on ../../modules/vpc/tgw.tf line 2, in resource "aws_ec2_transit_gateway_vpc_attachment" "default":
3: resource "aws_ec2_transit_gateway_vpc_attachment" "default" {
Error: "transit_gateway_id": required field is not set
on ../../modules/vpc/tgw.tf line 2, in resource "aws_ec2_transit_gateway_vpc_attachment" "default":
3: resource "aws_ec2_transit_gateway_vpc_attachment" "default" {
But if run the full plan (i.e. without -target
) along with rest of my other stuff, it works just fine. What am I missing here? Why it cannot find the value for the tgw_id
when it’s run partially? Any help solving this would be really appreciated!
-S