Skip to content

Commit

Permalink
Merge pull request #251 from HewlettPackard/pce-d-new
Browse files Browse the repository at this point in the history
US65433: workspaceID changes in case of glp
  • Loading branch information
reubenur-rahman authored Aug 11, 2024
2 parents 91d4f78 + 36695c2 commit 19d71db
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
21 changes: 13 additions & 8 deletions internal/acceptance_test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand All @@ -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) {
Expand Down
20 changes: 13 additions & 7 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) Copyright 2021 Hewlett Packard Enterprise Development LP
// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

package client

Expand Down Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/registration.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

package resources

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 19d71db

Please sign in to comment.