azure - terraform network_interface_ids - 属性值不合适

标签 azure terraform terraform-provider-azure

我正在尝试将“azurerm_virtual_machine”中的“network_interface_ids”设置为我的模块之一的输出,但在“terraform plan”期间收到以下错误,并且无法弄清楚我哪里出错了:

│ Error: Incorrect attribute value type
│ 
│   on modules/virtualmachine/main.tf line 6, in resource "azurerm_virtual_machine" "vm":
│    6:   network_interface_ids             = [var.nicid]
│     ├────────────────
│     │ var.nicid is a list of string, known only after apply
│ 
│ Inappropriate value for attribute "network_interface_ids": element 0:
│ string required.
╵
##[error]Bash exited with code '1'.

我确信这很简单,我让它可以工作而无需拆分成模块,只是不太明白。我已附上下面的所有相关代码(显然删除了大量代码以帮助简洁):

main.tf

  module "virtualmachine" {
  source                   = "./modules/virtualmachine"
  nicid                    = module.networking.nicidoutput
  }

模块/网络/main.tf

resource "azurerm_network_interface" "nic" {
  name                = var.nicname
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
}

模块/网络/outputs.tf

output "nicidoutput" {
    value = azurerm_network_interface.nic.id
}

模块/虚拟机/main.tf

  resource "azurerm_virtual_machine" "vm" {
  network_interface_ids             = [var.nicid]
  }

模块/虚拟机/variables.tf

variable "nicid" {
    type = list(string)
    description = "network interface id"
}

最佳答案

您的 var.nicid 已经是一个列表。所以应该是:

network_interface_ids             = var.nicid

更新:

还应在虚拟机中更改以下内容

nicid                    = [module.networking.nicidoutput] for virtualmachine

关于azure - terraform network_interface_ids - 属性值不合适,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71171249/

相关文章:

azure - Windows Azure 存储表连接超时

android - 使用 SAS(共享访问签名)通过 Azure 存储上传文件

azure - Terraform:无法使用 azurerm_lb_backend_address_pool 在 lb 后面创建虚拟机

azure - Terraform - 部署到多个azure订阅

azure - terraform application_security_group_ids 无效或未知 key

solr - 在 Azure 上运行 Solr

swift - Microsoft Azure移动SDK自定义提供商登录IOS

terraform - 无效的模板控制关键字

google-cloud-platform - 不正确的服务网络配置,例如 : xxxx:SERVICE_NETWORKING_NOT_ENABLED

azure - Terraform azurerm azurerm_data_factory_dataset_binary 参数定义