Skip to content

Commit a1f6192

Browse files
committed
fix: check for role attached to instance profile and create if it does not exist
Signed-off-by: Jonah Back <[email protected]>
1 parent ae893c4 commit a1f6192

File tree

1 file changed

+8
-4
lines changed
  • controllers/providers/aws

1 file changed

+8
-4
lines changed

controllers/providers/aws/iam.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ func (w *AwsWorker) CreateScalingGroupRole(name string) (*iam.Role, *iam.Instanc
214214
createdProfile = out.InstanceProfile
215215
time.Sleep(DefaultInstanceProfilePropagationDelay)
216216

217-
_, err = w.IamClient.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{
217+
} else {
218+
createdProfile = instanceProfile
219+
}
220+
221+
if len(createdProfile.Roles) == 0 {
222+
_, err := w.IamClient.AddRoleToInstanceProfile(&iam.AddRoleToInstanceProfileInput{
218223
InstanceProfileName: aws.String(name),
219224
RoleName: aws.String(name),
220225
})
@@ -224,10 +229,9 @@ func (w *AwsWorker) CreateScalingGroupRole(name string) (*iam.Role, *iam.Instanc
224229
return createdRole, createdProfile, errors.Wrap(err, "failed to attach instance-profile")
225230
}
226231
}
232+
} else {
233+
createdProfile.Roles = append(createdProfile.Roles, createdRole)
227234
}
228-
229-
} else {
230-
createdProfile = instanceProfile
231235
}
232236

233237
return createdRole, createdProfile, nil

0 commit comments

Comments
 (0)