![Terraform azurerm_network_interface-我做错了什么?](https://linux22.com/image/712604/Terraform%20azurerm_network_interface-%E6%88%91%E5%81%9A%E9%94%99%E4%BA%86%E4%BB%80%E4%B9%88%EF%BC%9F.png)
使用 terraform 构建一组 azure vms;无论如何都无法找出这个错误。我迷失在一个充满曲折通道的迷宫中……
此代码会产生以下错误。看上去没有错,但实际上有错。
resource "azurerm_virtual_network" "TW-PROD-AZR-NETDB-network" {
name = "TW-PROD-AZR-NETDB-Network"
address_space = ["10.240.0.0/16"]
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.TW-PROD-AZR-NETDB.name}"
resource "azurerm_subnet" "TW-PROD-AZR-NETDB-subnet1-private" {
name = "TW-PROD-AZR-NETDB-subnet1-private"
resource_group_name = "${azurerm_resource_group.TW-PROD-AZR-NETDB.name}"
virutal_network_name = "${azurerm_virtual_network.TW-PROD-AZR-NETDB-network.name}"
address_prefix = "10.240.1.0/24"
}
# Create VNIC DB01
resource "azurerm_network_interface" "TW-PROD-AZR-DB01-NIC01" {
name = "TW-PROD-AZR-DB01-NIC01"
location = "${var.location}"
resource_group_name = "TW-PROD-AZR-NETD"
network_security_group_id = "${azurerm_network_security_group.TW-PROD-AZRDB-SG.id}"
ip_configuration {
name = "TW-PROD-AZR-DB01-NIC01-CONFIG"
subnet_id = "${azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "TW-PROD-AZR-DB01-IP"
}
tags {
Env = "Production"
Group = "NETDB"
}
}
资源“azurerm_network_interface.TW-PROD-AZR-DB01-NIC01”配置:变量 azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private.id 中引用的未知资源“azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private”
答案1
你的 tf 文件中有两个错误。
1.最后资源azurerm_virtual_network
丢失。}
2.资源azurerm_subnet
中vir ut
al_network_name错误,应为vir tu
al_network_name。
以下 tf 文件对我有用。注意:为了方便测试,我删除了 NSG 和公共 IP。
resource "azurerm_virtual_network" "TW-PROD-AZR-NETDB-network" {
name = "TW-PROD-AZR-NETDB-Network"
address_space = ["10.240.0.0/16"]
location = "West US"
resource_group_name = "TW-PROD-AZR-NETD"
}
resource "azurerm_subnet" "TW-PROD-AZR-NETDB-subnet1-private" {
name = "TW-PROD-AZR-NETDB-subnet1-private"
resource_group_name = "TW-PROD-AZR-NETD"
virtual_network_name = "${azurerm_virtual_network.TW-PROD-AZR-NETDB-network.name}"
address_prefix = "10.240.1.0/24"
}
# Create VNIC DB01
resource "azurerm_network_interface" "TW-PROD-AZR-DB01-NIC01" {
name = "TW-PROD-AZR-DB01-NIC01"
location = "West US"
resource_group_name = "TW-PROD-AZR-NETD"
ip_configuration {
name = "TW-PROD-AZR-DB01-NIC01-CONFIG"
subnet_id = "${azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private.id}"
private_ip_address_allocation = "dynamic"
}
tags {
Env = "Production"
Group = "TW-PROD-AZR-NETD"
}
}
如果您使用比较工具,您将清楚地看到差异。