From 5975b2ba9711f78a78f9fe8e4b4b0f5f951c26a2 Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Tue, 10 Mar 2026 16:00:43 +0100 Subject: [PATCH] fix: tf acc test pipeline --- internal/testutils/functions.go | 6 +-- internal/testutils/helpers.go | 11 +++--- internal/testutils/testutils.go | 70 ++++++++++++++++----------------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/internal/testutils/functions.go b/internal/testutils/functions.go index 3e748941..5b8f2970 100644 --- a/internal/testutils/functions.go +++ b/internal/testutils/functions.go @@ -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) } diff --git a/internal/testutils/helpers.go b/internal/testutils/helpers.go index c8d063dc..4b460fba 100644 --- a/internal/testutils/helpers.go +++ b/internal/testutils/helpers.go @@ -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, ) } diff --git a/internal/testutils/testutils.go b/internal/testutils/testutils.go index 65c962cc..2e8ba9d4 100644 --- a/internal/testutils/testutils.go +++ b/internal/testutils/testutils.go @@ -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)