From 610dde7f02327b6c37a480b7074e07cc09e64814 Mon Sep 17 00:00:00 2001 From: Sylvia Moss Date: Fri, 5 Mar 2021 11:10:00 +0100 Subject: [PATCH] check for nil config map (#10730) --- command/hcl2_upgrade.go | 9 +++++++++ .../hcl2_upgrade/complete/expected.pkr.hcl | 7 +++++++ command/test-fixtures/hcl2_upgrade/complete/input.json | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/command/hcl2_upgrade.go b/command/hcl2_upgrade.go index b0647a23e..bcc90a6cd 100644 --- a/command/hcl2_upgrade.go +++ b/command/hcl2_upgrade.go @@ -1033,7 +1033,12 @@ func writeProvisioner(typeName string, provisioner *template.Provisioner) []byte provisionerContent := hclwrite.NewEmptyFile() body := provisionerContent.Body() block := body.AppendNewBlock(typeName, []string{provisioner.Type}) + cfg := provisioner.Config + if cfg == nil { + cfg = map[string]interface{}{} + } + if len(provisioner.Except) > 0 { cfg["except"] = provisioner.Except } @@ -1086,6 +1091,10 @@ func (p *PostProcessorParser) Parse(tpl *template.Template) error { ppBody.SetAttributeValue("keep_input_artifact", cty.BoolVal(*pp.KeepInputArtifact)) } cfg := pp.Config + if cfg == nil { + cfg = map[string]interface{}{} + } + if len(pp.Except) > 0 { cfg["except"] = pp.Except } diff --git a/command/test-fixtures/hcl2_upgrade/complete/expected.pkr.hcl b/command/test-fixtures/hcl2_upgrade/complete/expected.pkr.hcl index 4293048e5..67e127138 100644 --- a/command/test-fixtures/hcl2_upgrade/complete/expected.pkr.hcl +++ b/command/test-fixtures/hcl2_upgrade/complete/expected.pkr.hcl @@ -172,6 +172,11 @@ source "amazon-ebs" "named_builder" { build { sources = ["source.amazon-ebs.autogenerated_1", "source.amazon-ebs.named_builder"] + provisioner "breakpoint" { + only = ["amazon-ebs"] + pause_before = "5s" + } + provisioner "shell" { except = ["amazon-ebs"] inline = ["echo ${var.secret_account}", "echo ${build.ID}", "echo ${build.SSHPublicKey} | head -c 14", "echo ${path.root} is not ${path.cwd}", "echo ${packer.version}", "echo ${uuidv4()}"] @@ -277,5 +282,7 @@ build { Description = "packer amazon-import ${local.timestamp}" } } + post-processor "compress" { + } } } diff --git a/command/test-fixtures/hcl2_upgrade/complete/input.json b/command/test-fixtures/hcl2_upgrade/complete/input.json index 3c7461ed6..9d7af97eb 100644 --- a/command/test-fixtures/hcl2_upgrade/complete/input.json +++ b/command/test-fixtures/hcl2_upgrade/complete/input.json @@ -116,6 +116,13 @@ } ], "provisioners": [ + { + "type": "breakpoint", + "only": [ + "amazon-ebs" + ], + "pause_before": "5s" + }, { "type": "shell", "except": [ @@ -230,6 +237,9 @@ "tags": { "Description": "packer amazon-import {{timestamp}}" } + }, + { + "type": "compress" } ] ]