From 164a06176a7b3f2c5f26fe1a70294f5c2c6d5b10 Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Wed, 11 Sep 2024 18:03:17 +0530 Subject: [PATCH 1/7] add changes for test bucket endpoints --- ibm/service/cos/data_source_ibm_cos_bucket.go | 4 ++- ibm/service/cos/resource_ibm_cos_bucket.go | 34 +++++++++++-------- .../cos/resource_ibm_cos_bucket_object.go | 18 ++++++---- .../cos/resource_ibm_cos_bucket_test.go | 2 +- ...ource_ibm_cos_replication_configuration.go | 20 +++++++---- 5 files changed, 48 insertions(+), 30 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..71767f3cc5 100644 --- a/ibm/service/cos/data_source_ibm_cos_bucket.go +++ b/ibm/service/cos/data_source_ibm_cos_bucket.go @@ -598,6 +598,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error if err != nil { return err } + testEnv := false bucketName := d.Get("bucket_name").(string) serviceID := d.Get("resource_instance_id").(string) bucketType := d.Get("bucket_type").(string) @@ -621,7 +622,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error apiEndpoint = SelectSatlocCosApi(bucketType, serviceID, satlc_id) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, testEnv) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -718,6 +719,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error bucketCRN := fmt.Sprintf("%s:%s:%s", strings.Replace(serviceID, "::", "", -1), "bucket", bucketName) d.Set("crn", bucketCRN) d.Set("resource_instance_id", serviceID) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, strings.Contains(apiEndpoint, "test")) d.Set("s3_endpoint_public", apiEndpoint) d.Set("s3_endpoint_private", apiEndpointPrivate) d.Set("s3_endpoint_direct", directApiEndpoint) diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 7485a514ab..5369d6456f 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -750,13 +750,13 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error bucketsatcrn := satloc_guid[0] serviceID = bucketsatcrn } - + testEnv := false var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1100,13 +1100,13 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { bucketsatcrn := satloc_guid[0] serviceID = bucketsatcrn } - + testEnv := false var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint, visibility string visibility = endpointType if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) apiEndpoint = apiEndpointPublic if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1194,6 +1194,8 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { d.Set("crn", bucketCRN) d.Set("resource_instance_id", serviceID) d.Set("bucket_name", bucketName) + + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, strings.Contains(apiEndpoint, "test")) d.Set("s3_endpoint_public", apiEndpointPublic) d.Set("s3_endpoint_private", apiEndpointPrivate) d.Set("s3_endpoint_direct", directApiEndpoint) @@ -1391,13 +1393,13 @@ func resourceIBMCOSBucketCreate(d *schema.ResourceData, meta interface{}) error lConstraint := fmt.Sprintf("%s-%s", bLocation, storageClass) var endpointType = d.Get("endpoint_type").(string) - + testEnv := false var apiEndpoint, privateApiEndpoint, directApiEndpoint, visibility string if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation) + apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) visibility = endpointType if endpointType == "private" { apiEndpoint = privateApiEndpoint @@ -1515,13 +1517,13 @@ func resourceIBMCOSBucketDelete(d *schema.ResourceData, meta interface{}) error endpointType := parseBucketId(d.Id(), "endpointType") var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string - + testEnv := false if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1647,13 +1649,13 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, } var apiEndpoint, apiEndpointPrivate, directApiEndpoint string - + testEnv := false if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) if endpointType == "private" { apiEndpoint = apiEndpointPrivate } @@ -1707,15 +1709,19 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, return false, nil } -func SelectCosApi(apiType string, bLocation string) (string, string, string) { +func SelectCosApi(apiType string, bLocation string, test bool) (string, string, string) { + hostUrl := "cloud-object-storage.appdomain.cloud" + if test { + hostUrl = "cloud-object-storage.test.appdomain.cloud" + } if apiType == "crl" { - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bLocation) + return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl) } if apiType == "rl" { - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bLocation) + return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl) } if apiType == "ssl" { - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bLocation) + return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl) } return "", "", "" } diff --git a/ibm/service/cos/resource_ibm_cos_bucket_object.go b/ibm/service/cos/resource_ibm_cos_bucket_object.go index e907534138..b357e09f04 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket_object.go +++ b/ibm/service/cos/resource_ibm_cos_bucket_object.go @@ -476,17 +476,21 @@ func resourceIBMCOSBucketObjectDelete(ctx context.Context, d *schema.ResourceDat return nil } -func getCosEndpoint(bucketLocation string, endpointType string) string { +func getCosEndpoint(bucketLocation string, endpointType string, test bool) string { if bucketLocation != "" { + hostUrl := "cloud-object-storage.appdomain.cloud" + if test { + hostUrl = "cloud-object-storage.test.appdomain.cloud" + } switch endpointType { case "public": - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl) case "private": - return fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.private.%s.%s", bucketLocation, hostUrl) case "direct": - return fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.direct.%s.%s", bucketLocation, hostUrl) default: - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl) } } return "" @@ -498,8 +502,8 @@ func getS3Client(bxSession *bxsession.Session, bucketLocation string, endpointTy if endpointType == "direct" { visibility = "private" } - - apiEndpoint := getCosEndpoint(bucketLocation, endpointType) + testEnv := false + apiEndpoint := getCosEndpoint(bucketLocation, endpointType, testEnv) apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) if apiEndpoint == "" { diff --git a/ibm/service/cos/resource_ibm_cos_bucket_test.go b/ibm/service/cos/resource_ibm_cos_bucket_test.go index 8cc51802de..1a27c0ba49 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket_test.go +++ b/ibm/service/cos/resource_ibm_cos_bucket_test.go @@ -2242,7 +2242,7 @@ func testAccCheckIBMCosBucketExists(resource string, bucket string, regiontype s rt = "crl" } - apiEndpoint, _, _ := cos.SelectCosApi(rt, region) + apiEndpoint, _, _ := cos.SelectCosApi(rt, region, false) rsContClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixSession() if err != nil { diff --git a/ibm/service/cos/resource_ibm_cos_replication_configuration.go b/ibm/service/cos/resource_ibm_cos_replication_configuration.go index f805ace41f..79aa7ff9d8 100644 --- a/ibm/service/cos/resource_ibm_cos_replication_configuration.go +++ b/ibm/service/cos/resource_ibm_cos_replication_configuration.go @@ -334,19 +334,25 @@ func parseBucketReplId(id string, info string) string { return parseBucketId(bucketCRN, info) } -func getCosEndpointType(bucketLocation string, endpointType string) string { +func getCosEndpointType(bucketLocation string, endpointType string, test bool) string { + if bucketLocation != "" { + hostUrl := "cloud-object-storage.appdomain.cloud" + if test { + hostUrl = "cloud-object-storage.test.appdomain.cloud" + } switch endpointType { case "public": - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl) case "private": - return fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.private.%s.%s", bucketLocation, hostUrl) case "direct": - return fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.direct.%s.%s", bucketLocation, hostUrl) default: - return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation) + return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl) } } + return "" } @@ -357,8 +363,8 @@ func getS3ClientSession(bxSession *bxsession.Session, bucketLocation string, end if endpointType == "direct" { visibility = "private" } - - apiEndpoint := getCosEndpointType(bucketLocation, endpointType) + testEnv := false + apiEndpoint := getCosEndpointType(bucketLocation, endpointType, testEnv) apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) if apiEndpoint == "" { From 132ef1a3c8738375db1ef0b67f5b39dd4309977f Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Wed, 11 Sep 2024 18:08:35 +0530 Subject: [PATCH 2/7] update code --- ibm/service/cos/data_source_ibm_cos_bucket.go | 3 +-- ibm/service/cos/resource_ibm_cos_bucket.go | 16 ++++++---------- .../cos/resource_ibm_cos_bucket_object.go | 3 +-- ...resource_ibm_cos_replication_configuration.go | 3 +-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/ibm/service/cos/data_source_ibm_cos_bucket.go b/ibm/service/cos/data_source_ibm_cos_bucket.go index be28e9da3c..1e8316b38e 100644 --- a/ibm/service/cos/data_source_ibm_cos_bucket.go +++ b/ibm/service/cos/data_source_ibm_cos_bucket.go @@ -598,7 +598,6 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error if err != nil { return err } - testEnv := false bucketName := d.Get("bucket_name").(string) serviceID := d.Get("resource_instance_id").(string) bucketType := d.Get("bucket_type").(string) @@ -622,7 +621,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error apiEndpoint = SelectSatlocCosApi(bucketType, serviceID, satlc_id) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, testEnv) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, false) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 012a1f8d55..9637374383 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -753,13 +753,13 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error bucketsatcrn := satloc_guid[0] serviceID = bucketsatcrn } - testEnv := false + var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1108,13 +1108,12 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { bucketsatcrn := satloc_guid[0] serviceID = bucketsatcrn } - testEnv := false var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint, visibility string visibility = endpointType if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) apiEndpoint = apiEndpointPublic if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1403,13 +1402,12 @@ func resourceIBMCOSBucketCreate(d *schema.ResourceData, meta interface{}) error lConstraint := fmt.Sprintf("%s-%s", bLocation, storageClass) var endpointType = d.Get("endpoint_type").(string) - testEnv := false var apiEndpoint, privateApiEndpoint, directApiEndpoint, visibility string if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation, false) visibility = endpointType if endpointType == "private" { apiEndpoint = privateApiEndpoint @@ -1529,13 +1527,12 @@ func resourceIBMCOSBucketDelete(d *schema.ResourceData, meta interface{}) error endpointType = d.Get("endpoint_type").(string) } var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string - testEnv := false if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1664,13 +1661,12 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, } var apiEndpoint, apiEndpointPrivate, directApiEndpoint string - testEnv := false if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) if endpointType == "private" { apiEndpoint = apiEndpointPrivate } diff --git a/ibm/service/cos/resource_ibm_cos_bucket_object.go b/ibm/service/cos/resource_ibm_cos_bucket_object.go index b357e09f04..4868e74064 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket_object.go +++ b/ibm/service/cos/resource_ibm_cos_bucket_object.go @@ -502,8 +502,7 @@ func getS3Client(bxSession *bxsession.Session, bucketLocation string, endpointTy if endpointType == "direct" { visibility = "private" } - testEnv := false - apiEndpoint := getCosEndpoint(bucketLocation, endpointType, testEnv) + apiEndpoint := getCosEndpoint(bucketLocation, endpointType, false) apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) if apiEndpoint == "" { diff --git a/ibm/service/cos/resource_ibm_cos_replication_configuration.go b/ibm/service/cos/resource_ibm_cos_replication_configuration.go index 79aa7ff9d8..fbd461d899 100644 --- a/ibm/service/cos/resource_ibm_cos_replication_configuration.go +++ b/ibm/service/cos/resource_ibm_cos_replication_configuration.go @@ -363,8 +363,7 @@ func getS3ClientSession(bxSession *bxsession.Session, bucketLocation string, end if endpointType == "direct" { visibility = "private" } - testEnv := false - apiEndpoint := getCosEndpointType(bucketLocation, endpointType, testEnv) + apiEndpoint := getCosEndpointType(bucketLocation, endpointType, false) apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint) apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) if apiEndpoint == "" { From 9aedf43572cd0c83f85a4909303cdddaa55bf389 Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Tue, 1 Oct 2024 10:53:01 +0530 Subject: [PATCH 3/7] fix for test cloud account url --- ibm/service/cos/resource_ibm_cos_bucket.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 9637374383..2788441d1d 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -1202,10 +1202,16 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { d.Set("resource_instance_id", serviceID) d.Set("bucket_name", bucketName) - apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, strings.Contains(apiEndpoint, "test")) - d.Set("s3_endpoint_public", apiEndpointPublic) - d.Set("s3_endpoint_private", apiEndpointPrivate) - d.Set("s3_endpoint_direct", directApiEndpoint) + testEnv := strings.Contains(apiEndpoint, ".test.") + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + + if testEnv { + d.Set(fmt.Sprintf("s3_endpoint_%s", endpointType), apiEndpoint) + } else { + d.Set("s3_endpoint_public", apiEndpointPublic) + d.Set("s3_endpoint_private", apiEndpointPrivate) + d.Set("s3_endpoint_direct", directApiEndpoint) + } if endpointType != "" { d.Set("endpoint_type", endpointType) } @@ -1225,7 +1231,6 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { if apiType == "sl" { satconfig := fmt.Sprintf("https://config.%s.%s.cloud-object-storage.appdomain.cloud/v1", serviceID, bLocation) - sess.SetServiceURL(satconfig) } @@ -1673,7 +1678,6 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, if endpointType == "direct" { apiEndpoint = directApiEndpoint } - } apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint) From 33a271f3d3f586ca1aacbcc02b7bbf28fb0710aa Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Thu, 3 Oct 2024 16:38:22 +0530 Subject: [PATCH 4/7] fix endpoints in datasource --- ibm/service/cos/data_source_ibm_cos_bucket.go | 16 +++++++++++----- 1 file changed, 11 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 653fe61390..e1efc526da 100644 --- a/ibm/service/cos/data_source_ibm_cos_bucket.go +++ b/ibm/service/cos/data_source_ibm_cos_bucket.go @@ -700,7 +700,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error keyProtectFlag = true } - var satlc_id, apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string + var satlc_id, apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint, visibility string if satlc, ok := d.GetOk("satellite_location_id"); ok { satlc_id = satlc.(string) @@ -811,10 +811,16 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error bucketCRN := fmt.Sprintf("%s:%s:%s", strings.Replace(serviceID, "::", "", -1), "bucket", bucketName) d.Set("crn", bucketCRN) d.Set("resource_instance_id", serviceID) - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, strings.Contains(apiEndpoint, "test")) - d.Set("s3_endpoint_public", apiEndpoint) - d.Set("s3_endpoint_private", apiEndpointPrivate) - d.Set("s3_endpoint_direct", directApiEndpoint) + + testEnv := strings.Contains(apiEndpoint, ".test.") + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, testEnv) + if testEnv { + d.Set(fmt.Sprintf("s3_endpoint_%s", endpointType), apiEndpoint) + } else { + d.Set("s3_endpoint_public", apiEndpointPublic) + d.Set("s3_endpoint_private", apiEndpointPrivate) + d.Set("s3_endpoint_direct", directApiEndpoint) + } sess, err := meta.(conns.ClientSession).CosConfigV1API() if err != nil { return err From 483e3e44deca5c7d986d331c51b9baa0b741ac46 Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Fri, 4 Oct 2024 10:05:19 +0530 Subject: [PATCH 5/7] add FileFallBack check to IBMCOSBucketExists --- ibm/service/cos/resource_ibm_cos_bucket.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 0035bc30fd..1d9136ff7c 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -1685,21 +1685,27 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, serviceID = bucketsatcrn } - var apiEndpoint, apiEndpointPrivate, directApiEndpoint string + var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) + visibility = endpointType if endpointType == "private" { 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) if apiEndpoint == "" { From 5fca25535cd9f4bb56bf0088c3a2cc07ebfe5467 Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Fri, 4 Oct 2024 10:10:30 +0530 Subject: [PATCH 6/7] remove hardcoded test cloud url --- ibm/service/cos/resource_ibm_cos_bucket.go | 17 +++++++---------- .../cos/resource_ibm_cos_bucket_object.go | 7 ++----- ...esource_ibm_cos_replication_configuration.go | 7 ++----- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/ibm/service/cos/resource_ibm_cos_bucket.go b/ibm/service/cos/resource_ibm_cos_bucket.go index 1d9136ff7c..8151953f86 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket.go +++ b/ibm/service/cos/resource_ibm_cos_bucket.go @@ -762,7 +762,7 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1129,7 +1129,7 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { if apiType == "sl" { apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) apiEndpoint = apiEndpointPublic if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1219,7 +1219,7 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error { d.Set("bucket_name", bucketName) testEnv := strings.Contains(apiEndpoint, ".test.") - apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, testEnv) + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) if testEnv { d.Set(fmt.Sprintf("s3_endpoint_%s", endpointType), apiEndpoint) @@ -1432,7 +1432,7 @@ func resourceIBMCOSBucketCreate(d *schema.ResourceData, meta interface{}) error apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation, false) + apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation) visibility = endpointType if endpointType == "private" { apiEndpoint = privateApiEndpoint @@ -1557,7 +1557,7 @@ func resourceIBMCOSBucketDelete(d *schema.ResourceData, meta interface{}) error apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1691,7 +1691,7 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -1750,11 +1750,8 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool, return false, nil } -func SelectCosApi(apiType string, bLocation string, test bool) (string, string, string) { +func SelectCosApi(apiType string, bLocation string) (string, string, string) { hostUrl := "cloud-object-storage.appdomain.cloud" - if test { - hostUrl = "cloud-object-storage.test.appdomain.cloud" - } if apiType == "crl" { return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl) } diff --git a/ibm/service/cos/resource_ibm_cos_bucket_object.go b/ibm/service/cos/resource_ibm_cos_bucket_object.go index 4868e74064..e18678b28f 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket_object.go +++ b/ibm/service/cos/resource_ibm_cos_bucket_object.go @@ -476,12 +476,9 @@ func resourceIBMCOSBucketObjectDelete(ctx context.Context, d *schema.ResourceDat return nil } -func getCosEndpoint(bucketLocation string, endpointType string, test bool) string { +func getCosEndpoint(bucketLocation string, endpointType string) string { if bucketLocation != "" { hostUrl := "cloud-object-storage.appdomain.cloud" - if test { - hostUrl = "cloud-object-storage.test.appdomain.cloud" - } switch endpointType { case "public": return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl) @@ -502,7 +499,7 @@ func getS3Client(bxSession *bxsession.Session, bucketLocation string, endpointTy if endpointType == "direct" { visibility = "private" } - apiEndpoint := getCosEndpoint(bucketLocation, endpointType, false) + 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 == "" { diff --git a/ibm/service/cos/resource_ibm_cos_replication_configuration.go b/ibm/service/cos/resource_ibm_cos_replication_configuration.go index fbd461d899..d60b920565 100644 --- a/ibm/service/cos/resource_ibm_cos_replication_configuration.go +++ b/ibm/service/cos/resource_ibm_cos_replication_configuration.go @@ -334,13 +334,10 @@ func parseBucketReplId(id string, info string) string { return parseBucketId(bucketCRN, info) } -func getCosEndpointType(bucketLocation string, endpointType string, test bool) string { +func getCosEndpointType(bucketLocation string, endpointType string) string { if bucketLocation != "" { hostUrl := "cloud-object-storage.appdomain.cloud" - if test { - hostUrl = "cloud-object-storage.test.appdomain.cloud" - } switch endpointType { case "public": return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl) @@ -363,7 +360,7 @@ func getS3ClientSession(bxSession *bxsession.Session, bucketLocation string, end if endpointType == "direct" { visibility = "private" } - apiEndpoint := getCosEndpointType(bucketLocation, endpointType, false) + 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 == "" { From 2cbc5e7e5c1f80435659a9b833ac07df9e7262a2 Mon Sep 17 00:00:00 2001 From: Deeksha Sharma Date: Fri, 11 Oct 2024 10:52:20 +0530 Subject: [PATCH 7/7] update code --- ibm/service/cos/data_source_ibm_cos_bucket.go | 4 ++-- ibm/service/cos/resource_ibm_cos_bucket_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ibm/service/cos/data_source_ibm_cos_bucket.go b/ibm/service/cos/data_source_ibm_cos_bucket.go index e1efc526da..156cf021c2 100644 --- a/ibm/service/cos/data_source_ibm_cos_bucket.go +++ b/ibm/service/cos/data_source_ibm_cos_bucket.go @@ -714,7 +714,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error apiEndpoint = SelectSatlocCosApi(bucketType, serviceID, satlc_id) } else { - apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, false) + apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion) visibility = endpointType if endpointType == "private" { apiEndpoint = apiEndpointPrivate @@ -813,7 +813,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error d.Set("resource_instance_id", serviceID) testEnv := strings.Contains(apiEndpoint, ".test.") - apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, testEnv) + apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion) if testEnv { d.Set(fmt.Sprintf("s3_endpoint_%s", endpointType), apiEndpoint) } else { diff --git a/ibm/service/cos/resource_ibm_cos_bucket_test.go b/ibm/service/cos/resource_ibm_cos_bucket_test.go index 1a27c0ba49..8cc51802de 100644 --- a/ibm/service/cos/resource_ibm_cos_bucket_test.go +++ b/ibm/service/cos/resource_ibm_cos_bucket_test.go @@ -2242,7 +2242,7 @@ func testAccCheckIBMCosBucketExists(resource string, bucket string, regiontype s rt = "crl" } - apiEndpoint, _, _ := cos.SelectCosApi(rt, region, false) + apiEndpoint, _, _ := cos.SelectCosApi(rt, region) rsContClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixSession() if err != nil {