Skip to content

Commit e8648e6

Browse files
committed
fix: iam policy sweep
Signed-off-by: Nicolas FOURNIER <[email protected]>
1 parent 6058688 commit e8648e6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

ovh/resource_iam_policy_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ func testSweepIamPolicy(region string) error {
2424
return fmt.Errorf("error getting client: %s", err)
2525
}
2626

27-
policyIds := []string{}
28-
if err := client.Get("/v2/iam/policy", &policyIds); err != nil {
27+
policies := []IamPolicy{}
28+
if err := client.Get("/v2/iam/policy", &policies); err != nil {
2929
return fmt.Errorf("Error calling /v2/iam/policy:\n\t %q", err)
3030
}
3131

32-
if len(policyIds) == 0 {
33-
log.Print("[DEBUG] No identity groups to sweep")
32+
if len(policies) == 0 {
33+
log.Print("[DEBUG] No iam policy to sweep")
3434
return nil
3535
}
3636

37-
for _, polId := range policyIds {
38-
var polDetails IamPolicy
39-
if err := client.Get(fmt.Sprintf("/v2/iam/policy/%s", polId), &polDetails); err != nil {
40-
return err
37+
for _, pol := range policies {
38+
if !strings.HasPrefix(pol.Name, test_prefix) {
39+
continue
4140
}
4241

43-
if !strings.HasPrefix(polDetails.Name, test_prefix) {
42+
// skip seeping readonly attributes
43+
if pol.ReadOnly {
4444
continue
4545
}
4646

47-
log.Printf("[DEBUG] IAM policy found %s: %s", polDetails.Name, polId)
47+
log.Printf("[DEBUG] IAM policy found %s: %s", pol.Name, pol.Id)
4848
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
49-
log.Printf("[INFO] Deleting iam policy %s: %s", polDetails.Name, polId)
50-
if err := client.Delete(fmt.Sprintf("/v2/iam/policy/%s", polId), nil); err != nil {
49+
log.Printf("[INFO] Deleting iam policy %s: %s", pol.Name, pol.Id)
50+
if err := client.Delete(fmt.Sprintf("/v2/iam/policy/%s", pol.Id), nil); err != nil {
5151
return resource.RetryableError(err)
5252
}
5353

0 commit comments

Comments
 (0)