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

This commit is contained in:
Marcel S. Henselin 2026-03-10 16:00:43 +01:00
parent 731957fcd0
commit 5975b2ba97
3 changed files with 43 additions and 44 deletions

View file

@ -53,9 +53,9 @@ func CreateTemporaryHome(createValidCredentialsFile bool, t *testing.T) string {
// Define content, default = invalid token // Define content, default = invalid token
token := "foo_token" token := "foo_token"
if createValidCredentialsFile { //if createValidCredentialsFile {
token = GetTestProjectServiceAccountJson("") // token = GetTestProjectServiceAccountJson("")
} //}
if _, err = file.WriteString(token); err != nil { if _, err = file.WriteString(token); err != nil {
t.Fatalf("Error writing to file: %v", err) t.Fatalf("Error writing to file: %v", err)
} }

View file

@ -293,25 +293,24 @@ func RedisProviderConfig() string {
) )
} }
func ResourceManagerProviderConfig() string { func ResourceManagerProviderConfig(saKeyPath string) string {
key := GetTestProjectServiceAccountJson("")
if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" { if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" {
return fmt.Sprintf(` return fmt.Sprintf(`
provider "stackitprivatepreview" { provider "stackitprivatepreview" {
service_account_key = "%s" service_account_key_path = "%s"
}`, }`,
key, saKeyPath,
) )
} }
return fmt.Sprintf(` return fmt.Sprintf(`
provider "stackitprivatepreview" { provider "stackitprivatepreview" {
resourcemanager_custom_endpoint = "%s" resourcemanager_custom_endpoint = "%s"
authorization_custom_endpoint = "%s" authorization_custom_endpoint = "%s"
service_account_token = "%s" service_account_key_path = "%s"
}`, }`,
ResourceManagerCustomEndpoint, ResourceManagerCustomEndpoint,
AuthorizationCustomEndpoint, AuthorizationCustomEndpoint,
key, saKeyPath,
) )
} }

View file

@ -100,17 +100,17 @@ func ResourceNameWithDateTime(name string) string {
return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed) return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed)
} }
func GetTestProjectServiceAccountJson(path string) string { //func GetTestProjectServiceAccountJson(path string) string {
var err error // var err error
json, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_JSON_CONTENT") // json, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_JSON_CONTENT")
if !ok || json == "" { // if !ok || json == "" {
json, err = readTestServiceAccountJsonFromFile(path) // json, err = readTestServiceAccountJsonFromFile(path)
if err != nil { // if err != nil {
return "" // return ""
} // }
} // }
return json // return json
} //}
// func GetTestProjectServiceAccountToken(path string) string { // func GetTestProjectServiceAccountToken(path string) string {
// var err error // var err error
@ -154,30 +154,30 @@ func GetTestProjectServiceAccountJson(path string) string {
// return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil // return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
//} //}
func readTestServiceAccountJsonFromFile(path string) (string, error) { //func readTestServiceAccountJsonFromFile(path string) (string, error) {
if path == "" { // if path == "" {
customPath, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_FILE") // customPath, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_FILE")
if !ok || customPath == "" { // if !ok || customPath == "" {
path = serviceAccountFilePath // path = serviceAccountFilePath
// TODO: check if we want to handle this with a home dir // // TODO: check if we want to handle this with a home dir
/* // /*
home, err := os.UserHomeDir() // home, err := os.UserHomeDir()
if err != nil { // if err != nil {
return "", fmt.Errorf("getting home directory: %w", err) // return "", fmt.Errorf("getting home directory: %w", err)
} // }
path = filepath.Join(home, path) // path = filepath.Join(home, path)
*/ // */
} else { // } else {
path = customPath // path = customPath
} // }
} // }
//
credentialsRaw, err := os.ReadFile(path) // credentialsRaw, err := os.ReadFile(path)
if err != nil { // if err != nil {
return "", fmt.Errorf("opening file: %w", err) // return "", fmt.Errorf("opening file: %w", err)
} // }
return string(credentialsRaw), nil // return string(credentialsRaw), nil
} //}
func getenv(key, defaultValue string) string { func getenv(key, defaultValue string) string {
val := os.Getenv(key) val := os.Getenv(key)