From 88d4ce37c93c3b77251264efc62400e57d4ff8d2 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 13 Dec 2019 13:03:09 -0800 Subject: [PATCH] template functioin to let Provisioners access PACKER_RUN_UUID --- common/step_provision.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/common/step_provision.go b/common/step_provision.go index 4c1df2659..3f2c59ecd 100644 --- a/common/step_provision.go +++ b/common/step_provision.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "os" "time" "github.com/hashicorp/packer/helper/communicator" @@ -39,6 +40,7 @@ func PlaceholderData() map[string]string { placeholderData["User"] = "{{.User}}" placeholderData["Password"] = "{{.Password}}" placeholderData["ConnType"] = "{{.Type}}" + placeholderData["PACKER_RUN_UUID"] = "{{.PACKER_RUN_UUID}}" // Backwards-compatability: placeholderData["WinRMPassword"] = "{{.WinRMPassword}}" @@ -48,6 +50,20 @@ func PlaceholderData() map[string]string { func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} { hookData := map[string]interface{}{} + // instance_id is placed in state by the builders. + // Not yet implemented in Chroot, lxc/lxd, Azure, Qemu. + // Implemented in most others including digitalOcean (droplet id), + // docker (container_id), and clouds which use "server" internally instead + // of instance. + id, ok := state.GetOk("instance_id") + if ok { + hookData["ID"] = id + } else { + // Warn user that the id isn't implemented + hookData["ID"] = "ERR_ID_NOT_IMPLEMENTED_BY_BUILDER" + } + hookData["PACKER_RUN_UUID"] = os.Getenv("PACKER_RUN_UUID") + // Read communicator data into hook data comm, ok := state.GetOk("communicator_config") if !ok { @@ -67,19 +83,6 @@ func PopulateProvisionHookData(state multistep.StateBag) map[string]interface{} // Password. hookData["WinRMPassword"] = commConf.WinRMPassword - // instance_id is placed in state by the builders. - // Not yet implemented in Chroot, lxc/lxd, Azure, Qemu. - // Implemented in most others including digitalOcean (droplet id), - // docker (container_id), and clouds which use "server" internally instead - // of instance. - id, ok := state.GetOk("instance_id") - if ok { - hookData["ID"] = id - } else { - // Warn user that the id isn't implemented - hookData["ID"] = "ERR_ID_NOT_IMPLEMENTED_BY_BUILDER" - } - return hookData }