fix: tf acc test pipeline
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Has been cancelled
CI Workflow / Prepare GO cache (pull_request) Has been cancelled
CI Workflow / Test readiness for publishing provider (pull_request) Has been cancelled
CI Workflow / CI run tests (pull_request) Has been cancelled
CI Workflow / CI run build and linting (pull_request) Has been cancelled
CI Workflow / Code coverage report (pull_request) Has been cancelled
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Has been cancelled
CI Workflow / Prepare GO cache (pull_request) Has been cancelled
CI Workflow / Test readiness for publishing provider (pull_request) Has been cancelled
CI Workflow / CI run tests (pull_request) Has been cancelled
CI Workflow / CI run build and linting (pull_request) Has been cancelled
CI Workflow / Code coverage report (pull_request) Has been cancelled
This commit is contained in:
parent
731957fcd0
commit
5975b2ba97
3 changed files with 43 additions and 44 deletions
|
|
@ -53,9 +53,9 @@ func CreateTemporaryHome(createValidCredentialsFile bool, t *testing.T) string {
|
|||
|
||||
// Define content, default = invalid token
|
||||
token := "foo_token"
|
||||
if createValidCredentialsFile {
|
||||
token = GetTestProjectServiceAccountJson("")
|
||||
}
|
||||
//if createValidCredentialsFile {
|
||||
// token = GetTestProjectServiceAccountJson("")
|
||||
//}
|
||||
if _, err = file.WriteString(token); err != nil {
|
||||
t.Fatalf("Error writing to file: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -293,25 +293,24 @@ func RedisProviderConfig() string {
|
|||
)
|
||||
}
|
||||
|
||||
func ResourceManagerProviderConfig() string {
|
||||
key := GetTestProjectServiceAccountJson("")
|
||||
func ResourceManagerProviderConfig(saKeyPath string) string {
|
||||
if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key = "%s"
|
||||
service_account_key_path = "%s"
|
||||
}`,
|
||||
key,
|
||||
saKeyPath,
|
||||
)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackitprivatepreview" {
|
||||
resourcemanager_custom_endpoint = "%s"
|
||||
authorization_custom_endpoint = "%s"
|
||||
service_account_token = "%s"
|
||||
service_account_key_path = "%s"
|
||||
}`,
|
||||
ResourceManagerCustomEndpoint,
|
||||
AuthorizationCustomEndpoint,
|
||||
key,
|
||||
saKeyPath,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,17 +100,17 @@ func ResourceNameWithDateTime(name string) string {
|
|||
return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed)
|
||||
}
|
||||
|
||||
func GetTestProjectServiceAccountJson(path string) string {
|
||||
var err error
|
||||
json, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_JSON_CONTENT")
|
||||
if !ok || json == "" {
|
||||
json, err = readTestServiceAccountJsonFromFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return json
|
||||
}
|
||||
//func GetTestProjectServiceAccountJson(path string) string {
|
||||
// var err error
|
||||
// json, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_JSON_CONTENT")
|
||||
// if !ok || json == "" {
|
||||
// json, err = readTestServiceAccountJsonFromFile(path)
|
||||
// if err != nil {
|
||||
// return ""
|
||||
// }
|
||||
// }
|
||||
// return json
|
||||
//}
|
||||
|
||||
// func GetTestProjectServiceAccountToken(path string) string {
|
||||
// var err error
|
||||
|
|
@ -154,30 +154,30 @@ func GetTestProjectServiceAccountJson(path string) string {
|
|||
// return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
|
||||
//}
|
||||
|
||||
func readTestServiceAccountJsonFromFile(path string) (string, error) {
|
||||
if path == "" {
|
||||
customPath, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_FILE")
|
||||
if !ok || customPath == "" {
|
||||
path = serviceAccountFilePath
|
||||
// TODO: check if we want to handle this with a home dir
|
||||
/*
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("getting home directory: %w", err)
|
||||
}
|
||||
path = filepath.Join(home, path)
|
||||
*/
|
||||
} else {
|
||||
path = customPath
|
||||
}
|
||||
}
|
||||
|
||||
credentialsRaw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("opening file: %w", err)
|
||||
}
|
||||
return string(credentialsRaw), nil
|
||||
}
|
||||
//func readTestServiceAccountJsonFromFile(path string) (string, error) {
|
||||
// if path == "" {
|
||||
// customPath, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_FILE")
|
||||
// if !ok || customPath == "" {
|
||||
// path = serviceAccountFilePath
|
||||
// // TODO: check if we want to handle this with a home dir
|
||||
// /*
|
||||
// home, err := os.UserHomeDir()
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("getting home directory: %w", err)
|
||||
// }
|
||||
// path = filepath.Join(home, path)
|
||||
// */
|
||||
// } else {
|
||||
// path = customPath
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// credentialsRaw, err := os.ReadFile(path)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("opening file: %w", err)
|
||||
// }
|
||||
// return string(credentialsRaw), nil
|
||||
//}
|
||||
|
||||
func getenv(key, defaultValue string) string {
|
||||
val := os.Getenv(key)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue