From 8718e98efef7d0134ba5f64e5ae720fb32109b15 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 3 Jul 2019 13:30:50 -0700 Subject: [PATCH] add common commHost function --- helper/communicator/comm_host.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 helper/communicator/comm_host.go diff --git a/helper/communicator/comm_host.go b/helper/communicator/comm_host.go new file mode 100644 index 000000000..b2ffde9d3 --- /dev/null +++ b/helper/communicator/comm_host.go @@ -0,0 +1,22 @@ +package communicator + +import ( + "log" + + "github.com/hashicorp/packer/helper/multistep" +) + +// Generic commHost function that should work for most cloud builders. +func CommHost(host string, statebagKey string) func(multistep.StateBag) (string, error) { + return func(state multistep.StateBag) (string, error) { + if host != "" { + log.Printf("Using ssh_host value: %s", host) + return host, nil + } + ipAddress, hasIP := state.Get(statebagKey).(string) + if !hasIP { + return "", fmt.Errorf("Failed to retrieve IP address.") + } + return ipAddress, nil + } +}