From b52cf6197584754f276efd0ad1ab6057dbae04be Mon Sep 17 00:00:00 2001 From: Alijohn Ghassemlouei Date: Sat, 9 May 2020 05:54:20 -0400 Subject: [PATCH] aws_cloudtrail support (#96) * adding sdk sources for cloudtrail * adding cloudtrail to list of services * adding cloudtrail terraform id * adding cloudtrail api wrapper * adding cloudtrail function * adding cloudtrail to dependency * adding cloudtrail delete id * renaming cloudtrail const value * adding terraform resource type identifer for cloudtrail * normalizing cloudtrail terraform resource type * adjusting const value for cloudtrail * adjusting cloudtrail const accordingly * adding missing bracket * normalizing cloutrail const * adjusting remaining variable for cloudtrail * adjusting output variable * attempting to resolve cloudtrail output variable * adjusting cloudtrail output to use actual struct --- README.md | 1 + all.yml | 1 + resource/supported.go | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 01006c451..2a3bec5ff 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ A technical reason for this is that AWSweeper is build upon the already existing | aws_ami | x | x | aws_autoscaling_group | x | x | aws_cloudformation_stack | x | x +| aws_cloudtrail | | | aws_cloudwatch_log_group (*new*) | | x | aws_ebs_snapshot | x | x | aws_ebs_volume | x | x diff --git a/all.yml b/all.yml index a8a342a99..9f64262ed 100644 --- a/all.yml +++ b/all.yml @@ -1,6 +1,7 @@ aws_ami: aws_autoscaling_group: aws_cloudformation_stack: +aws_cloudtrail: aws_cloudwatch_log_group: aws_ecs_cluster: aws_ebs_snapshot: diff --git a/resource/supported.go b/resource/supported.go index bdf5f1afa..16048ea8e 100644 --- a/resource/supported.go +++ b/resource/supported.go @@ -13,6 +13,8 @@ import ( "github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface" "github.com/aws/aws-sdk-go/service/cloudwatchlogs" "github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface" + "github.com/aws/aws-sdk-go/service/cloudtrail" + "github.com/aws/aws-sdk-go/service/cloudtrail/cloudtrailiface" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/ecs" @@ -73,6 +75,7 @@ const ( S3Bucket TerraformResourceType = "aws_s3_bucket" SecurityGroup TerraformResourceType = "aws_security_group" Subnet TerraformResourceType = "aws_subnet" + CloudTrail TerraformResourceType = "aws_cloudtrail" Vpc TerraformResourceType = "aws_vpc" VpcEndpoint TerraformResourceType = "aws_vpc_endpoint" ) @@ -111,6 +114,7 @@ var ( S3Bucket: "Name", SecurityGroup: "GroupId", Subnet: "SubnetId", + CloudTrail: "Name", Vpc: "VpcId", VpcEndpoint: "VpcEndpointId", } @@ -152,6 +156,7 @@ var ( KmsKey: 9600, NetworkInterface: 9000, CloudWatchLogGroup: 8900, + CloudTrail: 8800, } tagFieldNames = []string{ @@ -191,6 +196,7 @@ func getDeleteID(resType TerraformResourceType) (string, error) { type AWS struct { autoscalingiface.AutoScalingAPI cloudformationiface.CloudFormationAPI + cloudtrailiface.CloudTrailAPI cloudwatchlogsiface.CloudWatchLogsAPI ec2iface.EC2API ecsiface.ECSAPI @@ -309,6 +315,8 @@ func (a *AWS) RawResources(resType TerraformResourceType) (interface{}, error) { return a.SecurityGroup() case Subnet: return a.subnets() + case CloudTrail: + return a.cloudTrails() case Vpc: return a.vpcs() case VpcEndpoint: @@ -595,6 +603,14 @@ func (a *AWS) s3Buckets() (interface{}, error) { return output.Buckets, nil } +func (a *AWS) cloudTrails() (interface{}, error) { + output, err := a.DescribeTrails(&cloudtrail.DescribeTrailsInput{}) + if err != nil { + return nil, err + } + return output.TrailList, nil +} + func (a *AWS) ebsSnapshots() (interface{}, error) { output, err := a.DescribeSnapshots(&ec2.DescribeSnapshotsInput{ Filters: []*ec2.Filter{