title: How to inherit/pass on variables in terraform
body: <p>I am pretty new with Terraform and having some issues with passing on variables between modules/ child directories.</p>
  
  <p>I have a structure like:</p>
  
  <pre><code>.
  |-- main.tf
  |-- variables.tf
  |-- terraform.tfvars
  |-- data.tf
  |-- compute
        |-- main.tf
        |-- variables.tf
        |-- terraform.tfvars
  |-- network
        |-- main.tf
        |-- variables.tf
        |-- terraform.tfvars
  </code></pre>
  
  <p>My main.tf in the root dir looks like this:</p>
  
  <pre><code>provider "azurerm" {
  }
  
  
  resource "azurerm_resource_group" "test" {
    name     = "${var.resourcegroup}"
    location = "${var.location}"
  
    tags {
      costcenter  = "costcenter_nr"
      environment = "test"
    }
  }
  
  resource "azurerm_virtual_network" "test" {
    name                = "${var.vnet}"
    location            = "${var.location}"
    resource_group_name = "${var.resourcegroup}"
    address_space       = ["10.102.2.0/23"]
  
    subnet {
      name           = "${var.subnet_agw}"
      address_prefix = "10.102.3.128/28"
    }
    depends_on = ["azurerm_resource_group.test"]
  }
  
  module "compute" {
    source = "./compute"
  }
  
  module "network" {
    source = "./network"
  }
  </code></pre>
  
  <p>In the network directory I want to create the network interfaces for the vm's. So the network interfaces depend on the subnet id. The vm's (I want to create with templates in compute) depend on the network interface id.</p>
  
  <p>In the data.tf in the root directory I output the subnet id:</p>
  
  <pre><code>data "azurerm_subnet" "agw" {
    name                 = "${var.subnet_agw}"
    virtual_network_name = "${var.vnet}"
    resource_group_name  = "${var.resourcegroup}"
  
    depends_on           = ["azurerm_virtual_network.test"]
  }
  
  output "subnet_ag" {
    value = "${data.azurerm_subnet.agw.id}"
  } 
  </code></pre>
  
  <p>How do I get to use that output/variable in network/main.tf so I can provision the network interface?</p>
  
  <p>network/main.tf would look like:</p>
  
  <pre><code>resource "azurerm_network_interface" "sql_server" {
    name                = "${var.sql_server}"
    location            = "${var.location}"
    resource_group_name = "${var.resourcegroup}"
  
    ip_configuration {
      name                          = "${var.sql_server}"
      subnet_id                     = "${????????}"
      private_ip_address_allocation = "dynamic"
    }
      depends_on = ["azurerm_resource_group.test"]
  }
  </code></pre>
  
  <p>Plus, will this dependency work since the dependency is created by the main.tf?!</p>