json 无法在local-exec置备程序Packer / Terraform中运行多行脚本

avwztpqn  于 2023-05-08  发布在  其他
关注(0)|答案(1)|浏览(171)

我正在尝试创建一个VMSS,并希望使用Packer捆绑我的图像和Terraform来创建Azure基础设施的其余部分。
我正在本地测试,但最终将推送到DevOps。当我尝试应用我的terraform时,我得到以下错误:

Error: local-exec provisioner error
│
│   with null_resource.packer,
│   on main.tf line 14, in resource "null_resource" "packer":
│   14:   provisioner "local-exec" {
│
│ Error running command 'packer build \
│ -var client_id=[client] \
│ -var client_secret=[secret] \
│ -var install_password=CHANGEME! \
│ -var location=UKSOUTH \
│ -var resource_group=[resourcegroup] \
│ -var storage_account=[sa] \
│ -var subscription_id=[sub] \
│ -var temp_resource_group_name=rg-packerbuild-test \
│ -var tenant_id=[tenant] \
│ -var virtual_network_name=[vnet] \
│ -var virtual_network_resource_group_name=[resource group] \
│ -var virtual_network_subnet_name=hosts \
│ windows2022.pkr.json
│ ': exit status 1. Output: Error: Could not find any config file in \
│
│ A config file must be suffixed with `.pkr.hcl` or `.pkr.json`. A folder can be
│ referenced.
locals {
  ami_name = join("-", [var.name, formatdate("YYYYMMDDhhmmss", timestamp())])
}

resource "null_resource" "packer" {
  triggers = {
    ami_name = local.ami_name
  }

  provisioner "local-exec" {
    working_dir = path.module
    command     = <<-EOF
    packer build \
    -var client_id=${var.client_id} \
    -var client_secret=${var.client_secret} \
    -var install_password=${var.install_password} \
    -var location=${var.location} \
    -var resource_group=${var.resource_group} \
    -var storage_account=${var.storage_account} \
    -var subscription_id=${var.SubscriptionId} \
    -var temp_resource_group_name=${var.TempResourceGroupName} \
    -var tenant_id=${var.TenantId} \
    -var virtual_network_name=${var.VirtualNetworkName} \
    -var virtual_network_resource_group_name=${var.VirtualNetworkRG} \
    -var virtual_network_subnet_name=${var.VirtualNetworkSubnet} \
    windows2022.pkr.json 
EOF
  }
}

文件就在那里,我在packer build命令之前添加了dir命令,它列出了正确的文件路径。
你知道我做错了什么吗?
谢谢

siv3szwd

siv3szwd1#

我通过添加interpreter命令并更改\来修复它。
希望这对某人有帮助。

provisioner "local-exec" {
    working_dir = path.module
    interpreter = ["PowerShell", "-Command"]
    command     = <<-EOT
    packer build `
    -force `
    -var client_id=${var.client_id} `
    -var client_secret=${var.client_secret} `
    -var install_password=${var.install_password} `
    -var location=${var.location} `
    -var resource_group=${var.resource_group} `
    -var storage_account=${var.storage_account} `
    -var subscription_id=${var.SubscriptionId} `
    -var temp_resource_group_name=${var.TempResourceGroupName} `
    -var tenant_id=${var.TenantId} `
    -var virtual_network_name=${var.VirtualNetworkName} `
    -var virtual_network_resource_group_name=${var.VirtualNetworkRG} `
    -var virtual_network_subnet_name=${var.VirtualNetworkSubnet} `
    windows2022.json 
    EOT
  }
}

相关问题