2017-07-25 4 views
0

私はTerraformを使用してAzureで2つのVMを作成しようとしています。インデックスからモジュールの出力にアクセスする

私は

variable "internalips" { 
    description = "List of Internal IPs" 
    default = ["10.0.2.10", "10.0.2.11"] 
    type = "list" 
} 


resource "azurerm_network_interface" "helloterraformnic" { 
count = 2 
name = "nic-${count.index}" 
location = "West US" 
resource_group_name = "myrg" 

    ip_configuration { 
     name = "testconfiguration1" 
     subnet_id = "${azurerm_subnet.helloterraformsubnet.id}" 
     private_ip_address_allocation = "static" 
     private_ip_address = "${element(private_ip_address, count.index)}" 
    } 
} 

のような2枚のNIC今、私はこれは私にエラー

を与える

resource "azurerm_virtual_machine" "helloterraformvm" { 
    count = 2 
    name = "${element(elasticmachines, count.index)}" 
    location = "West US" 
    resource_group_name = "myrg" 
    network_interface_ids = "${element(azurerm_network_interface.helloterraformnic, count.index)}" 
.... 
} 

azurerm_virtual_machineモジュールでそれらを使用するには、ルート設定モジュールをロードできませんでした作成します。 azurerm_virtual_machine [helloterraformvm]の設定を読み込んでいる間にエラー が読み込まれました: azurerm_network_interface.helloterraformnic: 三つの部分でなければならないリソース変数:

$ {要素(azurerm_network_interface.helloterraformnic、count.index)}私が作成した上記を使用するにはどうすればよい

:中TYPE.NAME.ATTR NICはインデックスを使用していますか?

答えて

1

lengthを使用する最初の考えは、それをハードコーディングする以上の数を得るために機能します。

あなたの問題のために

count = "${length(var.internalips)}" 

count = 2 

変化に

から、あなたが値を取得したい属性のリソースを指示する必要があります。

network_interface_ids = "${element(azurerm_network_interface.helloterraformnic.id, count.index)}" 

参照してください:

terraform Interpolation Syntax

terraform azurerm_virtual_machine Attributes Reference

+0

感謝を。それが私の問題を解決しました。 – user1191140

関連する問題