-1

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

Vasily Pozdeev
  • 239
  • 2
  • 7
  • 2
    Like this: `resource.aws_vpn_connection.example.local_ipv4_network_cidr`. Make sure you read and understand this: https://developer.hashicorp.com/terraform/language/expressions/references#resources. – Marko E Dec 16 '22 at 12:47
  • @MarkoE, oh, so ALL arguments are exported by default?? omg)) that's a game-changer. Thanks! – Vasily Pozdeev Dec 16 '22 at 12:50
  • Yup, so all the arguments are accessible plus some attributes. :) When reading the documentation it usually says `In addition to all arguments above, the following attributes are exported:`. On the right hand side of the docs you have `Argument Reference` and `Attribute Reference`: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpn_connection#attributes-reference. – Marko E Dec 16 '22 at 12:53

1 Answers1

0

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
Vasily Pozdeev
  • 239
  • 2
  • 7