From 3e7a0d32c1c4567df4e4a50d357ab2cd4f6537d9 Mon Sep 17 00:00:00 2001 From: IBM-Deeksha Date: Thu, 18 Jul 2024 13:21:59 +0530 Subject: [PATCH] Clevos 94481 read from endpointsfile (#5517) * remove hardcoded values for private and direct cos config endpoint. Use defaults values when no env variables are set * update code * update code * remove extra space * update code * update comment * udpate documentation * documentation update for issue #4819 * update doc * read from endpoints file --------- Co-authored-by: Deeksha Sharma --- ibm/service/cos/resource_ibm_cos_bucket.go | 7 +++++-- ibm/service/cos/resource_ibm_cos_bucket_object.go | 5 +++++ .../cos/resource_ibm_cos_replication_configuration.go | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 3e5656def6..7485a514ab 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -1101,8 +1101,8 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { serviceID = bucketsatcrn } - var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint string - + var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint, visibility string + visibility = endpointType if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { @@ -1112,11 +1112,14 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { apiEndpoint = apiEndpointPrivate } if endpointType == "direct" { + // visibility type "direct" is not supported in endpoints file. + visibility = "private" apiEndpoint = directApiEndpoint } } + apiEndpoint = conns.FileFallBack(rsConClient.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) authEndpoint, err := rsConClient.Config.EndpointLocator.IAMEndpoint() diff --git a/ibm/service/cos/resource_ibm_cos_bucket_object.go b/ibm/service/cos/resource_ibm_cos_bucket_object.go index 9b7afa0cf6..e907534138 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket_object.go +++ b/ibm/service/cos/resource_ibm_cos_bucket_object.go @@ -494,8 +494,13 @@ func getCosEndpoint(bucketLocation string, endpointType string) string { func getS3Client(bxSession *bxsession.Session, bucketLocation string, endpointType string, instanceCRN string) (*s3.S3, error) { var s3Conf *aws.Config + visibility := endpointType + if endpointType == "direct" { + visibility = "private" + } apiEndpoint := getCosEndpoint(bucketLocation, endpointType) + apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) if apiEndpoint == "" { return nil, fmt.Errorf("the endpoint doesn't exists for given location %s and endpoint type %s", bucketLocation, endpointType) diff --git a/ibm/service/cos/resource_ibm_cos_replication_configuration.go b/ibm/service/cos/resource_ibm_cos_replication_configuration.go index 46129d2986..f805ace41f 100644 --- a/ibm/service/cos/resource_ibm_cos_replication_configuration.go +++ b/ibm/service/cos/resource_ibm_cos_replication_configuration.go @@ -353,7 +353,13 @@ func getCosEndpointType(bucketLocation string, endpointType string) string { func getS3ClientSession(bxSession *bxsession.Session, bucketLocation string, endpointType string, instanceCRN string) (*s3.S3, error) { var s3Conf *aws.Config + visibility := endpointType + if endpointType == "direct" { + visibility = "private" + } + apiEndpoint := getCosEndpointType(bucketLocation, endpointType) + apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) if apiEndpoint == "" { return nil, fmt.Errorf("the endpoint doesn't exists for given location %s and endpoint type %s", bucketLocation, endpointType)