EC2 Transit Gateway VPN Attachment

hi , I am creating a vpn attachment but i’m getting an error like this and i even add ec2 tag
ERROR Error: no matching EC2 Transit Gateway VPN Attachment found
` ERROR on vpn.tf line 55, in data “aws_ec2_transit_gateway_vpn_attachment” “vpn_attachment”:

Data block for VPN Attachment

data “aws_ec2_transit_gateway_vpn_attachment” “vpn_attachment” {
vpn_connection_id = aws_vpn_connection.vpn_connection.id
transit_gateway_id = aws_ec2_transit_gateway.transit_gateway.id
}

AWS EC2 Tag for VPN Attachment

resource “aws_ec2_tag” “vpn_attachment_tag” {
resource_id = aws_vpn_connection.vpn_connection.transit_gateway_attachment_id
key = “name”
value = “EC2 Transit Gateway VPN Attachment”
}

I’m getting this same error as well. My problem is I’m switching from a VGW to a TGW and Terraform seems to be getting confused.

Your configuration isn’t creating a VPN attachment but looking for one - that’s what a data source is for. If you look at the documentation for the aws_ec2_transit_gateway_vpn_attachment data source, there is a note that says that the VPN attachment is implicitly created when you provision your site-to-site VPN connection which referencing a Transit Gateway. In Terraform, this is done using the aws_vpn_connection resource and specifying the transit_gateway_id argument. The first example in the documentation is relevant to this use case.