英文:
Pass array of strings from PowerShell to Packer
问题
以下是您要翻译的内容:
在此存储库中有一个名为ubuntu2204.pkr.hcl的打包脚本。
它接受以下参数:
variable "azure_tags" {
type = map(string)
default = {}
}
我一直在尝试从PowerShell脚本中调用它,如下所示:
$azureTags = @{
BusinessUnit = "IDS"
Environment = "Production"
}
packer build -var "capture_name_prefix=$ResourcesNamePrefix" `
-var "client_id=$ClientId" `
-var "client_secret=$ClientSecret" `
-var "install_password=$InstallPassword" `
-var "location=$Location" `
-var "resource_group=$ResourceGroup" `
-var "storage_account=$StorageAccount" `
-var "subscription_id=$SubscriptionId" `
-var "temp_resource_group_name=$TempResourceGroupName" `
-var "tenant_id=$TenantId" `
-var "virtual_network_name=$VirtualNetworkName" `
-var "virtual_network_resource_group_name=$VirtualNetworkRG" `
-var "virtual_network_subnet_name=$VirtualNetworkSubnet" `
-var "run_validation_diskspace=$env:RUN_VALIDATION_FLAG" `
-var "azure_tags=$($azureTags | ConvertTo-Json -Compress)" `
-color=false `
$TemplatePath
这会产生以下错误:
> 构建ubuntu2204 VM
> 错误:不允许使用变量
> 在参数行1的var.azure_tags的值上:
我是packer的新手,有人看到我做错了什么吗?
英文:
There's a packer script called ubuntu2204.pkr.hcl in this repo
It accepts the following parameter:
variable "azure_tags" {
type = map(string)
default = {}
}
I've been trying to call this from a PowerShell script as below:
$azureTags = @{
BusinessUnit = "IDS"
Environment = "Production"
}
packer build -var "capture_name_prefix=$ResourcesNamePrefix" `
-var "client_id=$ClientId" `
-var "client_secret=$ClientSecret" `
-var "install_password=$InstallPassword" `
-var "location=$Location" `
-var "resource_group=$ResourceGroup" `
-var "storage_account=$StorageAccount" `
-var "subscription_id=$SubscriptionId" `
-var "temp_resource_group_name=$TempResourceGroupName" `
-var "tenant_id=$TenantId" `
-var "virtual_network_name=$VirtualNetworkName" `
-var "virtual_network_resource_group_name=$VirtualNetworkRG" `
-var "virtual_network_subnet_name=$VirtualNetworkSubnet" `
-var "run_validation_diskspace=$env:RUN_VALIDATION_FLAG" `
-var "azure_tags=$($azureTags | ConvertTo-Json -Compress)" `
-color=false `
$TemplatePath
This is giving the following error:
> Build ubuntu2204 VM
> Error: Variables not allowed
> on value for var.azure_tags from arguments line 1:
I'm new to packer, anyone see what I've got wrong?
答案1
得分: 1
I think that has something to do with the quotes of the serialized json.
This worked for me with packer 1.9.2
.
Given this file file.pkr.hcl
:
variable "azure_tags" {
type = map(string)
default = {}
}
$azureTags = @{
BusinessUnit = "IDS"
Environment = "Production"
}
$tags=$($azureTags | ConvertTo-Json -Compress)
packer console -var "azure_tags=$($tags -replace '\\\"','\\\\"')" .\file.pkr.hcl
>
> var.azure_tags
{
"BusinessUnit" = "IDS"
"Environment" = "Production"
}
英文:
I think that has something to do with the quotes of the serialized json.
This worked for me with packer 1.9.2
.
Given this file file.pkr.hcl
:
variable "azure_tags" {
type = map(string)
default = {}
}
$azureTags = @{
BusinessUnit = "IDS"
Environment = "Production"
}
$tags=$($azureTags | ConvertTo-Json -Compress)
packer console -var "azure_tags=$($tags -replace '([\\]*)"', '$1$1\"')" .\file.pkr.hcl
>
> var.azure_tags
{
"BusinessUnit" = "IDS"
"Environment" = "Production"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论