Merge pull request #7075 from hashicorp/do_4844
Add env vars "PACKER_HTTP_IP" and "PACKER_HTTP_PORT" to our various shell provisioners
This commit is contained in:
commit
f19fdbcaaf
|
@ -178,10 +178,18 @@ func createFlattenedEnvVars(config *Config) (string, error) {
|
||||||
envVars["PACKER_BUILD_NAME"] = fmt.Sprintf("%s", config.PackerBuildName)
|
envVars["PACKER_BUILD_NAME"] = fmt.Sprintf("%s", config.PackerBuildName)
|
||||||
envVars["PACKER_BUILDER_TYPE"] = fmt.Sprintf("%s", config.PackerBuilderType)
|
envVars["PACKER_BUILDER_TYPE"] = fmt.Sprintf("%s", config.PackerBuilderType)
|
||||||
|
|
||||||
// expose PACKER_HTTP_ADDR
|
// expose ip address variables
|
||||||
httpAddr := common.GetHTTPAddr()
|
httpAddr := common.GetHTTPAddr()
|
||||||
if httpAddr != "" {
|
if httpAddr != "" {
|
||||||
envVars["PACKER_HTTP_ADDR"] = fmt.Sprintf("%s", httpAddr)
|
envVars["PACKER_HTTP_ADDR"] = httpAddr
|
||||||
|
}
|
||||||
|
httpIP := common.GetHTTPIP()
|
||||||
|
if httpIP != "" {
|
||||||
|
envVars["PACKER_HTTP_IP"] = httpIP
|
||||||
|
}
|
||||||
|
httpPort := common.GetHTTPPort()
|
||||||
|
if httpPort != "" {
|
||||||
|
envVars["PACKER_HTTP_PORT"] = httpPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolate environment variables
|
// interpolate environment variables
|
||||||
|
|
|
@ -96,6 +96,22 @@ func GetHTTPAddr() string {
|
||||||
return fmt.Sprintf("%s:%s", ip, port)
|
return fmt.Sprintf("%s:%s", ip, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetHTTPPort() string {
|
||||||
|
port, err := common.RetrieveSharedState("port", "")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s", port)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetHTTPIP() string {
|
||||||
|
ip, err := common.RetrieveSharedState("ip", "")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s", ip)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StepHTTPServer) Cleanup(multistep.StateBag) {
|
func (s *StepHTTPServer) Cleanup(multistep.StateBag) {
|
||||||
if s.l != nil {
|
if s.l != nil {
|
||||||
// Close the listener so that the HTTP server stops
|
// Close the listener so that the HTTP server stops
|
||||||
|
|
|
@ -380,10 +380,19 @@ func (p *Provisioner) createFlattenedEnvVars(elevated bool) (flattened string) {
|
||||||
envVars["PACKER_BUILD_NAME"] = p.config.PackerBuildName
|
envVars["PACKER_BUILD_NAME"] = p.config.PackerBuildName
|
||||||
envVars["PACKER_BUILDER_TYPE"] = p.config.PackerBuilderType
|
envVars["PACKER_BUILDER_TYPE"] = p.config.PackerBuilderType
|
||||||
|
|
||||||
|
// expose ip address variables
|
||||||
httpAddr := common.GetHTTPAddr()
|
httpAddr := common.GetHTTPAddr()
|
||||||
if httpAddr != "" {
|
if httpAddr != "" {
|
||||||
envVars["PACKER_HTTP_ADDR"] = httpAddr
|
envVars["PACKER_HTTP_ADDR"] = httpAddr
|
||||||
}
|
}
|
||||||
|
httpIP := common.GetHTTPIP()
|
||||||
|
if httpIP != "" {
|
||||||
|
envVars["PACKER_HTTP_IP"] = httpIP
|
||||||
|
}
|
||||||
|
httpPort := common.GetHTTPPort()
|
||||||
|
if httpPort != "" {
|
||||||
|
envVars["PACKER_HTTP_PORT"] = httpPort
|
||||||
|
}
|
||||||
|
|
||||||
// interpolate environment variables
|
// interpolate environment variables
|
||||||
p.config.ctx.Data = &EnvVarsTemplate{
|
p.config.ctx.Data = &EnvVarsTemplate{
|
||||||
|
|
|
@ -463,9 +463,19 @@ func (p *Provisioner) escapeEnvVars() ([]string, map[string]string) {
|
||||||
// Always available Packer provided env vars
|
// Always available Packer provided env vars
|
||||||
envVars["PACKER_BUILD_NAME"] = fmt.Sprintf("%s", p.config.PackerBuildName)
|
envVars["PACKER_BUILD_NAME"] = fmt.Sprintf("%s", p.config.PackerBuildName)
|
||||||
envVars["PACKER_BUILDER_TYPE"] = fmt.Sprintf("%s", p.config.PackerBuilderType)
|
envVars["PACKER_BUILDER_TYPE"] = fmt.Sprintf("%s", p.config.PackerBuilderType)
|
||||||
|
|
||||||
|
// expose ip address variables
|
||||||
httpAddr := common.GetHTTPAddr()
|
httpAddr := common.GetHTTPAddr()
|
||||||
if httpAddr != "" {
|
if httpAddr != "" {
|
||||||
envVars["PACKER_HTTP_ADDR"] = fmt.Sprintf("%s", httpAddr)
|
envVars["PACKER_HTTP_ADDR"] = httpAddr
|
||||||
|
}
|
||||||
|
httpIP := common.GetHTTPIP()
|
||||||
|
if httpIP != "" {
|
||||||
|
envVars["PACKER_HTTP_IP"] = httpIP
|
||||||
|
}
|
||||||
|
httpPort := common.GetHTTPPort()
|
||||||
|
if httpPort != "" {
|
||||||
|
envVars["PACKER_HTTP_PORT"] = httpPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split vars into key/value components
|
// Split vars into key/value components
|
||||||
|
|
|
@ -289,10 +289,20 @@ func (p *Provisioner) createFlattenedEnvVars() (flattened string) {
|
||||||
// Always available Packer provided env vars
|
// Always available Packer provided env vars
|
||||||
envVars["PACKER_BUILD_NAME"] = p.config.PackerBuildName
|
envVars["PACKER_BUILD_NAME"] = p.config.PackerBuildName
|
||||||
envVars["PACKER_BUILDER_TYPE"] = p.config.PackerBuilderType
|
envVars["PACKER_BUILDER_TYPE"] = p.config.PackerBuilderType
|
||||||
|
|
||||||
|
// expose ip address variables
|
||||||
httpAddr := common.GetHTTPAddr()
|
httpAddr := common.GetHTTPAddr()
|
||||||
if httpAddr != "" {
|
if httpAddr != "" {
|
||||||
envVars["PACKER_HTTP_ADDR"] = httpAddr
|
envVars["PACKER_HTTP_ADDR"] = httpAddr
|
||||||
}
|
}
|
||||||
|
httpIP := common.GetHTTPIP()
|
||||||
|
if httpIP != "" {
|
||||||
|
envVars["PACKER_HTTP_IP"] = httpIP
|
||||||
|
}
|
||||||
|
httpPort := common.GetHTTPPort()
|
||||||
|
if httpPort != "" {
|
||||||
|
envVars["PACKER_HTTP_PORT"] = httpPort
|
||||||
|
}
|
||||||
|
|
||||||
// Split vars into key/value components
|
// Split vars into key/value components
|
||||||
for _, envVar := range p.config.Vars {
|
for _, envVar := range p.config.Vars {
|
||||||
|
|
Loading…
Reference in New Issue