github.com/openshift/installer@v1.4.17/pkg/infrastructure/openstack/preprovision/terraform.go (about) 1 package preprovision 2 3 import ( 4 "errors" 5 "fmt" 6 "os" 7 "path/filepath" 8 ) 9 10 // SetTerraformEnvironment injects the environment variables required 11 // authenticate against the OpenStack API. 12 func SetTerraformEnvironment() error { 13 // Terraform runs in a different directory but we want to allow people to 14 // use clouds.yaml files in their local directory. Emulate this by setting 15 // the necessary environment variable to point to this file if (a) the user 16 // hasn't already set this environment variable and (b) there is actually 17 // a local file 18 if path := os.Getenv("OS_CLIENT_CONFIG_FILE"); path != "" { 19 return nil 20 } 21 22 cwd, err := os.Getwd() 23 if err != nil { 24 return fmt.Errorf("unable to determine working directory: %w", err) 25 } 26 27 cloudsYAML := filepath.Join(cwd, "clouds.yaml") 28 if _, err = os.Stat(cloudsYAML); err == nil { 29 os.Setenv("OS_CLIENT_CONFIG_FILE", cloudsYAML) 30 } else if !errors.Is(err, os.ErrNotExist) { 31 return fmt.Errorf("unable to determine if clouds.yaml exists: %w", err) 32 } 33 34 return nil 35 }