Skip to content

Commit

Permalink
fix: multipart fix for mqcloud
Browse files Browse the repository at this point in the history
(cherry picked from commit e7253421db30943d3582ce07d9504a2117f30ce1)
  • Loading branch information
shuaibbapputty authored and Shuaib Bapputty committed Dec 27, 2023
1 parent 617aba3 commit af9f5f3
Show file tree
Hide file tree
Showing 29 changed files with 449 additions and 562 deletions.
330 changes: 257 additions & 73 deletions examples/ibm-mqcloud/README.md

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions examples/ibm-mqcloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ resource "ibm_mqcloud_keystore_certificate" "mqcloud_keystore_certificate_instan
service_instance_guid = var.mqcloud_keystore_certificate_service_instance_guid
queue_manager_id = var.mqcloud_keystore_certificate_queue_manager_id
label = var.mqcloud_keystore_certificate_label
certificate_file = var.mqcloud_keystore_certificate_certificate_file
}

// Provision mqcloud_truststore_certificate resource instance
resource "ibm_mqcloud_truststore_certificate" "mqcloud_truststore_certificate_instance" {
service_instance_guid = var.mqcloud_truststore_certificate_service_instance_guid
queue_manager_id = var.mqcloud_truststore_certificate_queue_manager_id
label = var.mqcloud_truststore_certificate_label
certificate_file = var.mqcloud_truststore_certificate_certificate_file
}

// Data source is not linked to a resource instance
// Uncomment if an existing data source instance exists
/*
// Create mqcloud_queue_manager data source
data "ibm_mqcloud_queue_manager" "mqcloud_queue_manager_instance" {
service_instance_guid = var.mqcloud_queue_manager_service_instance_guid
name = var.mqcloud_queue_manager_name
service_instance_guid = var.data_mqcloud_queue_manager_service_instance_guid
name = var.data_mqcloud_queue_manager_name
}
*/

Expand All @@ -65,8 +66,8 @@ data "ibm_mqcloud_queue_manager_status" "mqcloud_queue_manager_status_instance"
/*
// Create mqcloud_application data source
data "ibm_mqcloud_application" "mqcloud_application_instance" {
service_instance_guid = var.mqcloud_application_service_instance_guid
name = var.mqcloud_application_name
service_instance_guid = var.data_mqcloud_application_service_instance_guid
name = var.data_mqcloud_application_name
}
*/

Expand All @@ -75,8 +76,8 @@ data "ibm_mqcloud_application" "mqcloud_application_instance" {
/*
// Create mqcloud_user data source
data "ibm_mqcloud_user" "mqcloud_user_instance" {
service_instance_guid = var.mqcloud_user_service_instance_guid
name = var.mqcloud_user_name
service_instance_guid = var.data_mqcloud_user_service_instance_guid
name = var.data_mqcloud_user_name
}
*/

Expand All @@ -85,9 +86,9 @@ data "ibm_mqcloud_user" "mqcloud_user_instance" {
/*
// Create mqcloud_truststore_certificate data source
data "ibm_mqcloud_truststore_certificate" "mqcloud_truststore_certificate_instance" {
service_instance_guid = var.mqcloud_truststore_certificate_service_instance_guid
queue_manager_id = var.mqcloud_truststore_certificate_queue_manager_id
label = var.mqcloud_truststore_certificate_label
service_instance_guid = var.data_mqcloud_truststore_certificate_service_instance_guid
queue_manager_id = var.data_mqcloud_truststore_certificate_queue_manager_id
label = var.data_mqcloud_truststore_certificate_label
}
*/

Expand All @@ -96,8 +97,8 @@ data "ibm_mqcloud_truststore_certificate" "mqcloud_truststore_certificate_instan
/*
// Create mqcloud_keystore_certificate data source
data "ibm_mqcloud_keystore_certificate" "mqcloud_keystore_certificate_instance" {
service_instance_guid = var.mqcloud_keystore_certificate_service_instance_guid
queue_manager_id = var.mqcloud_keystore_certificate_queue_manager_id
label = var.mqcloud_keystore_certificate_label
service_instance_guid = var.data_mqcloud_keystore_certificate_service_instance_guid
queue_manager_id = var.data_mqcloud_keystore_certificate_queue_manager_id
label = var.data_mqcloud_keystore_certificate_label
}
*/
62 changes: 25 additions & 37 deletions examples/ibm-mqcloud/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ variable "mqcloud_queue_manager_display_name" {
variable "mqcloud_queue_manager_location" {
description = "The locations in which the queue manager could be deployed."
type = string
default = "reserved-eu-fr-cluster-f884"
default = "reserved-eu-de-cluster-f884"
}
variable "mqcloud_queue_manager_size" {
description = "The queue manager sizes of deployment available. Deployment of lite queue managers for aws_us_east_1 and aws_eu_west_1 locations is not available."
Expand Down Expand Up @@ -53,24 +53,6 @@ variable "mqcloud_user_service_instance_guid" {
type = string
default = "Service Instance ID"
}

// Data source arguments for mqcloud_application
variable "mqcloud_application_service_instance_guid" {
description = "The GUID that uniquely identifies the MQ on Cloud service instance."
type = string
default = "Service Instance ID"
}
variable "mqcloud_user_name" {
description = "The shortname of the user that will be used as the IBM MQ administrator in interactions with a queue manager for this service instance."
type = string
default = "name"
}

variable "mqcloud_application_name" {
description = "The name of the application - conforming to MQ rules."
type = string
default = "name"
}
variable "mqcloud_user_name" {
description = "The shortname of the user that will be used as the IBM MQ administrator in interactions with a queue manager for this service instance."
type = string
Expand All @@ -94,10 +76,15 @@ variable "mqcloud_keystore_certificate_queue_manager_id" {
default = "Queue Manager ID"
}
variable "mqcloud_keystore_certificate_label" {
description = "Certificate label in queue manager store."
description = "The label to use for the certificate to be uploaded."
type = string
default = "label"
}
variable "mqcloud_keystore_certificate_certificate_file" {
description = "The filename and path of the certificate to be uploaded."
type = string
default = "SGVsbG8gd29ybGQ="
}

// Resource arguments for mqcloud_truststore_certificate
variable "mqcloud_truststore_certificate_service_instance_guid" {
Expand All @@ -110,21 +97,24 @@ variable "mqcloud_truststore_certificate_queue_manager_id" {
type = string
default = "Queue Manager ID"
}

variable "mqcloud_truststore_certificate_label" {
description = "Certificate label in queue manager store."
description = "The label to use for the certificate to be uploaded."
type = string
default = "label"
}
variable "mqcloud_truststore_certificate_certificate_file" {
description = "The filename and path of the certificate to be uploaded."
type = string
default = "SGVsbG8gd29ybGQ="
}

// Data source arguments for mqcloud_queue_manager
variable "mqcloud_queue_manager_service_instance_guid" {
variable "data_mqcloud_queue_manager_service_instance_guid" {
description = "The GUID that uniquely identifies the MQ on Cloud service instance."
type = string
default = "Service Instance ID"
}

variable "mqcloud_queue_manager_name" {
variable "data_mqcloud_queue_manager_name" {
description = "A queue manager name conforming to MQ restrictions."
type = string
default = "name"
Expand All @@ -143,60 +133,58 @@ variable "mqcloud_queue_manager_status_queue_manager_id" {
}

// Data source arguments for mqcloud_application
variable "mqcloud_application_service_instance_guid" {
variable "data_mqcloud_application_service_instance_guid" {
description = "The GUID that uniquely identifies the MQ on Cloud service instance."
type = string
default = "Service Instance ID"
}

variable "mqcloud_application_name" {
variable "data_mqcloud_application_name" {
description = "The name of the application - conforming to MQ rules."
type = string
default = "name"
}

// Data source arguments for mqcloud_user
variable "mqcloud_user_service_instance_guid" {
variable "data_mqcloud_user_service_instance_guid" {
description = "The GUID that uniquely identifies the MQ on Cloud service instance."
type = string
default = "Service Instance ID"
}

variable "mqcloud_user_name" {
variable "data_mqcloud_user_name" {
description = "The shortname of the user that will be used as the IBM MQ administrator in interactions with a queue manager for this service instance."
type = string
default = "name"
}

// Data source arguments for mqcloud_truststore_certificate
variable "mqcloud_truststore_certificate_service_instance_guid" {
variable "data_mqcloud_truststore_certificate_service_instance_guid" {
description = "The GUID that uniquely identifies the MQ on Cloud service instance."
type = string
default = "Service Instance ID"
}
variable "mqcloud_truststore_certificate_queue_manager_id" {
variable "data_mqcloud_truststore_certificate_queue_manager_id" {
description = "The id of the queue manager to retrieve its full details."
type = string
default = "Queue Manager ID"
}
variable "mqcloud_truststore_certificate_label" {
variable "data_mqcloud_truststore_certificate_label" {
description = "Certificate label in queue manager store."
type = string
default = "label"
}

// Data source arguments for mqcloud_keystore_certificate
variable "mqcloud_keystore_certificate_service_instance_guid" {
variable "data_mqcloud_keystore_certificate_service_instance_guid" {
description = "The GUID that uniquely identifies the MQ on Cloud service instance."
type = string
default = "Service Instance ID"
}
variable "mqcloud_keystore_certificate_queue_manager_id" {
variable "data_mqcloud_keystore_certificate_queue_manager_id" {
description = "The id of the queue manager to retrieve its full details."
type = string
default = "Queue Manager ID"
}
variable "mqcloud_keystore_certificate_label" {
variable "data_mqcloud_keystore_certificate_label" {
description = "Certificate label in queue manager store."
type = string
default = "label"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ require (
)

require (
github.com/IBM/mqcloud-go-sdk v0.0.0-20231207105140-14d858932788
github.com/IBM/mqcloud-go-sdk v0.0.4
github.com/IBM/sarama v1.41.2
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
sigs.k8s.io/controller-runtime v0.14.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYt
github.com/IBM/keyprotect-go-client v0.5.1/go.mod h1:5TwDM/4FRJq1ZOlwQL1xFahLWQ3TveR88VmL1u3njyI=
github.com/IBM/keyprotect-go-client v0.12.2 h1:Cjxcqin9Pl0xz3MnxdiVd4v/eIa79xL3hQpSbwOr/DQ=
github.com/IBM/keyprotect-go-client v0.12.2/go.mod h1:yr8h2noNgU8vcbs+vhqoXp3Lmv73PI0zAc6VMgFvWwM=
github.com/IBM/mqcloud-go-sdk v0.0.0-20231207105140-14d858932788 h1:cIT0YSzqMGqxM3OJQx1gp4gtYYy9U35O0tVdcFHOgwc=
github.com/IBM/mqcloud-go-sdk v0.0.0-20231207105140-14d858932788/go.mod h1:R4NBbDMygpHiFywUnOdV0UfBZap4HcHa3QXLlACr9TU=
github.com/IBM/mqcloud-go-sdk v0.0.4 h1:gqMpoU5a0qJ0GETG4PQrkgeEEoaQLvbxRJnEe6ytvC4=
github.com/IBM/mqcloud-go-sdk v0.0.4/go.mod h1:gQptHC6D+rxfg0muRFFGvTDmvl4YfiDE0uXkaRRewRk=
github.com/IBM/networking-go-sdk v0.42.2 h1:caqjx4jyFHi10Vlf3skHvlL6K3YJRVstsmCBmvdyqkA=
github.com/IBM/networking-go-sdk v0.42.2/go.mod h1:lTUZwtUkMANMnrLHFIgRhHrkBfwASY/Iho1fabaPHxo=
github.com/IBM/platform-services-go-sdk v0.55.0 h1:W598xZanL61bwd8O2DQexr4qjIr+/tP0Y845zoms5yA=
Expand Down
42 changes: 37 additions & 5 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ var (

// MQ on Cloud
var (
MqcloudInstanceID string
MqcloudQueueManagerID string
MqcloudKSCertFilePath string
MqcloudTSCertFilePath string
MqcloudConfigEndpoint string
MqcloudInstanceID string
MqcloudQueueManagerID string
MqcloudKSCertFilePath string
MqcloudTSCertFilePath string
MqCloudQueueManagerLocation string
MqCloudQueueManagerVersion string
MqCloudQueueManagerVersionUpdate string
)

// Secrets Manager
Expand Down Expand Up @@ -1591,11 +1595,15 @@ func init() {
fmt.Println("[WARN] Set the environment variable IBM_SATELLITE_SSH_PUB_KEY with a ssh public key or ibm_satellite_* tests may fail")
}

MqcloudConfigEndpoint = os.Getenv("IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT")
if MqcloudConfigEndpoint == "" {
fmt.Println("[INFO] Set the environment variable IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT for ibm_mqcloud service else tests will fail if this is not set correctly")
}

MqcloudInstanceID = os.Getenv("IBM_MQCLOUD_INSTANCE_ID")
if MqcloudInstanceID == "" {
fmt.Println("[INFO] Set the environment variable IBM_MQCLOUD_INSTANCE_ID for ibm_mqcloud_queue_manager resource or datasource else tests will fail if this is not set correctly")
}

MqcloudQueueManagerID = os.Getenv("IBM_MQCLOUD_QUEUEMANAGER_ID")
if MqcloudQueueManagerID == "" {
fmt.Println("[INFO] Set the environment variable IBM_MQCLOUD_QUEUEMANAGER_ID for ibm_mqcloud_queue_manager resource or datasource else tests will fail if this is not set correctly")
Expand All @@ -1608,6 +1616,18 @@ func init() {
if MqcloudTSCertFilePath == "" {
fmt.Println("[INFO] Set the environment variable IBM_MQCLOUD_TS_CERT_PATH for ibm_mqcloud_truststore_certificate resource or datasource else tests will fail if this is not set correctly")
}
MqCloudQueueManagerLocation = os.Getenv(("IBM_MQCLOUD_QUEUEMANAGER_LOCATION"))
if MqCloudQueueManagerLocation == "" {
fmt.Println("[INFO] Set the environment variable IBM_MQCLOUD_QUEUEMANAGER_LOCATION for ibm_mqcloud_queue_manager resource or datasource else tests will fail if this is not set correctly")
}
MqCloudQueueManagerVersion = os.Getenv(("IBM_MQCLOUD_QUEUEMANAGER_VERSION"))
if MqCloudQueueManagerVersion == "" {
fmt.Println("[INFO] Set the environment variable IBM_MQCLOUD_QUEUEMANAGER_VERSION for ibm_mqcloud_queue_manager resource or datasource else tests will fail if this is not set correctly")
}
MqCloudQueueManagerVersionUpdate = os.Getenv(("IBM_MQCLOUD_QUEUEMANAGER_VERSIONUPDATE"))
if MqCloudQueueManagerVersionUpdate == "" {
fmt.Println("[INFO] Set the environment variable IBM_MQCLOUD_QUEUEMANAGER_VERSIONUPDATE for ibm_mqcloud_queue_manager resource or datasource else tests will fail if this is not set correctly")
}
}

var (
Expand Down Expand Up @@ -1821,6 +1841,9 @@ func TestAccPreCheckSatelliteSSH(t *testing.T) {

func TestAccPreCheckMqcloud(t *testing.T) {
TestAccPreCheck(t)
if MqcloudConfigEndpoint == "" {
t.Fatal("IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT must be set for acceptance tests")
}
if MqcloudInstanceID == "" {
t.Fatal("IBM_MQCLOUD_INSTANCE_ID must be set for acceptance tests")
}
Expand All @@ -1833,6 +1856,15 @@ func TestAccPreCheckMqcloud(t *testing.T) {
if MqcloudKSCertFilePath == "" {
t.Fatal("IBM_MQCLOUD_KS_CERT_PATH must be set for acceptance tests")
}
if MqCloudQueueManagerLocation == "" {
t.Fatal("IBM_MQCLOUD_QUEUEMANAGER_LOCATION must be set for acceptance tests")
}
if MqCloudQueueManagerVersion == "" {
t.Fatal("IBM_MQCLOUD_QUEUEMANAGER_VERSION must be set for acceptance tests")
}
if MqCloudQueueManagerVersionUpdate == "" {
t.Fatal("IBM_MQCLOUD_QUEUEMANAGER_VERSIONUPDATE must be set for acceptance tests")
}
}

func TestAccProviderFactories() map[string]func() (*schema.Provider, error) {
Expand Down
22 changes: 13 additions & 9 deletions ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,12 @@ func (session clientSession) ProjectV1() (*project.ProjectV1, error) {

// MQ on Cloud
func (session clientSession) MqcloudV1() (*mqcloudv1.MqcloudV1, error) {
sessionMqcloudClient := session.mqcloudClient
sessionMqcloudClient.EnableRetries(0, 0)
return session.mqcloudClient, session.mqcloudClientErr
if session.mqcloudClientErr != nil {
sessionMqcloudClient := session.mqcloudClient
sessionMqcloudClient.EnableRetries(0, 0)
return session.mqcloudClient, session.mqcloudClientErr
}
return session.mqcloudClient.Clone(), nil
}

// ClientSession configures and returns a fully initialized ClientSession
Expand Down Expand Up @@ -3266,23 +3269,24 @@ func (c *Config) ClientSession() (interface{}, error) {
if fileMap != nil && c.Visibility != "public-and-private" {
mqCloudURL = fileFallBack(fileMap, c.Visibility, "IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT", c.Region, mqCloudURL)
}

accept_language := os.Getenv("IBMCLOUD_MQCLOUD_ACCEPT_LANGUAGE")
mqcloudClientOptions := &mqcloudv1.MqcloudV1Options{
Authenticator: authenticator,
URL: EnvFallBack([]string{"IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT"}, mqCloudURL),
Authenticator: authenticator,
AcceptLanguage: core.StringPtr(accept_language),
URL: EnvFallBack([]string{"IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT"}, mqCloudURL),
}

// Construct the service client for MQ Cloud.
session.mqcloudClient, err = mqcloudv1.NewMqcloudV1(mqcloudClientOptions)
if err != nil {
session.mqcloudClientErr = fmt.Errorf("Error occurred while configuring MQ Cloud service: %q", err)
} else {
if err == nil {
// Enable retries for API calls
session.mqcloudClient.Service.EnableRetries(c.RetryCount, c.RetryDelay)
// Add custom header for analytics
session.mqcloudClient.SetDefaultHeaders(gohttp.Header{
"X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)},
})
} else {
session.mqcloudClientErr = fmt.Errorf("Error occurred while configuring MQ on Cloud service: %q", err)
}

// Construct the service options.
Expand Down
Loading

0 comments on commit af9f5f3

Please sign in to comment.