Terraform, can a resource be passed as a variable into a module?

This is possible with terraform > 0.12. You can use the object type, butt you have to explicitly list fields that you use within your module.

# module's variables.tf
variable "parent_vnet" {
  # List each field in `azurerm_route_table` that your module will access
  type = object({
    name = string
    location = string
    resource_group_name = string
  })
} 

# caller
resource "azurerm_route_table" "my_parent_vnet" {
  # ...
}

module "my-module" {
  parent_vnet = azurerm_route_table.my_parent_vnet
}

Leave a Comment