Skip to content

JamesWoolfenden/terraform-aws-cloudtrail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-aws-cloudtrail

Build Status Latest Release GitHub tag (latest SemVer) Terraform Version Infrastructure Tests pre-commit checkov Infrastructure Tests

This is an updated example for using Cloudtrail that works, in addition to the trail Glue is added to support querying in Athena.


It's 100% Open Source and licensed under the APACHE2.

Introduction

This module deploys a Cloudtrail set-up, with kms key and S3 log bucket and sets up a table for Athena with AWS Glue.

Usage

Include this repository as a module in your existing terraform code:

module "cloudtrail" {
  source            = "JamesWoolfenden/cloudtrail/aws"
  version           = "v0.1.3"
  trail             = var.trail
}

Costs

Terraform directory at .
  ✔ Running terraform plan
  ✔ Running terraform show

✔ Calculating monthly cost estimate

Project: .

 Name                                                  Monthly Qty  Unit              Monthly Cost

 module.cloudtrail.aws_cloudwatch_log_group.trails
 ├─ Data ingested                                                0  GB                       $0.00
 ├─ Archival Storage                                             0  GB                       $0.00
 └─ Insights queries data scanned                                0  GB                       $0.00

 module.cloudtrail.aws_kms_key.cloudtrail
 ├─ Customer master key                                          1  months                   $1.00
 ├─ Requests                                        Cost depends on usage: $0.03 per 10k requests
 ├─ ECC GenerateDataKeyPair requests                Cost depends on usage: $0.10 per 10k requests
 └─ RSA GenerateDataKeyPair requests                Cost depends on usage: $0.10 per 10k requests

 module.cloudtrail.aws_s3_bucket.trails
 ├─ Standard - infrequent access
 │  ├─ Storage                                                   0  GB-months                $0.00
 │  ├─ PUT, COPY, POST, LIST requests                            0  1k requests              $0.00
 │  ├─ GET, SELECT, and all other requests                       0  1k requests              $0.00
 │  ├─ Lifecycle transition                                      0  1k requests              $0.00
 │  ├─ Retrievals                                                0  GB-months                $0.00
 │  ├─ Select data scanned                                       0  GB-months                $0.00
 │  └─ Select data returned                                      0  GB-months                $0.00
 ├─ One zone - infrequent access
 │  ├─ Storage                                                   0  GB-months                $0.00
 │  ├─ PUT, COPY, POST, LIST requests                            0  1k requests              $0.00
 │  ├─ GET, SELECT, and all other requests                       0  1k requests              $0.00
 │  ├─ Lifecycle transition                                      0  1k requests              $0.00
 │  ├─ Retrievals                                                0  GB-months                $0.00
 │  ├─ Select data scanned                                       0  GB-months                $0.00
 │  └─ Select data returned                                      0  GB-months                $0.00
 ├─ Glacier
 │  ├─ Storage                                                   0  GB-months                $0.00
 │  ├─ PUT, COPY, POST, LIST requests                            0  1k requests              $0.00
 │  ├─ GET, SELECT, and all other requests                       0  1k requests              $0.00
 │  ├─ Lifecycle transition                                      0  1k requests              $0.00
 │  ├─ Retrieval requests (standard)                             0  1k requests              $0.00
 │  ├─ Retrievals (standard)                                     0  GB-months                $0.00
 │  ├─ Select data scanned (standard)                            0  GB-months                $0.00
 │  ├─ Select data returned (standard)                           0  GB-months                $0.00
 │  ├─ Retrieval requests (expedited)                            0  1k requests              $0.00
 │  ├─ Retrievals (expedited)                                    0  GB-months                $0.00
 │  ├─ Select data scanned (expedited)                           0  GB-months                $0.00
 │  ├─ Select data returned (expedited)                          0  GB-months                $0.00
 │  ├─ Retrieval requests (bulk)                                 0  1k requests              $0.00
 │  ├─ Retrievals (bulk)                                         0  GB-months                $0.00
 │  ├─ Select data scanned (bulk)                                0  GB-months                $0.00
 │  ├─ Select data returned (bulk)                               0  GB-months                $0.00
 │  └─ Early delete (within 90 days)                             0  GB-months                $0.00
 ├─ Glacier deep archive
 │  ├─ Storage                                                   0  GB-months                $0.00
 │  ├─ PUT, COPY, POST, LIST requests                            0  1k requests              $0.00
 │  ├─ GET, SELECT, and all other requests                       0  1k requests              $0.00
 │  ├─ Lifecycle transition                                      0  1k requests              $0.00
 │  ├─ Retrieval requests (standard)                             0  1k requests              $0.00
 │  ├─ Retrievals (standard)                                     0  GB-months                $0.00
 │  ├─ Retrieval requests (bulk)                                 0  1k requests              $0.00
 │  ├─ Retrievals (bulk)                                         0  GB-months                $0.00
 │  └─ Early delete (within 180 days)                            0  GB-months                $0.00
 ├─ Standard
 │  ├─ Storage                                                   0  GB-months                $0.00
 │  ├─ PUT, COPY, POST, LIST requests                            0  1k requests              $0.00
 │  ├─ GET, SELECT, and all other requests                       0  1k requests              $0.00
 │  ├─ Select data scanned                                       0  GB-months                $0.00
 │  └─ Select data returned                                      0  GB-months                $0.00
 └─ Intelligent tiering
    ├─ Storage (frequent access)                                 0  GB-months                $0.00
    ├─ Storage (infrequent access)                               0  GB-months                $0.00
    ├─ Monitoring and automation                                 0  1k objects               $0.00
    ├─ PUT, COPY, POST, LIST requests                            0  1k requests              $0.00
    ├─ GET, SELECT, and all other requests                       0  1k requests              $0.00
    ├─ Lifecycle transition                                      0  1k requests              $0.00
    ├─ Select data scanned                                       0  GB-months                $0.00
    ├─ Select data returned                                      0  GB-months                $0.00
    └─ Early delete (within 30 days)                             0  GB-months                $0.00

 PROJECT TOTAL                                                                               $1.00

----------------------------------
To estimate usage-based resources use --usage-file, see https://infracost.io/usage-file

3 resource types weren't estimated as they're not supported yet.
Please watch/star https://github.com/infracost/infracost as new resources are added regularly.
1 x aws_cloudtrail
1 x aws_glue_catalog_table
1 x aws_glue_catalog_database

Checks

This module has a Checkov skip added as the MFA_delete functionality is currently broken in Terraform 0.12.8. I have added an ignore so that you can manually update this item without interference.

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

No modules.

Resources

Name Type
aws_cloudtrail.account resource
aws_cloudwatch_log_group.trails resource
aws_glue_catalog_database.cloudtrail resource
aws_glue_catalog_table.cloudtrail resource
aws_iam_role.cloudtrail resource
aws_iam_role_policy.cloudtrail resource
aws_kms_alias.trails resource
aws_kms_key.cloudtrail resource
aws_s3_bucket.trails resource
aws_s3_bucket_acl.trails resource
aws_s3_bucket_lifecycle_configuration.trails resource
aws_s3_bucket_policy.trails resource
aws_s3_bucket_public_access_block.trails resource
aws_s3_bucket_server_side_encryption_configuration.trails resource
aws_s3_bucket_versioning.trails resource
aws_sns_topic.cloudtrail resource
aws_caller_identity.current data source
aws_cloudtrail_service_account.main data source
aws_region.current data source

Inputs

Name Description Type Default Required
enable_log_file_validation Bool to enable log file validation bool true no
enable_logging Toggle logging bool true no
expiry Expire logs after this many days number 30 no
is_multi_region_trail Is this a multi-region trail? Secure option is default bool true no
is_organization_trail Is this for an organisation? bool false no
log_group_name n/a string "cloudtrail" no
retention_in_days n/a number 90 no
trail Basic Settings for Cloudtrail map(any)
{
"include_global_service_events": false,
"name": "tf-trail-account",
"s3_key_prefix": "prefix"
}
no

Outputs

Name Description
bucket n/a
kms n/a
log_group n/a
service_account n/a
trail n/a

Policy

The Terraform resource required is:

resource "aws_iam_policy" "terraform_pike" {
  name_prefix = "terraform_pike"
  path        = "/"
  description = "Pike Autogenerated policy from IAC"

  policy = jsonencode({
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "SNS:CreateTopic",
                "SNS:DeleteTopic",
                "SNS:GetTopicAttributes",
                "SNS:ListTagsForResource",
                "SNS:SetTopicAttributes"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "cloudtrail:CreateTrail",
                "cloudtrail:DeleteTrail",
                "cloudtrail:DescribeTrails",
                "cloudtrail:GetEventSelectors",
                "cloudtrail:GetTrailStatus",
                "cloudtrail:ListTags",
                "cloudtrail:StartLogging",
                "cloudtrail:UpdateTrail"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "glue:CreateDatabase",
                "glue:CreateTable",
                "glue:DeleteDatabase",
                "glue:DeleteTable",
                "glue:GetDatabase",
                "glue:GetTable",
                "glue:UpdateDatabase",
                "glue:UpdateTable"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor3",
            "Effect": "Allow",
            "Action": [
                "iam:CreateRole",
                "iam:DeleteRole",
                "iam:DeleteRolePolicy",
                "iam:GetRole",
                "iam:GetRolePolicy",
                "iam:ListAttachedRolePolicies",
                "iam:ListInstanceProfilesForRole",
                "iam:ListRolePolicies",
                "iam:PassRole",
                "iam:PutRolePolicy"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor4",
            "Effect": "Allow",
            "Action": [
                "kms:CreateAlias",
                "kms:CreateKey",
                "kms:DeleteAlias",
                "kms:DescribeKey",
                "kms:EnableKeyRotation",
                "kms:GetKeyPolicy",
                "kms:GetKeyRotationStatus",
                "kms:ListAliases",
                "kms:ListResourceTags",
                "kms:PutKeyPolicy",
                "kms:ScheduleKeyDeletion"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor5",
            "Effect": "Allow",
            "Action": [
                "logs:AssociateKmsKey",
                "logs:CreateLogGroup",
                "logs:DeleteLogGroup",
                "logs:DeleteRetentionPolicy",
                "logs:DescribeLogGroups",
                "logs:DisassociateKmsKey",
                "logs:ListTagsLogGroup",
                "logs:PutRetentionPolicy"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "VisualEditor6",
            "Effect": "Allow",
            "Action": [
                "s3:CreateBucket",
                "s3:DeleteBucket",
                "s3:GetAccelerateConfiguration",
                "s3:GetBucketAcl",
                "s3:GetBucketCORS",
                "s3:GetBucketLogging",
                "s3:GetBucketObjectLockConfiguration",
                "s3:GetBucketPolicy",
                "s3:GetBucketPublicAccessBlock",
                "s3:GetBucketRequestPayment",
                "s3:GetBucketTagging",
                "s3:GetBucketVersioning",
                "s3:GetBucketWebsite",
                "s3:GetEncryptionConfiguration",
                "s3:GetLifecycleConfiguration",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:GetReplicationConfiguration",
                "s3:ListAllMyBuckets",
                "s3:ListBucket",
                "s3:PutBucketAcl",
                "s3:PutBucketLogging",
                "s3:PutBucketPolicy",
                "s3:PutBucketPublicAccessBlock",
                "s3:PutBucketVersioning",
                "s3:PutEncryptionConfiguration",
                "s3:PutLifecycleConfiguration"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
})
}

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2019-2023 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

James Woolfenden
James Woolfenden