From 931cf2f58498cd2e905bc1d9dcf17ea4845b645f Mon Sep 17 00:00:00 2001 From: Mahesh N Date: Thu, 1 Aug 2024 16:06:43 +0530 Subject: [PATCH 1/4] US65433: workspaceID changes in case of glp --- internal/acceptance_test/helper.go | 21 +++++++++++++-------- pkg/client/client.go | 20 +++++++++++++------- pkg/constants/constants.go | 21 ++++++++++++--------- 3 files changed, 38 insertions(+), 24 deletions(-) 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..10683755 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 := utils.GetEnv("HPEGL_IAM_VERSION", constants.IamGlcs) + 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" From 7131fa3c7e051c8ff54cb38283915f2580c5607f Mon Sep 17 00:00:00 2001 From: mahesh-hpe Date: Mon, 5 Aug 2024 16:04:06 +0530 Subject: [PATCH 2/4] use iam_version from resource --- pkg/client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 10683755..a4317ea4 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -53,7 +53,7 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error) // Create VMaas Client client := new(Client) - iamVersion := utils.GetEnv("HPEGL_IAM_VERSION", constants.IamGlcs) + iamVersion := r.Get("iam_version").(string) queryParam := map[string]string{ constants.LocationKey: vmaasProviderSettings[constants.LOCATION].(string), } From 95a7c50ae209f8c3994e5279d20310f201234c5d Mon Sep 17 00:00:00 2001 From: mahesh-hpe Date: Fri, 9 Aug 2024 15:38:20 +0530 Subject: [PATCH 3/4] update spacename description --- pkg/resources/registration.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/resources/registration.go b/pkg/resources/registration.go index de99a2c3..7a71bdbf 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 UUID.", }, constants.APIURL: { Type: schema.TypeString, From 36695c276188a314b5578c4b94b3d55358c892fa Mon Sep 17 00:00:00 2001 From: mahesh-hpe Date: Fri, 9 Aug 2024 15:51:00 +0530 Subject: [PATCH 4/4] update description --- pkg/resources/registration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/resources/registration.go b/pkg/resources/registration.go index 7a71bdbf..d18840cf 100644 --- a/pkg/resources/registration.go +++ b/pkg/resources/registration.go @@ -82,7 +82,7 @@ func (r Registration) ProviderSchemaEntry() *schema.Resource { Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("HPEGL_VMAAS_SPACE_NAME", ""), - 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 UUID.", + 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,