gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:58:11 25 4
gpt4 key购买 nike

我的 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/

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