From dbcb6ae7fb2f788037e750e6f67fb915ca8ac688 Mon Sep 17 00:00:00 2001 From: Nico Esteves Date: Thu, 18 Jul 2019 12:41:28 +0200 Subject: [PATCH] aws-dump: Added ec2:nat-gateways --- aws/dump/README.md | 15 ++++++++------- aws/dump/ec2.go | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/aws/dump/README.md b/aws/dump/README.md index 075541f..8cdb8fa 100644 --- a/aws/dump/README.md +++ b/aws/dump/README.md @@ -9,21 +9,21 @@ Dump AWS resources Flags: --help Show context-sensitive help (also try --help-long and --help-man). - --assume-role-arn=ASSUME-ROLE-ARN + --assume-role-arn=ASSUME-ROLE-ARN Role to assume - --assume-role-external-id=ASSUME-ROLE-EXTERNAL-ID + --assume-role-external-id=ASSUME-ROLE-EXTERNAL-ID External ID of the role to assume - --assume-role-session-name=ASSUME-ROLE-SESSION-NAME + --assume-role-session-name=ASSUME-ROLE-SESSION-NAME Role session name --region=REGION AWS Region - --mfa-serial-number=MFA-SERIAL-NUMBER + --mfa-serial-number=MFA-SERIAL-NUMBER MFA Serial Number - --mfa-token-code=MFA-TOKEN-CODE + --mfa-token-code=MFA-TOKEN-CODE MFA Token Code -v, --version Display the version - -c, --accounts-config=ACCOUNTS-CONFIG + -c, --accounts-config=ACCOUNTS-CONFIG Configuration file with the accounts to list resources for. - -t, --terraform-backends-config=TERRAFORM-BACKENDS-CONFIG + -t, --terraform-backends-config=TERRAFORM-BACKENDS-CONFIG Configuration file with the terraform backends to compare with. -o, --output=OUTPUT Filename to store the results in. --only-unmanaged Only return resources not managed by terraform. @@ -36,6 +36,7 @@ Flags: * EC2 * VPC * Security Groups + * NAT gateways * IAM (Does not include attachments) * Users * Access keys diff --git a/aws/dump/ec2.go b/aws/dump/ec2.go index c608db6..53c0db8 100644 --- a/aws/dump/ec2.go +++ b/aws/dump/ec2.go @@ -17,6 +17,7 @@ var ( "security-groups": EC2ListSecurityGroups, "images": EC2ListImages, "instances": EC2ListInstances, + "nat-gateways": EC2ListNATGateways, }, } ) @@ -181,3 +182,29 @@ func EC2ListInstances(session *Session) *ReportResult { return &ReportResult{instances, err} } + +func EC2ListNATGateways(session *Session) *ReportResult { + + client := ec2.New(session.Session, session.Config) + + resources := []Resource{} + err := client.DescribeNatGatewaysPages(&ec2.DescribeNatGatewaysInput{}, + func(page *ec2.DescribeNatGatewaysOutput, lastPage bool) bool { + for _, natGateway := range page.NatGateways { + resource := Resource{ + ID: *natGateway.NatGatewayId, + ARN: "", + AccountID: session.AccountID, + Service: "ec2", + Type: "nat-gateway", + Region: *session.Config.Region, + Metadata: structs.Map(natGateway), + } + resources = append(resources, resource) + } + + return true + }) + + return &ReportResult{resources, err} +}