How to get local_ipv4_network_cidr from aws_vpn_connection resource

150 Views Asked by At

I've created a site-2-site vpn in terraform:

resource "aws_vpn_connection" "example" {
  customer_gateway_id = # <cgw id>
  transit_gateway_id  = # <tgw id>

  outside_ip_address_type = "PublicIpv4"
  type                    = "ipsec.1"

  local_ipv4_network_cidr  = "192.168.0.0/18"
  remote_ipv4_network_cidr = "10.0.1.0/24"

  static_routes_only = false

}

Now I want to add a static route in TGW route table:

resource "aws_ec2_transit_gateway_route" "example_route" {
  transit_gateway_route_table_id = # <route table ID>

  destination_cidr_block        = "192.168.0.0/18" # how to replace THIS part with a reference to previous resource??
  transit_gateway_attachment_id = # <attachment ID>
}

I tried to use tolist(aws_vpn_connection.example.routes)[0].destination_cidr_block (as per terraform docs), but apparently it's empty

1

There are 1 best solutions below

0
On

okay, so apparently that was my misreading of terraform docs - it's not only attributes exported but also arguments. so, as Marko stated, I could use

aws_vpn_connection.example.local_ipv4_network_cidr