首次申请后未输出 Terraform Azure mac 地址

Terraform Azure mac address not being outputted after first apply

在 terraform plan 期间,我在 azurerm_network_interface.ni 下看到 mac_address: <computed>,但是当我尝试打印时,我得到空字符串。

output "mac" {
  value = "${azurerm_network_interface.ni.mac_address}"
}

输出

$ terraform apply

output
    mac =

当您只是创建网络接口而不使用它时,它不会有 MAC 地址。在 Note of creating the Network Interface 中查看:

Azure assigns a MAC address to the network interface only after the network interface is attached to a virtual machine and the virtual machine is started the first time.

如果想通过

输出Terraform中的MAC地址
azurerm_network_interface.ni.mac_address

您应该为它附加一个 VM 并至少启动 VM 一次。