Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the fix for cos deletion access denied issue #5083

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading