azure - 共享图片库中的 Terraform Azure 虚拟机

标签 azure azure-cli

我的 Azure 共享图像库 (myGallery) 中有一个图像,名为 myImage,版本为 1.0.0

我尝试通过 Terraform 为图库中的此图像创建虚拟机,但收到以下错误:

Error: creating Linux Virtual Machine "testingvm" (Resource Group "myrg"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed." Target="osProfile"

  • Azure CLI 版本:2.26.1
  • Terraform 版本:1.0.0
  • Azure Terraform 提供程序版本:2.69.0

我的虚拟机 Terraform 如下所示:

resource "azurerm_linux_virtual_machine" "testingvm" {
  name                        = "testingvm"
  resource_group_name         = var.resource_group_name
  location                    = var.location

  size                        = "Standard_D2s_v4"
  network_interface_ids       = [azurerm_network_interface.testingvm.id]

  admin_username              = "azureuser"

  source_image_id             = "/subscriptions/MY_SUBSCRIPTION/resourceGroups/myrg/providers/Microsoft.Compute/galleries/myGallery/images/myImage/versions/1.0.0"

  os_disk {
    name                      = "testingvm-os"
    caching                   = "ReadWrite"
    storage_account_type      = "Premium_LRS"
  }

  admin_ssh_key {
    username                  = "azureuser"
    public_key                = module.vm_key_pair.pair_key_pub_value_openssh
  }
}

我尝试使用这两种方法,但没有成功(我相信后者是推荐的):

我尝试引用 this Stack Overflow entry也没有任何运气。

我在这里做错了什么?

<小时/>

再次尝试

我也尝试过使用这个:

source_image_reference {
  publisher                 = "myPublisher"
  offer                     = "myOffer"
  sku                       = "mySKU"
  version                   = "1.0.0"
}

查看输出后,identifier block 会输出匹配的参数:

az sig image-definition show \
  --gallery-image-definition myImage \
  --gallery-name myGallery
  --resource-group myrg

结果是:

Error: creating Linux Virtual Machine "testingvm" (Resource Group "myrg"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="PlatformImageNotFound" Message="The platform image 'myPublisher:myOffer:mySKU:1.0.0' is not available. Verify that all fields in the storage profile are correct. For more details about storage profile information, please refer to https://aka.ms/storageprofile" Target="imageReference"

最佳答案

感谢@KyleHale,我能够解决这个问题:

resource "azurerm_virtual_machine" "testingvm" {
  name                        = "testingvm"
  resource_group_name         = var.resource_group_name
  location                    = var.location

  vm_size                     = "Standard_D2s_v4"
  network_interface_ids       = [azurerm_network_interface.testingvm.id]

  storage_image_reference {
    id = "THE_ID_I_LISTED_BEFORE"
  }

  storage_os_disk {
    name                      = "testingvm-os"
    caching                   = "ReadWrite"
    create_option             = "FromImage"
    managed_disk_type         = "Standard_LRS"
  }
}

关于azure - 共享图片库中的 Terraform Azure 虚拟机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68581841/

相关文章:

c# - ThreadPool SetMinThreads - 设置它的影响

azure - QueueTrigger 未选取消息 - Azure WebJobs SDK 3.0

azure - 如何将 azure-devops 命令添加到脱机本地服务器中的 Azure CLI?

azure - Azure CLI 和 Powershell cmdlet 之间的功能不一致

git - Azure CLI 从任务创建新分支

java - 如何对 Java 上的 Microsoft Azure WebApp 进行故障排除?如何访问日志?

Azure(HTTP 500 内部服务器错误)。我需要更好的错误消息

azure - 无需登录即可使用 Azure API(使用角色)

azure - 如何使用 Azure Az CLI 以编程方式创建配置了 Autopilot 的 Azure Cosmos DB

azure - 如何检查Azure blob是否存在于多个容器中的存储帐户中的任何位置?