mirror of
https://github.com/hashicorp/packer.git
synced 2026-05-28 04:35:38 -04:00
hcl2_upgrade: add share_image_gallery workaround (#12087)
In azure templates, the shared_image_gallery was mistakenly considered an attribute while this is supposed to be a block. This is due to a heuristic we use for deciding whether a JSON object is to be translated to an attribute or a block that fell short as the shared_image_gallery does not contain complex types. This cannot be fixed trivially for the general case, so we add this entity to the list of workarounds until we can implement something more robust.
This commit is contained in:
parent
0bac9b6f63
commit
68ddb2f89d
5 changed files with 22 additions and 1 deletions
|
|
@ -121,6 +121,7 @@ func getBareComponentFinder() packer.ComponentFinder {
|
|||
"file": func() (packersdk.Builder, error) { return &file.Builder{}, nil },
|
||||
"null": func() (packersdk.Builder, error) { return &null.Builder{}, nil },
|
||||
"amazon-ebs": func() (packersdk.Builder, error) { return &ebs.Builder{}, nil },
|
||||
"azure-arm": func() (packersdk.Builder, error) { return &ebs.Builder{}, nil },
|
||||
},
|
||||
Provisioners: packer.MapOfProvisioner{
|
||||
"shell-local": func() (packersdk.Provisioner, error) { return &shell_local.Provisioner{}, nil },
|
||||
|
|
|
|||
|
|
@ -637,7 +637,7 @@ func jsonBodyToHCL2Body(out *hclwrite.Body, kvs map[string]interface{}) {
|
|||
case map[string]interface{}:
|
||||
var mostComplexElem interface{}
|
||||
for _, randomElem := range value {
|
||||
if k == "linux_options" || k == "network_interface" {
|
||||
if k == "linux_options" || k == "network_interface" || k == "shared_image_gallery" {
|
||||
break
|
||||
}
|
||||
// HACK: we take the most complex element of that map because
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ func Test_hcl2_upgrade(t *testing.T) {
|
|||
{folder: "nonexistent", flags: []string{}, exitCode: 1, exitEarly: true},
|
||||
{folder: "placeholders", flags: []string{}, exitCode: 0},
|
||||
{folder: "ami_test", flags: []string{}, exitCode: 0},
|
||||
{folder: "azure_shg", flags: []string{}, exitCode: 0},
|
||||
}
|
||||
|
||||
for _, tc := range tc {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
source "azure-arm" "autogenerated_1" {
|
||||
shared_image_gallery {
|
||||
gallery_name = "web_app"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
sources = ["source.azure-arm.autogenerated_1"]
|
||||
|
||||
}
|
||||
8
command/test-fixtures/hcl2_upgrade/azure_shg/input.json
Normal file
8
command/test-fixtures/hcl2_upgrade/azure_shg/input.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "azure-arm",
|
||||
"shared_image_gallery": {
|
||||
"gallery_name": "web_app"
|
||||
}
|
||||
}]
|
||||
}
|
||||
Loading…
Reference in a new issue