@@ -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