diff --git a/internal/acceptance_test/helper.go b/internal/acceptance_test/helper.go index 1fb8ce20..a737d32e 100644 --- a/internal/acceptance_test/helper.go +++ b/internal/acceptance_test/helper.go @@ -22,14 +22,19 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) { headers["Authorization"] = os.Getenv("HPEGL_IAM_TOKEN") headers["subject"] = os.Getenv(constants.CmpSubjectKey) } - + iamVersion := utils.GetEnv("HPEGL_IAM_VERSION", constants.IamGlcs) + queryParam := map[string]string{ + constants.LocationKey: os.Getenv("HPEGL_VMAAS_LOCATION"), + } + if iamVersion == constants.IamGlp { + queryParam[constants.WorkspaceKey] = os.Getenv("HPEGL_VMAAS_SPACE_NAME") + } else { + queryParam[constants.SpaceKey] = os.Getenv("HPEGL_VMAAS_SPACE_NAME") + } cfg := api_client.Configuration{ - Host: os.Getenv("HPEGL_VMAAS_API_URL"), - DefaultHeader: headers, - DefaultQueryParams: map[string]string{ - constants.LocationKey: os.Getenv("HPEGL_VMAAS_LOCATION"), - constants.SpaceKey: os.Getenv("HPEGL_VMAAS_SPACE_NAME"), - }, + Host: os.Getenv("HPEGL_VMAAS_API_URL"), + DefaultHeader: headers, + DefaultQueryParams: queryParam, } apiClient := api_client.NewAPIClient(&cfg) err := apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) { @@ -41,7 +46,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"), + "iam_version": iamVersion, }, } if utils.GetEnvBool(constants.MockIAMKey) { diff --git a/pkg/client/client.go b/pkg/client/client.go index 034fc4e6..a4317ea4 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,4 +1,4 @@ -// (C) Copyright 2021 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP package client @@ -53,14 +53,20 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error) // Create VMaas Client client := new(Client) + iamVersion := r.Get("iam_version").(string) + queryParam := map[string]string{ + constants.LocationKey: vmaasProviderSettings[constants.LOCATION].(string), + } + if iamVersion == constants.IamGlp { + queryParam[constants.WorkspaceKey] = vmaasProviderSettings[constants.SPACENAME].(string) + } else { + queryParam[constants.SpaceKey] = vmaasProviderSettings[constants.SPACENAME].(string) + } cfg := api_client.Configuration{ - Host: vmaasProviderSettings[constants.APIURL].(string), - DefaultHeader: getHeaders(), - DefaultQueryParams: map[string]string{ - constants.SpaceKey: vmaasProviderSettings[constants.SPACENAME].(string), - constants.LocationKey: vmaasProviderSettings[constants.LOCATION].(string), - }, + Host: vmaasProviderSettings[constants.APIURL].(string), + DefaultHeader: getHeaders(), + DefaultQueryParams: queryParam, } apiClient := api_client.NewAPIClient(&cfg) utils.SetMeta(apiClient, r) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 08216ad0..38b05508 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -1,19 +1,22 @@ -// (C) Copyright 2021 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP // Package constants - constants that are used in pkg/client and pkg/resources package constants const ( // ServiceName - the service mnemonic - ServiceName = "vmaas" - ServiceURL = "https://iac-vmaas.us1.greenlake-hpe.com" + ServiceName = "vmaas" + ServiceURL = "https://iac-vmaas.us1.greenlake-hpe.com" + IamGlp string = "glp" + IamGlcs string = "glcs" - LOCATION = "location" - SPACENAME = "space_name" - APIURL = "api_url" - INSECURE = "allow_insecure" - SpaceKey = "space" - LocationKey = "location" + LOCATION = "location" + SPACENAME = "space_name" + APIURL = "api_url" + INSECURE = "allow_insecure" + SpaceKey = "space" + WorkspaceKey = "workspaceID" + LocationKey = "location" MockIAMKey = "TF_ACC_MOCK_IAM" CmpSubjectKey = "TF_ACC_CMP_SUBJECT" diff --git a/pkg/resources/registration.go b/pkg/resources/registration.go index de99a2c3..d18840cf 100644 --- a/pkg/resources/registration.go +++ b/pkg/resources/registration.go @@ -1,4 +1,4 @@ -// (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP package resources @@ -82,7 +82,7 @@ func (r Registration) ProviderSchemaEntry() *schema.Resource { Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("HPEGL_VMAAS_SPACE_NAME", ""), - Description: "IAM Space name of the GL VMaaS Service, can also be set with the HPEGL_VMAAS_SPACE_NAME env var.", + Description: "It can also be set with the HPEGL_VMAAS_SPACE_NAME env var. When `HPEGL_IAM_VERSION` is `glcs` it refers to IAM Space name of the GL VMaaS Service i.e., Default. When `HPEGL_IAM_VERSION` is `glp` it refers to GLP Workspace ID.", }, constants.APIURL: { Type: schema.TypeString,