From 4a0e0c253161061130c24a4c3b60788695fc4f49 Mon Sep 17 00:00:00 2001 From: Mahesh N Date: Wed, 12 Jun 2024 12:32:49 +0530 Subject: [PATCH] Fix tf acceptance test --- go.mod | 2 +- go.sum | 4 ++-- internal/acceptance_test/helper.go | 4 ++-- pkg/atf/constants.go | 24 ++++++++++++++++++------ pkg/atf/reader.go | 3 ++- pkg/utils/utils.go | 10 +++++++++- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index e05986a3..d0085713 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/HewlettPackard/hpegl-vmaas-terraform-resources go 1.21 require ( - github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.9-0.20240611110535-bde9db20c238 + github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.9-0.20240611163337-ef8debaa03a8 github.com/golang/mock v1.6.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-docs v0.9.0 diff --git a/go.sum b/go.sum index 1715638b..7aa83146 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.9-0.20240611110535-bde9db20c238 h1:DSFTAcz5MaBeUz4hsvzr/we4F1P4ZBtdfiVulnFbaJ8= -github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.9-0.20240611110535-bde9db20c238/go.mod h1:UzXizYR6sUVsvDRMcLC2E4eabJsPH/3nM8rlKL2BLSc= +github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.9-0.20240611163337-ef8debaa03a8 h1:WHn8kRFLG6Fzy/DEDt30Vk1uFoUJ0Kzc8pSjIExGMss= +github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk v0.1.9-0.20240611163337-ef8debaa03a8/go.mod h1:UzXizYR6sUVsvDRMcLC2E4eabJsPH/3nM8rlKL2BLSc= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= diff --git a/internal/acceptance_test/helper.go b/internal/acceptance_test/helper.go index 9e5939ad..1fb8ce20 100644 --- a/internal/acceptance_test/helper.go +++ b/internal/acceptance_test/helper.go @@ -1,4 +1,4 @@ -// (C) Copyright 2021 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP package acceptancetest @@ -31,7 +31,6 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) { constants.SpaceKey: os.Getenv("HPEGL_VMAAS_SPACE_NAME"), }, } - apiClient := api_client.NewAPIClient(&cfg) err := apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) { d := &utils.ResourceData{ @@ -42,6 +41,7 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) { "user_secret": os.Getenv("HPEGL_USER_SECRET"), "api_vended_service_client": true, "iam_token": os.Getenv("HPEGL_IAM_TOKEN"), + "iam_version": utils.GetEnv("HPEGL_IAM_VERSION", "glcs"), }, } if utils.GetEnvBool(constants.MockIAMKey) { diff --git a/pkg/atf/constants.go b/pkg/atf/constants.go index 1f93fa87..d612d5af 100644 --- a/pkg/atf/constants.go +++ b/pkg/atf/constants.go @@ -1,11 +1,13 @@ package atf -const providerStanza = ` - provider hpegl { - vmaas { - } - } -` +import "fmt" + +// const providerStanza = ` +// provider hpegl { +// vmaas { +// } +// } +// ` var accTestPath = "../../acc-testcases" @@ -16,3 +18,13 @@ const ( randMaxLimit = 999999 ) + +func GetProviderStanza(alias string) string { + return fmt.Sprintf(` + provider hpegl { + alias = "%s" + vmaas { + } + } +`, alias) +} diff --git a/pkg/atf/reader.go b/pkg/atf/reader.go index 9a139a08..12fed5da 100644 --- a/pkg/atf/reader.go +++ b/pkg/atf/reader.go @@ -167,10 +167,11 @@ func (r *reader) parseConfig(v *viper.Viper) []accConfig { configs[i].config = fmt.Sprintf(` %s %s "%s" "tf_%s" { + provider = hpegl.%s %s } `, - providerStanza, getType(r.isResource), r.name, tfKey, tfConfig, + GetProviderStanza(tfKey), getType(r.isResource), r.name, tfKey, tfKey, tfConfig, ) r.parseRegex(v, i) configs[i].validations = r.parseValidations(v, i) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 6f4efb65..ca1982f9 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -1,4 +1,4 @@ -// (C) Copyright 2021 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP package utils @@ -76,3 +76,11 @@ func GetEnvBool(key string) bool { return value } + +func GetEnv(key, defaultVal string) string { + value, exists := os.LookupEnv(key) + if !exists { + value = defaultVal + } + return value +}