Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for InstanceProfile tags #30

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions iamy/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ func (a *AwsFetcher) marshalPolicyDescriptionAsync(policyArn string, target *str
}()
}

func (a *AwsFetcher) fetchPolicyTags(policyArn string, tags *map[string]string) {
log.Println("Fetching tags for", policyArn)
func (a *AwsFetcher) fetchInstanceProfileTags(instanceProfileName string, tags *map[string]string) {
log.Println("Fetching tags for instance profile ", instanceProfileName)

var err error
*tags, err = a.iam.getPolicyTags(policyArn)
*tags, err = a.iam.getInstanceProfileTags(instanceProfileName)
if err != nil {
a.policyTagFetchError = err
}
Expand All @@ -230,7 +230,10 @@ func (a *AwsFetcher) marshalRoleAsync(roleName string, roleDescription *string,

func (a *AwsFetcher) populateInstanceProfileData(resp *iam.ListInstanceProfilesOutput) error {
for _, profileResp := range resp.InstanceProfiles {
if ok, err := a.isSkippableManagedResource(CfnInstanceProfile, *profileResp.InstanceProfileName, map[string]string{}, *profileResp.Path); ok {
tags := make(map[string]string)
a.fetchInstanceProfileTags(*profileResp.InstanceProfileName, &tags)

if ok, err := a.isSkippableManagedResource(CfnInstanceProfile, *profileResp.InstanceProfileName, tags, *profileResp.Path); ok {
log.Printf(err)
continue
}
Expand All @@ -243,6 +246,7 @@ func (a *AwsFetcher) populateInstanceProfileData(resp *iam.ListInstanceProfilesO
role := *(roleResp.RoleName)
profile.Roles = append(profile.Roles, role)
}
profile.Tags = tags
a.data.InstanceProfiles = append(a.data.InstanceProfiles, &profile)
}
return nil
Expand Down
12 changes: 12 additions & 0 deletions iamy/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ func (c *iamClient) getPolicyTags(arn string) (map[string]string, error) {
return nil, err
}

func (c *iamClient) getInstanceProfileTags(name string) (map[string]string, error) {
resp, err := c.ListInstanceProfileTags(&iam.ListInstanceProfileTagsInput{InstanceProfileName: &name})
if err == nil && resp.Tags != nil {
tags := make(map[string]string)
for _, tag := range resp.Tags {
tags[*tag.Key] = *tag.Value
}
return tags, err
}
return nil, err
}

func (c *iamClient) getRole(name string) (string, int, error) {
resp, err := c.GetRole(&iam.GetRoleInput{RoleName: &name})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions iamy/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Role struct {
type InstanceProfile struct {
iamService `json:"-"`
Roles []string `json:"Roles,omitempty"`
Tags map[string]string `json:"Tags,omitempty"`
}

func (ip InstanceProfile) ResourceType() string {
Expand Down