0
votes

In Terraform, I want to create a route table for an existing subnet. To achieve the desired end result, I need to pull the CIDR/Prefix for the VNET. The VNET CIDR value is not known beforehand, the only values I know before launch is the VNET's name and Resource Group.

I would like to take the VNET CIDR/Prefix and insert it as a destination in the route table.

data "azurerm_virtual_network" "vnet" {
  name                 = "${var.vnet_name}"
  resource_group_name  = "${var.vnet_rg}"
}

module "routetable" {
  source                  = "modules/routetable"
  route_table_name        = "${var.route_table_name}"
  resource_group_name     = 
"${data.azurerm_resource_group.vnet.name}"
  location                = "eastus"
  route_prefixes          = ["0.0.0.0/0", "${EXISTING_VNET_CIDR_HERE}"]


  route_nexthop_types     = ["VirtualAppliance", "VirtualAppliance"]
  route_names             = ["route1", "route2"]
}
1

1 Answers

2
votes

just use data you are getting from the vnet:

${data.azurerm_virtual_network.vnet.address_spaces}

the only issue - assress_spaces is an array (i think its called list in terraforms terms).