github.com/HashDataInc/packer@v1.3.2/helper/common/shared_state.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 ) 9 10 // Used to set variables which we need to access later in the build, where 11 // state bag and config information won't work 12 func sharedStateFilename(suffix string, buildName string) string { 13 uuid := os.Getenv("PACKER_RUN_UUID") 14 return filepath.Join(os.TempDir(), fmt.Sprintf("packer-%s-%s-%s", uuid, suffix, buildName)) 15 } 16 17 func SetSharedState(key string, value string, buildName string) error { 18 return ioutil.WriteFile(sharedStateFilename(key, buildName), []byte(value), 0600) 19 } 20 21 func RetrieveSharedState(key string, buildName string) (string, error) { 22 value, err := ioutil.ReadFile(sharedStateFilename(key, buildName)) 23 if err != nil { 24 return "", err 25 } 26 return string(value), nil 27 } 28 29 func RemoveSharedStateFile(key string, buildName string) { 30 os.Remove(sharedStateFilename(key, buildName)) 31 }