Skip to content

Commit

Permalink
aws_cloudtrail support (#96)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Alijohn Ghassemlouei committed May 9, 2020
1 parent ddc8ed0 commit b52cf61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions all.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
aws_ami:
aws_autoscaling_group:
aws_cloudformation_stack:
aws_cloudtrail:
aws_cloudwatch_log_group:
aws_ecs_cluster:
aws_ebs_snapshot:
Expand Down
16 changes: 16 additions & 0 deletions resource/supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -111,6 +114,7 @@ var (
S3Bucket: "Name",
SecurityGroup: "GroupId",
Subnet: "SubnetId",
CloudTrail: "Name",
Vpc: "VpcId",
VpcEndpoint: "VpcEndpointId",
}
Expand Down Expand Up @@ -152,6 +156,7 @@ var (
KmsKey: 9600,
NetworkInterface: 9000,
CloudWatchLogGroup: 8900,
CloudTrail: 8800,
}

tagFieldNames = []string{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit b52cf61

Please sign in to comment.