Skip to content

Commit

Permalink
Merge pull request #68 from dctrwatson/instance-profiles-first
Browse files Browse the repository at this point in the history
Delete instance-profile before roles
  • Loading branch information
mtibben authored Dec 4, 2019
2 parents d67de18 + 4940375 commit 8469cff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions iamy/awsdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ type awsSyncCmdGenerator struct {
func (a *awsSyncCmdGenerator) deleteOldEntities() {
iam := newIamClient(awsSession())

for _, fromInstanceProfile := range a.from.InstanceProfiles {
if found, _ := a.to.FindInstanceProfileByName(fromInstanceProfile.Name, fromInstanceProfile.Path); !found {
for _, roleName := range fromInstanceProfile.Roles {
a.cmds.Add("aws", "iam", "remove-role-from-instance-profile", "--instance-profile-name", fromInstanceProfile.Name, "--role-name", roleName)
}
a.cmds.Add("aws", "iam", "delete-instance-profile",
"--instance-profile-name", fromInstanceProfile.Name)
}
}
for _, fromRole := range a.from.Roles {
if found, _ := a.to.FindRoleByName(fromRole.Name, fromRole.Path); !found {
// detach managed policies
Expand Down Expand Up @@ -194,15 +203,6 @@ func (a *awsSyncCmdGenerator) deleteOldEntities() {
"--policy-arn", Arn(fromPolicy, a.to.Account))
}
}
for _, fromInstanceProfile := range a.from.InstanceProfiles {
if found, _ := a.to.FindInstanceProfileByName(fromInstanceProfile.Name, fromInstanceProfile.Path); !found {
for _, roleName := range fromInstanceProfile.Roles {
a.cmds.Add("aws", "iam", "remove-role-from-instance-profile", "--instance-profile-name", fromInstanceProfile.Name, "--role-name", roleName)
}
a.cmds.Add("aws", "iam", "delete-instance-profile",
"--instance-profile-name", fromInstanceProfile.Name)
}
}
}

func (a *awsSyncCmdGenerator) updatePolicies() {
Expand Down

0 comments on commit 8469cff

Please sign in to comment.