Module: cloudtrail
Terraform module to provision an AWS CloudTrail.
The module accepts an encrypted S3 bucket with versioning to store CloudTrail logs.
The bucket could be from the same AWS account or from a different account.
This is useful if an organization uses a number of separate AWS accounts to isolate the Audit environment from other environments (production, staging, development).
In this case, you create CloudTrail in the production environment (production AWS account), while the S3 bucket to store the CloudTrail logs is created in the Audit AWS account, restricting access to the logs only to the users/groups from the Audit account.
Usage
module "cloudtrail" {
source = "cloudposse/cloudtrail/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "cluster"
enable_log_file_validation = true
include_global_service_events = true
is_multi_region_trail = false
enable_logging = true
s3_bucket_name = "my-cloudtrail-logs-bucket"
}
NOTE: To create an S3 bucket for CloudTrail logs, use terraform-aws-cloudtrail-s3-bucket module. It creates an S3 bucket and an IAM policy to allow CloudTrail logs.
module "cloudtrail" {
source = "cloudposse/cloudtrail/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "cluster"
enable_log_file_validation = true
include_global_service_events = true
is_multi_region_trail = false
enable_logging = true
s3_bucket_name = module.cloudtrail_s3_bucket.bucket_id
}
module "cloudtrail_s3_bucket" {
source = "cloudposse/cloudtrail-s3-bucket/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "cluster"
}
For a complete example, see examples/complete.
Variables
Required Variables
s3_bucket_name(string) requiredS3 bucket name for CloudTrail logs
Optional Variables
advanced_event_selectoroptionalSpecifies an advanced event selector for enabling data event logging. See: https://www.terraform.io/docs/providers/aws/r/cloudtrail.html for details on this variable
Type:
list(object({
name = optional(string)
field_selector = list(object({
field = string
ends_with = optional(list(string))
not_ends_with = optional(list(string))
equals = optional(list(string))
not_equals = optional(list(string))
starts_with = optional(list(string))
not_starts_with = optional(list(string))
}))
}))Default value:
[ ]cloud_watch_logs_group_arn(string) optionalSpecifies a log group name using an Amazon Resource Name (ARN), that represents the log group to which CloudTrail logs will be delivered
Default value:
""cloud_watch_logs_role_arn(string) optionalSpecifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group
Default value:
""enable_log_file_validation(bool) optionalSpecifies whether log file integrity validation is enabled. Creates signed digest for validated contents of logs
Default value:
trueenable_logging(bool) optionalEnable logging for the trail
Default value:
trueevent_selectoroptionalSpecifies an event selector for enabling data event logging. See: https://www.terraform.io/docs/providers/aws/r/cloudtrail.html for details on this variable
Type:
list(object({
include_management_events = bool
read_write_type = string
exclude_management_event_sources = optional(set(string))
data_resource = list(object({
type = string
values = list(string)
}))
}))Default value:
[ ]include_global_service_events(bool) optionalSpecifies whether the trail is publishing events from global services such as IAM to the log files
Default value:
falseinsight_selectoroptionalSpecifies an insight selector for type of insights to log on a trail
Type:
list(object({
insight_type = string
}))Default value:
[ ]is_multi_region_trail(bool) optionalSpecifies whether the trail is created in the current region or in all regions
Default value:
trueis_organization_trail(bool) optionalThe trail is an AWS Organizations trail
Default value:
falsekms_key_arn(string) optionalSpecifies the KMS key ARN to use to encrypt the logs delivered by CloudTrail
Default value:
""s3_key_prefix(string) optionalPrefix for S3 bucket used by Cloudtrail to store logs
Default value:
nullsns_topic_name(string) optionalSpecifies the name of the Amazon SNS topic defined for notification of log file delivery
Default value:
null
Context Variables
The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.
context.tf file of this module and part of the terraform-null-label pattern.Outputs
cloudtrail_arnThe Amazon Resource Name of the trail
cloudtrail_home_regionThe region in which the trail was created
cloudtrail_idThe ID of the trail. (Name for provider < v5, ARN for provider >= v5).
Dependencies
Requirements
terraform, version:>= 1.3.0aws, version:>= 3.0
Providers
aws, version:>= 3.0
Modules
| Name | Version | Source | Description |
|---|---|---|---|
this | 0.25.0 | cloudposse/label/null | n/a |
Resources
The following resources are used by this module:
aws_cloudtrail.default(resource)
Data Sources
The following data sources are used by this module: