@@ -410,19 +410,24 @@ func createCloudFormationStack(prov client.ConfigProvider, t *cfn_bootstrap.Temp
410410 cfnSvc := cloudformation .NewService (CFN )
411411
412412 Eventually (func () bool {
413- err := cfnSvc .ReconcileBootstrapStack (t .Spec .StackName , * renderCustomCloudFormation (t ), tags )
413+ err := cfnSvc .ReconcileBootstrapStack (t .Spec .StackName , * renderCustomCloudFormation (t ), tags , true )
414414 output , err1 := CFN .DescribeStackEvents (& cfn.DescribeStackEventsInput {StackName : aws .String (t .Spec .StackName ), NextToken : aws .String ("1" )})
415+ By ("========= Stack Event Output Begin =========" )
415416 for _ , event := range output .StackEvents {
416417 By (fmt .Sprintf ("Event details for %s : Resource: %s, Status: %s, Reason: %s" , aws .StringValue (event .LogicalResourceId ), aws .StringValue (event .ResourceType ), aws .StringValue (event .ResourceStatus ), aws .StringValue (event .ResourceStatusReason )))
417418 }
419+ By ("========= Stack Event Output End =========" )
418420 return err == nil && err1 == nil
419421 }, 2 * time .Minute ).Should (Equal (true ))
422+
420423 stack , err := CFN .DescribeStacks (& cfn.DescribeStacksInput {StackName : aws .String (t .Spec .StackName )})
421424 if err == nil && len (stack .Stacks ) > 0 {
422425 deleteMultitenancyRoles (prov )
423426 if aws .StringValue (stack .Stacks [0 ].StackStatus ) == cfn .StackStatusRollbackFailed ||
424427 aws .StringValue (stack .Stacks [0 ].StackStatus ) == cfn .StackStatusRollbackComplete ||
425- aws .StringValue (stack .Stacks [0 ].StackStatus ) == cfn .StackStatusRollbackInProgress {
428+ aws .StringValue (stack .Stacks [0 ].StackStatus ) == cfn .StackStatusRollbackInProgress ||
429+ aws .StringValue (stack .Stacks [0 ].StackStatus ) == cfn .StackStatusCreateFailed ||
430+ aws .StringValue (stack .Stacks [0 ].StackStatus ) == cfn .StackStatusDeleteFailed {
426431 // If cloudformation stack creation fails due to resources that already exist, stack stays in rollback status and must be manually deleted.
427432 // Delete resources that failed because they already exists.
428433 deleteResourcesInCloudFormation (prov , t )
@@ -445,17 +450,23 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
445450 iamSvc := iam .New (prov )
446451 temp := * renderCustomCloudFormation (t )
447452 for _ , val := range temp .Resources {
453+ By (fmt .Sprintf ("deleting the following resource: %s" , val .AWSCloudFormationType ()))
448454 tayp := val .AWSCloudFormationType ()
449455 if tayp == configservice .ResourceTypeAwsIamRole {
450456 role := val .(* cfn_iam.Role )
457+ By (fmt .Sprintf ("cleanup for role with name '%s'" , role .RoleName ))
451458 Eventually (func (gomega Gomega ) bool {
452459 _ , err := iamSvc .DeleteRole (& iam.DeleteRoleInput {RoleName : aws .String (role .RoleName )})
453460 return awserrors .IsNotFound (err ) || err == nil
454461 }, 5 * time .Minute , 5 * time .Second ).Should (BeTrue ())
455462 }
456463 if val .AWSCloudFormationType () == "AWS::IAM::InstanceProfile" {
457464 profile := val .(* cfn_iam.InstanceProfile )
458- _ , _ = iamSvc .DeleteInstanceProfile (& iam.DeleteInstanceProfileInput {InstanceProfileName : aws .String (profile .InstanceProfileName )})
465+ By (fmt .Sprintf ("cleanup for profile with name '%s'" , profile .InstanceProfileName ))
466+ Eventually (func (gomega Gomega ) bool {
467+ _ , err := iamSvc .DeleteInstanceProfile (& iam.DeleteInstanceProfileInput {InstanceProfileName : aws .String (profile .InstanceProfileName )})
468+ return awserrors .IsNotFound (err ) || err == nil
469+ }, 5 * time .Minute , 5 * time .Second ).Should (BeTrue ())
459470 }
460471 if val .AWSCloudFormationType () == "AWS::IAM::ManagedPolicy" {
461472 policy := val .(* cfn_iam.ManagedPolicy )
@@ -464,7 +475,12 @@ func deleteResourcesInCloudFormation(prov client.ConfigProvider, t *cfn_bootstra
464475 if len (policies .Policies ) > 0 {
465476 for _ , p := range policies .Policies {
466477 if aws .StringValue (p .PolicyName ) == policy .ManagedPolicyName {
467- _ , _ = iamSvc .DeletePolicy (& iam.DeletePolicyInput {PolicyArn : p .Arn })
478+ By (fmt .Sprintf ("cleanup for policy '%s'" , p .String ()))
479+ Eventually (func (gomega Gomega ) bool {
480+ _ , err := iamSvc .DeletePolicy (& iam.DeletePolicyInput {PolicyArn : p .Arn })
481+ return awserrors .IsNotFound (err ) || err == nil
482+ }, 5 * time .Minute , 5 * time .Second ).Should (BeTrue ())
483+ // TODO: why is there a break here? Don't we want to clean up everything?
468484 break
469485 }
470486 }
0 commit comments