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:
Megan Marsh 2018-12-06 14:41:31 -08:00 committed by GitHub
commit f19fdbcaaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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{

View File

@ -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

View File

@ -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 {