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

Add ec2 snapshot Start Time #725

Merged
merged 1 commit into from
Jan 3, 2022
Merged
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
18 changes: 12 additions & 6 deletions resources/ec2-snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package resources

import (
"fmt"
"time"

"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 EC2Snapshot struct {
svc *ec2.EC2
id string
tags []*ec2.Tag
svc *ec2.EC2
id string
startTime *time.Time
tags []*ec2.Tag
}

func init() {
Expand All @@ -33,9 +36,10 @@ func ListEC2Snapshots(sess *session.Session) ([]Resource, error) {
resources := make([]Resource, 0)
for _, out := range resp.Snapshots {
resources = append(resources, &EC2Snapshot{
svc: svc,
id: *out.SnapshotId,
tags: out.Tags,
svc: svc,
id: *out.SnapshotId,
startTime: out.StartTime,
tags: out.Tags,
})
}

Expand All @@ -44,6 +48,8 @@ func ListEC2Snapshots(sess *session.Session) ([]Resource, error) {

func (e *EC2Snapshot) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("StartTime", e.startTime.Format(time.RFC3339))

for _, tagValue := range e.tags {
properties.Set(fmt.Sprintf("tag:%v", *tagValue.Key), tagValue.Value)
}
Expand Down