gpt4 book ai didi

azure - 在 Azure 中创建多个具有不同配置的 VM

转载 作者:行者123 更新时间:2023-12-03 04:01:58 27 4
gpt4 key购买 nike

我想在 Azure 中使用 terraform 创建两个虚拟机。我已经配置了两个“azurerm_network_interface”,但是当我尝试应用更改时,我收到错误。你有什么主意吗?如果我尝试在不同区域创建它们会出现问题吗?

错误类似于:找不到 vm2-nic azurerm_network_interface

# Configure the Azure Provider
provider "azurerm" {
subscription_id = var.subscription_id
tenant_id = var.tenant_id
version = "=2.10.0"
features {}
}

resource "azurerm_virtual_network" "main" {
name = "north-network"
address_space = ["10.0.0.0/16"]
location = "North Europe"
resource_group_name = var.azurerm_resource_group_name
}

resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = var.azurerm_resource_group_name
virtual_network_name = azurerm_virtual_network.main.name
address_prefix = "10.0.2.0/24"
}

resource "azurerm_public_ip" "example" {
name = "test-pip"
location = "North Europe"
resource_group_name = var.azurerm_resource_group_name
allocation_method = "Static"
idle_timeout_in_minutes = 30

tags = {
environment = "dev01"
}
}

resource "azurerm_network_interface" "main" {
for_each = var.locations
name = "${each.key}-nic"
location = "${each.value}"
resource_group_name = var.azurerm_resource_group_name

ip_configuration {
name = "testconfiguration1"
subnet_id = azurerm_subnet.internal.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.example.id
}
}

resource "azurerm_virtual_machine" "main" {
for_each = var.locations
name = "${each.key}t-vm"
location = "${each.value}"
resource_group_name = var.azurerm_resource_group_name
network_interface_ids = [azurerm_network_interface.main[each.key].id]
vm_size = "Standard_D2s_v3"
...

错误:

Error: Error creating Network Interface "vm2-nic" (Resource Group "candidate-d7f5a2-rg"): network.InterfacesClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidResourceReference" Message="Resource /subscriptions/xxxxxxx/resourceGroups/xxxx/providers/Microsoft.Network/virtualNetworks/north-network/subnets/internal referenced by resource /subscriptions/xxxxx/resourceGroups/xxxxx/providers/Microsoft.Network/networkInterfaces/vm2-nic was not found. Please make sure that the referenced resource exists, and that both resources are in the same region." Details=[]

on environment.tf line 47, in resource "azurerm_network_interface" "main":
47: resource "azurerm_network_interface" "main" {

最佳答案

根据文档,附加到 VM 的每个 NIC 必须位于与 VM 相同的位置(区域)和订阅中。 https://learn.microsoft.com/en-us/azure/virtual-machines/windows/network-overview .

如果您可以在与 VM 相同的位置重新创建 NIC,或者在与 NIC 相同的位置创建 VM,则可能会解决您的问题。

关于azure - 在 Azure 中创建多个具有不同配置的 VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61909945/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com