gpt4 book ai didi

azure - Terraform 无法在德国中西部地区创建 Azure 虚拟机

转载 作者:行者123 更新时间:2023-12-03 05:16:29 25 4
gpt4 key购买 nike

我尝试在 德国中西部 区域创建 azure 虚拟机,但收到以下错误:

Error: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status= Code="SkuNotAvailable" Message="The requested size for resource '/subscriptions//resourceGroups/shared-rg/providers/Microsoft.Compute/virtualMachines/jumphost' is currently not available in location 'germanywestcentral' zones '' for subscription ''. Please try another size or deploy to a different location or zones. See https://aka.ms/azureskunotavailable for details."││ with module.jump_host_vm.azurerm_virtual_machine.vm,│ on modules/virtual-machine/main.tf line 1, in resource "azurerm_virtual_machine" "vm":│ 1: resource "azurerm_virtual_machine" "vm" {

我使用的是Standard_A1_v2尺寸和22.04-LTS的SKU。请在下面找到我的 terraform 代码:

resource "azurerm_virtual_machine" "vm" {
name = var.vm_name
location = var.location
resource_group_name = var.rg_name
network_interface_ids = var.nic_id
vm_size = var.vm_size #"Standard_A1_v2"

delete_os_disk_on_termination = true

delete_data_disks_on_termination = true

storage_image_reference {
publisher = var.storage_image_reference.publisher #"Canonical"
offer = var.storage_image_reference.offer #"UbuntuServer"
sku = var.storage_image_reference.sku #"20.04-LTS"
version = var.storage_image_reference.version #"latest"
}
storage_os_disk {
name = var.storage_os_disk.name #"myosdisk1"
caching = var.storage_os_disk.caching #"ReadWrite"
create_option = var.storage_os_disk.create_option #"FromImage"
managed_disk_type = var.storage_os_disk.managed_disk_type #"Standard_LRS"
}

os_profile_linux_config {
disable_password_authentication = true
}
tags = merge(var.common_tags)
}

上述值如下:

jump_host_vm_name = "jumphost"
jump_host_vm_size = "Standard_A1_v2"
jump_host_storage_image_reference = {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "22.04-LTS"
version = "latest"
}
jump_host_storage_os_disk = {
name = "myosdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

有人可以帮我理解为什么它不起作用吗?根据 Azure 网站 [1],该虚拟机在德国地区可用。

[1] - https://azure.microsoft.com/en-us/explore/global-infrastructure/products-by-region/?regions=all&products=virtual-machines

最佳答案

似乎 Canonical:UbuntuServer:22.04-LTS:latest 不可用并且正在预览中。我们可以使用以下版本 16.04-LTS/19_10-daily-gen2对于 16.04 版本,虚拟机大小为“Standard_A1_v2”对于最新的 sku 19_10-daily-gen2,支持的虚拟机大小将为 Standard_DS2_v2

 storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS" //"19_10-daily-gen2"
version = "latest"
}

以下是获取受支持的 SKU 版本的命令

Get-AzVMImageSku -Location "Germany West Central" -PublisherName "Canonical" -Offer "UbuntuServer" | Select Skus

enter image description here

请从 snippet 找到以下示例代码引用主要tf如下

data "azurerm_resource_group" "example" {
name = "***********"
}
data "azuread_client_config" "current" {}

resource "azurerm_virtual_network" "puvnet" {
name = "Public_VNET"
resource_group_name = data.azurerm_resource_group.example.name
location = "Germany West Central"
address_space = ["10.19.0.0/16"]
dns_servers = ["10.19.0.4", "10.19.0.5"]
}

resource "azurerm_subnet" "osubnet" {
name = "Outer_Subnet"
resource_group_name = data.azurerm_resource_group.example.name
address_prefixes = ["10.19.1.0/24"]
virtual_network_name = azurerm_virtual_network.puvnet.name
}


resource "azurerm_network_interface" "main" {
name = "testdemo"
location = "Germany West Central"
resource_group_name = data.azurerm_resource_group.example.name

ip_configuration {
name = "testconfiguration1"
subnet_id = azurerm_subnet.osubnet.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_virtual_machine" "main" {
name = "vmjumphost"
location = "Germany West Central"
resource_group_name = data.azurerm_resource_group.example.name
network_interface_ids = [azurerm_network_interface.main.id]
vm_size = "Standard_A1_v2"
storage_image_reference {
offer = "UbuntuServer"
publisher = "Canonical"
sku = "19_10-daily-gen2"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "hostname"
admin_username = "********"
admin_password = "*********"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = "staging"
}
}

提供者文件如下:

terraform {

required_version = "~>1.3.3"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.0.0"
}
}
}

provider "azurerm" {
features {}
skip_provider_registration = true
}

运行时

terraform plan 

enter image description here

申请后

terraform apply -auto-approve

enter image description here

从用户界面验证

enter image description here

enter image description here

关于azure - Terraform 无法在德国中西部地区创建 Azure 虚拟机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74797873/

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