@@ -475,23 +475,30 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
475
475
if tayp == configservice .ResourceTypeAwsIamRole {
476
476
role := val .(* cfn_iam.Role )
477
477
By (fmt .Sprintf ("cleanup for role with name '%s'" , role .RoleName ))
478
+ // added repeat to not keep flooding the logs.
479
+ repeat := false
478
480
Eventually (func (gomega Gomega ) bool {
479
481
_ , err := iamSvc .DeleteRole (& iam.DeleteRoleInput {RoleName : aws .String (role .RoleName )})
480
- if err != nil {
481
- By (fmt .Sprintf ("failed to delete role '%s'; reason: %s" , role .RoleName , err .Error ()))
482
+ if err != nil && ! repeat {
483
+ By (fmt .Sprintf ("failed to delete role '%s'; reason: %+v" , role .RoleName , err ))
484
+ repeat = true
482
485
}
483
- return awserrors .IsNotFound (err ) || err == nil
486
+ code , ok := awserrors .Code (err )
487
+ return err == nil || (ok && code == iam .ErrCodeNoSuchEntityException )
484
488
}, 5 * time .Minute , 5 * time .Second ).Should (BeTrue ())
485
489
}
486
490
if val .AWSCloudFormationType () == "AWS::IAM::InstanceProfile" {
487
491
profile := val .(* cfn_iam.InstanceProfile )
488
492
By (fmt .Sprintf ("cleanup for profile with name '%s'" , profile .InstanceProfileName ))
493
+ repeat := false
489
494
Eventually (func (gomega Gomega ) bool {
490
495
_ , err := iamSvc .DeleteInstanceProfile (& iam.DeleteInstanceProfileInput {InstanceProfileName : aws .String (profile .InstanceProfileName )})
491
- if err != nil {
492
- By (fmt .Sprintf ("failed to delete role '%s'; reason: %s" , profile .InstanceProfileName , err .Error ()))
496
+ if err != nil && ! repeat {
497
+ By (fmt .Sprintf ("failed to delete role '%s'; reason: %+v" , profile .InstanceProfileName , err ))
498
+ repeat = true
493
499
}
494
- return awserrors .IsNotFound (err ) || err == nil
500
+ code , ok := awserrors .Code (err )
501
+ return err == nil || (ok && code == iam .ErrCodeNoSuchEntityException )
495
502
}, 5 * time .Minute , 5 * time .Second ).Should (BeTrue ())
496
503
}
497
504
if val .AWSCloudFormationType () == "AWS::IAM::ManagedPolicy" {
@@ -502,12 +509,15 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
502
509
for _ , p := range policies .Policies {
503
510
if aws .StringValue (p .PolicyName ) == policy .ManagedPolicyName {
504
511
By (fmt .Sprintf ("cleanup for policy '%s'" , p .String ()))
512
+ repeat := false
505
513
Eventually (func (gomega Gomega ) bool {
506
514
_ , err := iamSvc .DeletePolicy (& iam.DeletePolicyInput {PolicyArn : p .Arn })
507
- if err != nil {
508
- By (fmt .Sprintf ("failed to delete policy '%s'; reason: %s" , policy .Description , err .Error ()))
515
+ if err != nil && ! repeat {
516
+ By (fmt .Sprintf ("failed to delete policy '%s'; reason: %+v" , policy .Description , err ))
517
+ repeat = true
509
518
}
510
- return awserrors .IsNotFound (err ) || err == nil
519
+ code , ok := awserrors .Code (err )
520
+ return err == nil || (ok && code == iam .ErrCodeNoSuchEntityException )
511
521
}, 5 * time .Minute , 5 * time .Second ).Should (BeTrue ())
512
522
// TODO: why is there a break here? Don't we want to clean up everything?
513
523
break
0 commit comments