[英]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.