Skip to content

Commit bafba21

Browse files
committed
fix(cloudformation-stack): remove role afterwards
1 parent 1c42a86 commit bafba21

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

resources/cloudformation-stack.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ type CloudFormationStack struct {
107107
parentID *string
108108
roleARN *string
109109
maxDeleteAttempts int
110+
roleCreated bool
111+
roleName string
110112
}
111113

112114
func (r *CloudFormationStack) Filter() error {
@@ -148,6 +150,20 @@ func (r *CloudFormationStack) createRole(ctx context.Context) error {
148150
},
149151
})
150152

153+
r.roleCreated = true
154+
r.roleName = roleParts[len(roleParts)-1]
155+
156+
return err
157+
}
158+
159+
func (r *CloudFormationStack) removeRole(ctx context.Context) error {
160+
if !r.roleCreated {
161+
return nil
162+
}
163+
164+
_, err := r.iamSvc.DeleteRole(ctx, &iam.DeleteRoleInput{
165+
RoleName: ptr.String(r.roleName),
166+
})
151167
return err
152168
}
153169

@@ -196,9 +212,9 @@ func (r *CloudFormationStack) removeWithAttempts(ctx context.Context, attempt in
196212
} else {
197213
return r.removeWithAttempts(ctx, attempt+1)
198214
}
199-
} else {
200-
return nil
201215
}
216+
217+
return r.removeRole(ctx)
202218
}
203219

204220
func GetParentStack(svc cloudformationiface.CloudFormationAPI, stackID string) (*cloudformation.Stack, error) {

0 commit comments

Comments
 (0)