Skip to content

Commit

Permalink
Adding the fix for cos deletion access denied issue
Browse files Browse the repository at this point in the history
  • Loading branch information
IBM-diksha authored and hkantare committed Jan 30, 2024
1 parent c116881 commit 38db859
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ibm/service/cos/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
token "github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam/token"
"github.com/IBM/ibm-cos-sdk-go/aws/session"
"github.com/IBM/ibm-cos-sdk-go/service/s3"
rc "github.com/IBM/platform-services-go-sdk/resourcecontrollerv2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -1550,7 +1551,26 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool,
if len(bucket_meta) < 2 || len(strings.Split(bucket_meta[1], ":")) < 2 {
return false, fmt.Errorf("[ERROR] Error parsing bucket ID. Bucket ID format must be: $CRN:meta:$buckettype:$bucketlocation")
}

resourceInstanceId := strings.Split(d.Id(), ":bucket:")[0]
resourceInstanceIdInput := resourceInstanceId + "::"
resourceInstanceGet := rc.GetResourceInstanceOptions{
ID: &resourceInstanceIdInput,
}
rsConClientV2, errConf := meta.(conns.ClientSession).ResourceControllerV2API()
if errConf != nil {
return false, errConf
}
instance, resp, err := rsConClientV2.GetResourceInstance(&resourceInstanceGet)
if err != nil {
if resp != nil && resp.StatusCode == 404 {
return false, nil
}
fmt.Println(fmt.Errorf("[WARN] Error getting resource instance from cos bucket: %s with resp code: %s", err, resp))
}
if instance != nil && (strings.Contains(*instance.State, "removed") || strings.Contains(*instance.State, "pending_reclamation")) {
log.Printf("[WARN] Removing instance from state because it's in removed or pending_reclamation state from the cos bucket resource")
return false, nil
}
bucketName := parseBucketId(d.Id(), "bucketName")
serviceID := parseBucketId(d.Id(), "serviceID")

Expand Down

0 comments on commit 38db859

Please sign in to comment.