From b41612d01489f60f189f6b227a6f8c55d0fff0dd Mon Sep 17 00:00:00 2001 From: mahesh-hpe Date: Thu, 12 Dec 2024 15:22:09 +0530 Subject: [PATCH] Remove vmaas-api and add insecure flag --- acc-dev-testcases/README.md | 4 ++-- pkg/client/client.go | 17 +++++++++++++++++ pkg/resources/registration.go | 12 ++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/acc-dev-testcases/README.md b/acc-dev-testcases/README.md index 80997987..d24add3c 100644 --- a/acc-dev-testcases/README.md +++ b/acc-dev-testcases/README.md @@ -21,10 +21,10 @@ export HPEGL_VMAAS_SPACE_NAME= ``` By default the Terraform Provider will use the VMaaS production endpoint. To -use a non-production endpoint the `HPEGL_VMAAS_API_URL` must be set. For +use a non-production endpoint the `HPEGL_VMAAS_BROKER_URL` must be set. For example: ```bash -export HPEGL_VMAAS_API_URL="https://iac-vmaas.intg.hpedevops.net" +export HPEGL_VMAAS_BROKER_URL="https://vmaas-broker.intg.hpedevops.net" ``` By Default acceptance test will run test cases from folder `acc-testcases`. diff --git a/pkg/client/client.go b/pkg/client/client.go index 9a6f0095..32282c18 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -3,7 +3,9 @@ package client import ( + "crypto/tls" "fmt" + "net/http" "os" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -59,6 +61,7 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error) // Create VMaas Client client := new(Client) iamVersion := r.Get("iam_version").(string) + insecure := vmaasProviderSettings[constants.INSECURE].(bool) queryParam := map[string]string{ constants.LocationKey: vmaasProviderSettings[constants.LOCATION].(string), } @@ -80,6 +83,13 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error) DefaultHeader: brokerHeaders, DefaultQueryParams: queryParam, } + if insecure { + brokerCfgForAPIClient.HTTPClient = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + } + } brokerApiClient := api_client.NewAPIClient(&brokerCfgForAPIClient) utils.SetMetaFnAndVersion(brokerApiClient, r, 0) // Create cmp client @@ -88,6 +98,13 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error) DefaultHeader: map[string]string{}, DefaultQueryParams: map[string]string{}, } + if insecure { + cfg.HTTPClient = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + } + } apiClient := api_client.NewAPIClient(&cfg) err = utils.SetCMPVars(apiClient, brokerApiClient, &cfg) if err != nil { diff --git a/pkg/resources/registration.go b/pkg/resources/registration.go index 8167489b..d5f0f37c 100644 --- a/pkg/resources/registration.go +++ b/pkg/resources/registration.go @@ -88,18 +88,18 @@ func (r Registration) ProviderSchemaEntry() *schema.Resource { 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 ID.", }, - constants.APIURL: { - Type: schema.TypeString, - Required: true, - DefaultFunc: schema.EnvDefaultFunc("HPEGL_VMAAS_API_URL", constants.ServiceURL), - Description: "The URL to use for the VMaaS API, can also be set with the HPEGL_VMAAS_API_URL env var", - }, constants.BROKERRURL: { Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("HPEGL_VMAAS_BROKER_URL", constants.BrokerURL), Description: "The URL to use for the VMaaS Broker API, can also be set with the HPEGL_VMAAS_BROKER_URL env var", }, + constants.INSECURE: { + Type: schema.TypeBool, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("INSECURE", false), + Description: "Not to be used in production. To perform client connection ignoring TLS, it can also be set with the INSECURE env var", + }, }, } }