Skip to content

Commit

Permalink
fix: read endpoint type from schema (IBM-Cloud#5552)
Browse files Browse the repository at this point in the history
* fix: read endpoint type from schema

* add empty string check

* update code

---------

Co-authored-by: Deeksha Sharma <deekshasharma@Deekshas-MacBook-Pro.local>
  • Loading branch information
IBM-Deeksha and Deeksha Sharma authored Aug 9, 2024
1 parent 5a74d81 commit 59a6f73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ibm/service/cos/data_source_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
23 changes: 19 additions & 4 deletions ibm/service/cos/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 59a6f73

Please sign in to comment.