我在实验室测试了相同的场景,错误对我来说也是一样的。
Message:参数imageReference的值无效。
根本原因:当我们尝试从 SIG 映像版本导出到磁盘时,但使用了映像上不存在的 LUN 位置。
当尝试从映像版本创建托管磁盘时,我们得到的参数无效,因为两个资源正在使用的 LUN 编号不匹配。
解决方法:
默认情况下,在 azure 中,每当我们从映像版本创建 VM 时,都会使用托管磁盘创建它。
因此,我尝试使用共享映像直接部署虚拟机,并且部署成功。
这是我的一部分main.tf
用于部署虚拟机,我在其中定义了共享映像版本位置,并在获取数据后将其用于虚拟机操作系统磁盘。
# Information about existing shared image version
data "azurerm_shared_image_version" "asgi" {
name = var.galleryImageVersionName
image_name = var.galleryImageDefinitionName
gallery_name = var.galleryName
resource_group_name = "the resource group where your shared Image Version is!!"
}
# Virtual Machine - Windows
resource "azurerm_windows_virtual_machine" "avm-01" {
name = local.vmName
computer_name = "myVm"
resource_group_name = azurerm_resource_group.arg-01.name # new resource group where we are creating all the resources using shared image gallery.
location = azurerm_resource_group.arg-01.location #same as the image version.
size = "Standard_A1"
admin_username = var.adminUsername
admin_password = var.adminPassword
network_interface_ids = [azurerm_network_interface.anic-01.id]
source_image_id = data.azurerm_shared_image_version.asgi.id
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
}
In variables.tf
,我已经定义了我在我的中使用的变量main.tf
file .
provider "azurerm" {
features {}
subscription_id = var.tf_var_arm_subscription_id
}
variable "tf_var_arm_subscription_id" {
type = string
description = "Variable for our resource group"
}
variable "resourceGroupName" {
type = string
default = "tf-rg"
description = "Resource Group for this deployment."
}
variable "location" {
type = string
default = "West US 2"
description = "Enter the location for all resources."
}
variable "galleryName" {
type = string
description = "Name of the Shared Image Gallery."
}
variable "galleryImageDefinitionName" {
type = string
description = "Name of the Image Definition."
}
variable "galleryImageVersionName" {
type = string
}
My terraform.tfvars
文件有我的订阅 ID 和所有共享图库资源名称。
tf_var_arm_subscription_id = "SubscriptionID"
# Defining values to the variables
galleryName = "mysharedgallery"
galleryImageDefinitionName = "my-image"
galleryImageVersionName = "0.0.1"
我还添加了其他设置,例如虚拟网络等我需要在我的虚拟机中创建它main.tf
.
Output
Note :请为您的资源提供与共享图片库相同的区域。