[英]Terraform azurerm provider fails with autorest:DoErrorUnlessStatusCode 400
我已經嘗試了多種配置,但它們似乎都不起作用。 我還嘗試了用我的Azure超級用戶運行terraform,該用戶可以對所有內容進行RW訪問,但仍然無法創建資源。
這是我的terraform配置和運行結果:
provider "azurerm" {
subscription_id = "xxxxxxxxxxxxxxxxxx"
client_id = "xxxxxxxxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxx"
tenant_id = "xxxxxxxxxxxxxxxxxxx"
}
resource "azurerm_resource_group" "1Demo" {
name = "1Demo"
location = "West US"
}
resource "azurerm_virtual_network" "network" {
name = "demoNetwork"
address_space = ["10.0.0.0/16"]
location = "West US"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
}
resource "azurerm_resource_group" "networkGroup" {
name = "demoNetworkGroup"
location = "West US"
}
resource "azurerm_storage_account" "test" {
name = "accsa"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
location = "westus"
account_type = "Standard_LRS"
tags {
environment = "staging"
}
}
resource "azurerm_storage_container" "test" {
name = "vhds"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
resource "azurerm_network_security_group" "demo" {
name = "demoSecurityGroup"
location = "West US"
resource_group_name = "${azurerm_resource_group.networkGroup.name}"
security_rule {
name = "default-allow-rdp"
priority = 1000
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "winrm"
priority = 1010
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "5985"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "winrm-out"
priority = 100
direction = "Outbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "5985"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
resource "azurerm_public_ip" "demoIP" {
name = "demoIPAddress"
location = "West US"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
public_ip_address_allocation = "static"
}
resource "azurerm_subnet" "demosubnet" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
virtual_network_name = "${azurerm_virtual_network.network.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "nicdemo" {
name = "nicdemo"
location = "West US"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
ip_configuration {
name = "ipconfiguration"
subnet_id = "${azurerm_subnet.demosubnet.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_virtual_machine" "terraformtest" {
name = "terraformtest"
location = "West US"
resource_group_name = "${azurerm_resource_group.1Demo.name}"
network_interface_ids = ["${azurerm_network_interface.nicdemo.id}"]
vm_size = "Standard_D1_V2"
storage_image_reference {
publisher = "MicrosoftWindowsServerHPCPack"
offer = "WindowsServerHPCPack"
sku = "2012R2"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "terraformtest"
admin_username = "adminadmin"
admin_password = "AdminAdmin123"
}
}
azurerm_resource_group.networkGroup: Refreshing state... (ID: /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/demoNetworkGroup)
azurerm_resource_group.1Demo: Refreshing state... (ID: /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/1Demo)
azurerm_public_ip.demoIP: Refreshing state... (ID: /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/1Demo/providers/Microsoft.Network/publicIPAddresses/demoIPAddress)
azurerm_storage_account.test: Refreshing state... (ID: /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/1demo/providers/Microsoft.Storage/storageAccounts/accsa)
azurerm_network_security_group.demo: Refreshing state... (ID: /subscriptions/xxxxxxxxxxxxxxx/resourceGroups/demoNetworkGroup/providers/Microsoft.Network/networkSecurityGroups/demoSecurityGroup)
azurerm_storage_container.test: Refreshing state... (ID: vhds)
azurerm_virtual_network.network: Creating...
address_space.#: "" => "1"
address_space.0: "" => "10.0.0.0/16"
location: "" => "westus"
name: "" => "demoNetwork"
resource_group_name: "" => "1Demo"
subnet.#: "" => "<computed>"
Error applying plan:
1 error(s) occurred:
* azurerm_virtual_network.network: autorest:DoErrorUnlessStatusCode 400 PUT https://management.azure.com/subscriptions/xxxxxxxxxxxxxxx/resourceGroups/1Demo/providers/Microsoft.Network/virtualnetworks/demoNetwork?api-version=2015-06-15 failed with 400 Bad Request
我嘗試了很多不同的方法,但似乎沒有任何效果。 我也嘗試過使用經典的Azure提供程序來做到這一點,並且效果很好。 是天青石供應商給我帶來麻煩。 我不確定這是否是一個地形錯誤,所以我一直推遲提交錯誤,直到我在這里獲得第二意見為止。 提前致謝。
經過幾天的研究,我發現由於Azure的垃圾回收在某種程度上是隨機的,因此資源名稱不一定總是立即釋放。 我可以通過重命名所有存儲和網絡名稱以及資源組來解決此問題。 希望將來對其他人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.