Skip to content

Commit

Permalink
extracting to a globals.go file & updating eip & ecs to reference it
Browse files Browse the repository at this point in the history
  • Loading branch information
ina-stoyanova committed Oct 8, 2020
1 parent a57f1b3 commit 1af68c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 0 additions & 2 deletions aws/ecs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/gruntwork-io/gruntwork-cli/errors"
)

const firstSeenTagKey = "cloud-nuke-first-seen"

// Tag an ECS cluster identified by the given cluster ARN with a tag that has the given key and value
func tagEcsCluster(awsSession *session.Session, clusterArn *string, tagKey string, tagValue string) error {
svc := ecs.New(awsSession)
Expand Down
5 changes: 2 additions & 3 deletions aws/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func getFirstSeenTag(svc *ec2.EC2, address ec2.Address, key string, layout strin
// Returns a formatted string of EIP allocation ids
func getAllEIPAddresses(session *session.Session, region string, excludeAfter time.Time) ([]*string, error) {
svc := ec2.New(session)
const key = "cloud-nuke-first-seen"
const layout = "2006-01-02 15:04:05"

result, err := svc.DescribeAddresses(&ec2.DescribeAddressesInput{})
Expand All @@ -59,15 +58,15 @@ func getAllEIPAddresses(session *session.Session, region string, excludeAfter ti

var allocationIds []*string
for _, address := range result.Addresses {
firstSeenTime, err := getFirstSeenTag(svc, *address, key, layout)
firstSeenTime, err := getFirstSeenTag(svc, *address, firstSeenTagKey, layout)
if err != nil {
return nil, errors.WithStackTrace(err)
}

if firstSeenTime == nil {
now := time.Now().UTC()
firstSeenTime = &now
if err := setFirstSeenTag(svc, *address, key, *firstSeenTime, layout); err != nil {
if err := setFirstSeenTag(svc, *address, firstSeenTagKey, *firstSeenTime, layout); err != nil {
return nil, err
}
}
Expand Down
3 changes: 3 additions & 0 deletions aws/globals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package aws

const firstSeenTagKey = "cloud-nuke-first-seen"

0 comments on commit 1af68c1

Please sign in to comment.