@@ -74,30 +74,29 @@ func cleanup(ctx context.Context, svc *ec2.Client, iamsvc *iam.Client) {
74
74
}
75
75
76
76
if len (Roles ) == 0 {
77
- roles , err := iamsvc .ListRoles (ctx , & iam.ListRolesInput {
78
- PathPrefix : aws .String ("/GitpodNetworkCheck" ),
79
- })
80
- if err != nil {
81
- log .WithError (err ).Warn ("Failed to list roles, please cleanup manually" )
82
- } else if len (roles .Roles ) == 0 {
83
- log .Info ("No roles found." )
84
- }
85
-
86
- for _ , role := range roles .Roles {
87
- if role .RoleName == nil {
88
- continue
77
+ paginator := iam .NewListInstanceProfilesPaginator (iamsvc , & iam.ListInstanceProfilesInput {})
78
+ for paginator .HasMorePages () {
79
+ output , err := paginator .NextPage (ctx )
80
+ if err != nil {
81
+ log .WithError (err ).Warn ("Failed to list roles, please cleanup manually" )
82
+ break
89
83
}
90
84
91
- if * role .RoleName == gitpodRoleName {
92
- Roles = append (Roles , * role .RoleName )
85
+ for _ , ip := range output .InstanceProfiles {
86
+ if * ip .InstanceProfileName == gitpodInstanceProfile {
87
+ {
88
+ InstanceProfile = * ip .InstanceProfileName
89
+ if len (ip .Roles ) > 0 {
90
+ for _ , role := range ip .Roles {
91
+ Roles = append (Roles , * role .RoleName )
92
+ }
93
+ }
94
+ }
95
+ }
93
96
}
94
97
}
95
98
}
96
99
97
- if InstanceProfile == "" {
98
- InstanceProfile = gitpodInstanceProfile
99
- }
100
-
101
100
if len (Roles ) > 0 {
102
101
for _ , role := range Roles {
103
102
_ , err := iamsvc .DetachRolePolicy (ctx , & iam.DetachRolePolicyInput {PolicyArn : aws .String ("arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore" ), RoleName : aws .String (role )})
0 commit comments