Skip to content

Commit

Permalink
fix: check for role attached to instance profile and create if it doe…
Browse files Browse the repository at this point in the history
…s not exist

Signed-off-by: Jonah Back <jonah@jonahback.com>
  • Loading branch information
backjo committed May 23, 2022
1 parent ae893c4 commit a1f6192
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions controllers/providers/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ func (w *AwsWorker) CreateScalingGroupRole(name string) (*iam.Role, *iam.Instanc
createdProfile = out.InstanceProfile
time.Sleep(DefaultInstanceProfilePropagationDelay)

_, err = w.IamClient.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{
} else {
createdProfile = instanceProfile
}

if len(createdProfile.Roles) == 0 {
_, err := w.IamClient.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{
InstanceProfileName: aws.String(name),
RoleName: aws.String(name),
})
Expand All @@ -224,10 +229,9 @@ func (w *AwsWorker) CreateScalingGroupRole(name string) (*iam.Role, *iam.Instanc
return createdRole, createdProfile, errors.Wrap(err, "failed to attach instance-profile")
}
}
} else {
createdProfile.Roles = append(createdProfile.Roles, createdRole)
}

} else {
createdProfile = instanceProfile
}

return createdRole, createdProfile, nil
Expand Down

0 comments on commit a1f6192

Please sign in to comment.