2019-07-03 16:30:50 -04:00
|
|
|
package communicator
|
|
|
|
|
|
|
|
import (
|
2019-07-03 16:34:23 -04:00
|
|
|
"fmt"
|
2019-07-03 16:30:50 -04:00
|
|
|
"log"
|
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2019-07-03 16:30:50 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 != "" {
|
2020-01-30 18:22:22 -05:00
|
|
|
log.Printf("Using host value: %s", host)
|
2019-07-03 16:30:50 -04:00
|
|
|
return host, nil
|
|
|
|
}
|
|
|
|
ipAddress, hasIP := state.Get(statebagKey).(string)
|
|
|
|
if !hasIP {
|
|
|
|
return "", fmt.Errorf("Failed to retrieve IP address.")
|
|
|
|
}
|
|
|
|
return ipAddress, nil
|
|
|
|
}
|
|
|
|
}
|