Terraform引用(获取)subnet_id不在当前定义文件中

时间:2017-11-20 17:51:08

标签: terraform-provider-azure

我无法理解如何引用未在" current"中定义的子网。定义文件。

我有两个不同的定义文件,一个用于网络定义(文件A),另一个用于计算资源(文件B)。

如何引用文件B中文件A中定义的子网?

文件A 包含以下内容

    resource "azurerm_resource_group" "NetResourceGroup" {
      name     = "NetworkResources"
      location = "westeurope"
    }

    resource "azurerm_virtual_network" "vnet" {
      name                = "mainvnet"
      location            =     "${azurerm_resource_group.NetResourceGroup.location}"
      address_space       = ["10.0.0.0/16"]
      resource_group_name = "${azurerm_resource_group.NetResourceGroup.name}"
    }

    resource "azurerm_subnet" "dcsubnet" {
      name                 = "dcsubnet"
      virtual_network_name = "${azurerm_virtual_network.vnet.name}"
      resource_group_name  = "${azurerm_resource_group.NetResourceGroup.name}"
      address_prefix       = "10.0.1.0/24"
    }

    resource "azurerm_subnet" "sqlsubnet" {
      name                 = "sqlsubnet"
      virtual_network_name = "${azurerm_virtual_network.vnet.name}"
      resource_group_name  = "${azurerm_resource_group.NetResourceGroup.name}"
      address_prefix       = "10.0.2.0/24"
    }

文件B 包含以下内容:

    resource "azurerm_resource_group" "DCResourceGroup" {
      name     = "DomainControllerVMs"
      location = "westeurope"
    }

    resource "azurerm_storage_account" "DCStorageAccoount" {
      name                     = "domaincontrollersdisks"
      location                 = "${azurerm_resource_group.DCResourceGroup.location}"
      resource_group_name      = "${azurerm_resource_group.DCResourceGroup.name}"
      account_tier             = "Standard"
      account_replication_type = "LRS"
}

resource "azurerm_availability_set" "DCAvailabilitySet" {
      name                         = "dcsavailset"
      location                     = "${azurerm_resource_group.DCResourceGroup.location}"
      resource_group_name          = "${azurerm_resource_group.DCResourceGroup.name}"
      platform_fault_domain_count  = 2
      platform_update_domain_count = 2
      managed                      = true
    }

    resource "azurerm_network_interface" "dc1nic" {
      name                = "dcnic${count.index}"
      location            = "${azurerm_resource_group.DCResourceGroup.location}"
      resource_group_name = "${azurerm_resource_group.DCResourceGroup.name}"

      ip_configuration {
        name                                    = "ipconfig${count.index}"
        subnet_id                               = "${?????????}"
        private_ip_address_allocation           = "Dynamic"
      }
}

提前致谢

0 个答案:

没有答案