title: Passing Terraform variables between Modules within Modules?
body: <p>I have an issue I have gotten stuck on building a module from the <a href="https://github.com/kubernetes-sigs/kubespray/tree/master/contrib/terraform/openstack" rel="nofollow noreferrer">Kubespray</a> project.</p>
  
  <p>I have the following folder structure:</p>
  
  <pre><code>terraform/
  modules/
     kubespray/
        modules/
           compute/
           ips/
           network/
        main.tf
        variables.tf
  roles/
      kubespray/
          terraform_setup/
               main.tf
  </code></pre>
  
  <p>Within the <code>kubespray/main.tf</code> module there are variables being passed around:</p>
  
  <pre><code>module "ips" {
    source = "./modules/ips"
  
    number_of_k8s_masters         = "${var.number_of_k8s_masters}"
    number_of_k8s_masters_no_etcd = "${var.number_of_k8s_masters_no_etcd}"
    number_of_k8s_nodes           = "${var.number_of_k8s_nodes}"
    floatingip_pool               = "${var.floatingip_pool}"
    number_of_bastions            = "${var.number_of_bastions}"
    external_net                  = "${var.external_net}"
    network_name                  = "${var.network_name}"
    router_id                     = "${module.network.router_id}"
  }
  
  module "compute" {
    source = "./modules/compute"
    ...
    k8s_master_fips                              = "${module.ips.k8s_master_fips}"
    k8s_master_no_etcd_fips                      = "${module.ips.k8s_master_no_etcd_fips}"
    k8s_node_fips                                = "${module.ips.k8s_node_fips}"
    bastion_fips                                 = "${module.ips.bastion_fips}"
    ...
  }
  output "private_subnet_id" {
    value = "${module.network.subnet_id}"
  }
  
  output "floating_network_id" {
    value = "${var.external_net}"
  }
  
  output "router_id" {
    value = "${module.network.router_id}"
  }
  
  output "k8s_master_fips" {
    value = "${concat(module.ips.k8s_master_fips, module.ips.k8s_master_no_etcd_fips)}"
  }
  
  output "k8s_node_fips" {
    value = "${module.ips.k8s_node_fips}"
  }
  
  output "bastion_fips" {
    value = "${module.ips.bastion_fips}"
  }
  </code></pre>
  
  <p>If I run my terraform init/apply from inside the submodule in <code>modules/kubespray/</code> It works fine</p>
  
  <p>If I run from my <code>role/kubespray</code> that has</p>
  
  <pre><code>module "kubespray" {
    source    = "../../../modules/kubespray"
    providers = {
      openstack.src = openstack
    }
  }
  </code></pre>
  
  <p>it fails with</p>
  
  <blockquote>
    <p>Error: Invalid index</p>
    
    <p>on ../../../modules/kubespray/modules/compute/main.tf line 670, in
    resource "openstack_compute_floatingip_associate_v2" "k8s_node":  670:
    floating_ip           = "${var.k8s_node_fips[count.index]}"
        |----------------
        | count.index is 0
        | var.k8s_node_fips is empty list of dynamic</p>
  </blockquote>
  
  <p>Help would be extremely appreicated</p>