From 59a6f7361f205085b2e5501c0b5be5dbfe700998 Mon Sep 17 00:00:00 2001 From: IBM-Deeksha Date: Fri, 9 Aug 2024 20:49:16 +0530 Subject: [PATCH] fix: read endpoint type from schema (#5552) * fix: read endpoint type from schema * add empty string check * update code --------- Co-authored-by: Deeksha Sharma --- ibm/service/cos/data_source_ibm_cos_bucket.go | 4 +++- ibm/service/cos/resource_ibm_cos_bucket.go | 23 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ibm/service/cos/data_source_ibm_cos_bucket.go b/ibm/service/cos/data_source_ibm_cos_bucket.go index 6ad75ed0e6..24e7c74ad9 100644 --- a/ibm/service/cos/data_source_ibm_cos_bucket.go +++ b/ibm/service/cos/data_source_ibm_cos_bucket.go @@ -729,7 +729,9 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error // User is expected to define both private and direct url type under "private" in endpoints file since visibility type "direct" is not supported. cosConfigURL := conns.FileFallBack(rsConClient.Config.EndpointsFile, "private", "IBMCLOUD_COS_CONFIG_ENDPOINT", bucketRegion, cosConfigUrls[endpointType]) cosConfigURL = conns.EnvFallBack([]string{"IBMCLOUD_COS_CONFIG_ENDPOINT"}, cosConfigURL) - sess.SetServiceURL(cosConfigURL) + if cosConfigURL != "" { + sess.SetServiceURL(cosConfigURL) + } } if bucketType == "sl" { diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 7485a514ab..32850cd514 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -743,6 +743,9 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error bucketName := parseBucketId(d.Id(), "bucketName") serviceID := parseBucketId(d.Id(), "serviceID") endpointType := parseBucketId(d.Id(), "endpointType") + if endpointType == "" { + endpointType = d.Get("endpoint_type").(string) + } bLocation := parseBucketId(d.Id(), "bLocation") apiType := parseBucketId(d.Id(), "apiType") if apiType == "sl" { @@ -939,7 +942,9 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error // User is expected to define both private and direct url type under "private" in endpoints file since visibility type "direct" is not supported. cosConfigURL := conns.FileFallBack(rsConClient.Config.EndpointsFile, "private", "IBMCLOUD_COS_CONFIG_ENDPOINT", bLocation, cosConfigUrls[endpointType]) cosConfigURL = conns.EnvFallBack([]string{"IBMCLOUD_COS_CONFIG_ENDPOINT"}, cosConfigURL) - sess.SetServiceURL(cosConfigURL) + if cosConfigURL != "" { + sess.SetServiceURL(cosConfigURL) + } } if apiType == "sl" { @@ -1087,6 +1092,9 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { bucketName := parseBucketId(d.Id(), "bucketName") serviceID := parseBucketId(d.Id(), "serviceID") endpointType := parseBucketId(d.Id(), "endpointType") + if endpointType == "" { + endpointType = d.Get("endpoint_type").(string) + } apiType := parseBucketId(d.Id(), "apiType") bLocation := parseBucketId(d.Id(), "bLocation") @@ -1208,7 +1216,9 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { // User is expected to define both private and direct url type under "private" in endpoints file since visibility type "direct" is not supported. cosConfigURL := conns.FileFallBack(rsConClient.Config.EndpointsFile, "private", "IBMCLOUD_COS_CONFIG_ENDPOINT", bLocation, cosConfigUrls[endpointType]) cosConfigURL = conns.EnvFallBack([]string{"IBMCLOUD_COS_CONFIG_ENDPOINT"}, cosConfigURL) - sess.SetServiceURL(cosConfigURL) + if cosConfigURL != "" { + sess.SetServiceURL(cosConfigURL) + } } if apiType == "sl" { @@ -1513,7 +1523,9 @@ func resourceIBMCOSBucketDelete(d *schema.ResourceData, meta interface{}) error } endpointType := parseBucketId(d.Id(), "endpointType") - + if endpointType == "" { + endpointType = d.Get("endpoint_type").(string) + } var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string if apiType == "sl" { @@ -1638,8 +1650,11 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, apiType := parseBucketId(d.Id(), "apiType") bLocation := parseBucketId(d.Id(), "bLocation") - endpointType := parseBucketId(d.Id(), "endpointType") + endpointType := parseBucketId(d.Id(), "endpointType") + if endpointType == "" { + endpointType = d.Get("endpoint_type").(string) + } if apiType == "sl" { satloc_guid := strings.Split(serviceID, ":") bucketsatcrn := satloc_guid[0]