Skip to content

Instantly share code, notes, and snippets.

@100daysofdevops
Created February 13, 2019 00:10
Show Gist options
  • Save 100daysofdevops/8f0a56dabddd482fd2936ca3def2f9fa to your computer and use it in GitHub Desktop.
Save 100daysofdevops/8f0a56dabddd482fd2936ca3def2f9fa to your computer and use it in GitHub Desktop.
provider "aws" {
region = "us-west-2"
}
resource "aws_cloudtrail" "my-demo-cloudtrail" {
name = "my-demo-cloudtrail-terraform"
s3_bucket_name = "${aws_s3_bucket.s3_bucket_name.id}"
include_global_service_events = true
is_multi_region_trail = true
enable_log_file_validation = true
}
resource "aws_s3_bucket" "s3_bucket_name" {
bucket = "s3-cloudtrail-bucket-with-terraform-code"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::s3-cloudtrail-bucket-with-terraform-code"
},
{
"Sid": "AWSCloudTrailWrite",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::s3-cloudtrail-bucket-with-terraform-code/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}
]
}
POLICY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment