diff --git a/controllers/providers/aws/iam.go b/controllers/providers/aws/iam.go index 1cbeebb4..6cc148f4 100644 --- a/controllers/providers/aws/iam.go +++ b/controllers/providers/aws/iam.go @@ -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), }) @@ -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