From 4f8848fdb9358fc2a8b8c4a59c424febde09a409 Mon Sep 17 00:00:00 2001 From: Manuel Vogel Date: Fri, 21 Jan 2022 09:18:09 +0100 Subject: [PATCH] feat: add missing tags for iam resources (#731) * feat: add tags for iam user * fix: propagate tags for iam user * chore(iam-role-policy): reorder imports * feat(iam-instance-profile): add tags --- resources/iam-instance-profiles.go | 14 ++++++++++++++ resources/iam-role-policy.go | 3 ++- resources/iam-users.go | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/resources/iam-instance-profiles.go b/resources/iam-instance-profiles.go index 4db7cf09c..c39314805 100644 --- a/resources/iam-instance-profiles.go +++ b/resources/iam-instance-profiles.go @@ -3,11 +3,13 @@ package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" + "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMInstanceProfile struct { svc *iam.IAM name string + tags []*iam.Tag } func init() { @@ -29,6 +31,7 @@ func ListIAMInstanceProfiles(sess *session.Session) ([]Resource, error) { resources = append(resources, &IAMInstanceProfile{ svc: svc, name: *out.InstanceProfileName, + tags: out.Tags, }) } @@ -56,3 +59,14 @@ func (e *IAMInstanceProfile) Remove() error { func (e *IAMInstanceProfile) String() string { return e.name } + +func (e *IAMInstanceProfile) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", e.name) + + for _, tag := range e.tags { + properties.SetTag(tag.Key, tag.Value) + } + + return properties +} diff --git a/resources/iam-role-policy.go b/resources/iam-role-policy.go index 2843132d8..9e426b324 100644 --- a/resources/iam-role-policy.go +++ b/resources/iam-role-policy.go @@ -2,9 +2,10 @@ package resources import ( "fmt" - "github.com/sirupsen/logrus" "strings" + "github.com/sirupsen/logrus" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" diff --git a/resources/iam-users.go b/resources/iam-users.go index f351e2a0c..700343455 100644 --- a/resources/iam-users.go +++ b/resources/iam-users.go @@ -3,11 +3,13 @@ package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" + "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMUser struct { svc *iam.IAM name string + tags []*iam.Tag } func init() { @@ -27,6 +29,7 @@ func ListIAMUsers(sess *session.Session) ([]Resource, error) { resources = append(resources, &IAMUser{ svc: svc, name: *out.UserName, + tags: out.Tags, }) } @@ -47,3 +50,14 @@ func (e *IAMUser) Remove() error { func (e *IAMUser) String() string { return e.name } + +func (e *IAMUser) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("Name", e.name) + + for _, tag := range e.tags { + properties.SetTag(tag.Key, tag.Value) + } + + return properties +}