Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #350 from videte47/master
Browse files Browse the repository at this point in the history
Enable Tag filter on EC2 Images
  • Loading branch information
svenwltr authored Apr 15, 2019
2 parents e744709 + 4dfad10 commit 4d614f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ accounts:
- property: "tag:team"
type: regex
value: ".+"
EC2Image:
- property: "tag:release"
value: "production"
19 changes: 15 additions & 4 deletions resources/ec2-images.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/rebuy-de/aws-nuke/pkg/types"
)

type EC2Image struct {
svc *ec2.EC2
id string
svc *ec2.EC2
id string
tags []*ec2.Tag
}

func init() {
Expand All @@ -30,8 +32,9 @@ func ListEC2Images(sess *session.Session) ([]Resource, error) {
resources := make([]Resource, 0)
for _, out := range resp.Images {
resources = append(resources, &EC2Image{
svc: svc,
id: *out.ImageId,
svc: svc,
id: *out.ImageId,
tags: out.Tags,
})
}

Expand All @@ -45,6 +48,14 @@ func (e *EC2Image) Remove() error {
return err
}

func (e *EC2Image) Properties() types.Properties {
properties := types.NewProperties()
for _, tagValue := range e.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
return properties
}

func (e *EC2Image) String() string {
return e.id
}

0 comments on commit 4d614f1

Please sign in to comment.