[英]Unable to change an azure subnet using terraform
我是 terraform 的新手,想更改網絡上的子網,但遇到了一個奇怪的錯誤。 谷歌一無所獲。 這就是我要輸入的內容(在更改 main.tf 和運行計划之后)
`terraform apply -replace="azurerm_subnet.subnet1" Terraform 將執行以下操作:
# module.network.azurerm_subnet.subnet[0] will be updated in-place
~ resource "azurerm_subnet" "subnet" {
~ address_prefixes = [
- "10.0.2.0/24",
+ "10.0.4.0/24",
]
id =
"/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/lab-
resources/providers/Microsoft.Network/virtualNetworks/acctvnet/subnets/subnet1"
name = "subnet1"
# (7 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
` 我輸入是,我得到這個錯誤:
錯誤:更新子網:(名稱“subnet1”/虛擬網絡名稱“acctvnet”/資源組“lab-resources”):network.SubnetsClient#CreateOrUpdate:發送請求失敗:StatusCode=400 -- 原始錯誤:Code="InUseSubnetCannotBeUpdated" Message="子網subnet1 正在使用中,無法更新。" Details=[] │ │ 與 module.network.azurerm_subnet.subnet[0],│ on.terraform/modules/network/main.tf 第 15 行,資源“azurerm_subnet”“子網”:│ 15:資源“azurerm_subnet”“子網" { │
虛擬機已關閉,我看不出還有什么可以使用它。
我還嘗試使用 terraform 污點“azurerm_subnet.subnet1”
有任何想法嗎? 我正在做的事情是不可能的嗎?
這是我的 main.tf
terraform {
required_version = ">=0.12"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "lab_autodeploy" {
name = "lab-resources"
location = "East US 2"
}
module "Windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.lab_autodeploy.name
is_windows_image = true
vm_hostname = "new_ddc" // line can be removed if only one VM module per resource group
size = "Standard_F2"
admin_password = "$omePassw0rd"
vm_os_simple = "WindowsServer"
public_ip_dns = ["srv"] // change to a unique name per datacenter region
vnet_subnet_id = module.network.vnet_subnets[0]
depends_on = [azurerm_resource_group.lab_autodeploy]
}
module "network" {
source = "Azure/network/azurerm"
resource_group_name = azurerm_resource_group.lab_autodeploy.name
subnet_prefixes = ["10.4.0.0/24"]
subnet_names = ["subnet1"]
depends_on = [azurerm_resource_group.lab_autodeploy]
}
output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
這不是 Terraform 特有的問題 - 在 Azure 中,您無法更改附加了東西的子網。 關閉虛擬機電源這一事實沒有任何區別。
要在不破壞 VM 的情況下解決此問題,您可以將 NIC 移動到不同的子網(如有必要,創建一個臨時子網),執行地址空間更改,然后將 NIC 移回。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.