通过索引访问模块的输出

时间:2017-07-25 21:53:16

标签: terraform

我正在尝试使用Terraform在Azure上创建2个VM。

我创建了2个像

这样的网卡
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)}"
    }
}

现在我想在模块azurerm_virtual_machine

中使用它们
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)}"
....
}

这给了我一个错误

  

无法加载root配置模块:加载azure / rg.tf时出错:错误   读取azurerm_virtual_machine的配置[helloterraformvm]:   azurerm_network_interface.helloterraformnic:资源变量必须   分为三部分:TYPE.NAME.ATTR in:

     

$ {element(azurerm_network_interface.helloterraformnic,count.index)}

如何使用索引来使用上面创建的网卡?

1 个答案:

答案 0 :(得分:1)

首先考虑使用count = 2 函数来获取计数而不是硬编码。

来自

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

更改为

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

对于您的问题,您需要告诉资源您想要获取值的属性。

Private Sub ContextMenuStrip1Items_Click(sender As Object, e As ToolStripItemClickedEventArgs)
    Select Case e.ClickedItem.Text


        Case "Colar", "Paste"
            Try
                ContextMenuStrip1.Close()
                Dim Formato As DataFormats.Format = Nothing

                If **Clipboard.ContainsImage** Then
                    Formato = DataFormats.GetFormat(DataFormats.Bitmap)
                    If RichTextBox1.CanPaste(Formato) Then
                        RichTextBox1.Paste(Formato)
                    End If**

                ElseIf Clipboard.ContainsText(TextDataFormat.Html) Then
                    Formato = DataFormats.GetFormat(DataFormats.Html)
                    If RichTextBox1.CanPaste(Formato) Then
                        RichTextBox1.Paste(Formato)
                    Else
                        RichTextBox1.Paste

                    End If

                ElseIf Clipboard.ContainsText(TextDataFormat.Rtf) Then
                    Formato = DataFormats.GetFormat(DataFormats.Rtf)
                    If RichTextBox1.CanPaste(Formato) Then
                        RichTextBox1.Paste(Formato)
                    Else
                        RichTextBox1.Paste
                    End If


                elseif clipboard.ContainsText
                    RichTextBox1.Paste


                Else
                    MsgBox("Formato não suportado")
                End If


            Catch ex As Exception
            End Try




        Case "Imagem", "Image"
            Using OFD As New OpenFileDialog
                With OFD
                    .Multiselect = False
                    .InitialDirectory = "C:\Documents"
                    .Filter = "Image files (*.Bmp, *.Gif, *.Jpg, *.Png, *.Tif)|*.Bmp;*.Gif;*.Jpg;*.Png;*.Tif"
                End With
                ContextMenuStrip1.Close()
                If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                    If OFD.FileName <> "" Then
                        Clipboard.SetImage(Image.FromFile(OFD.FileName))
                        RichTextBox1.Paste()
                    End If
                End If
            End Using

         End Case

End Sub

参考:

terraform Interpolation Syntax

terraform azurerm_virtual_machine Attributes Reference