Advertisement
Guest User

Untitled

a guest
Dec 21st, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.18 KB | None | 0 0
  1. locals {
  2.   head_cloudtrail_s3_bucket_name = "com.example.head.cloudtrail"
  3. }
  4.  
  5. data "aws_caller_identity" "current" {}
  6.  
  7. resource "aws_cloudtrail" "head_cloudtrail" {
  8.   name = "tf-head-cloudtrail"
  9.   s3_key_prefix = ""
  10.   s3_bucket_name = aws_s3_bucket.head_cloudtrail_s3.id
  11.  
  12.   is_multi_region_trail = true
  13.   is_organization_trail = true
  14.   include_global_service_events = true
  15.  
  16.   enable_logging = true
  17.  
  18.   depends_on = [
  19.     aws_s3_bucket.head_cloudtrail_s3
  20.   ]
  21. }
  22.  
  23. resource "aws_s3_bucket" "head_cloudtrail_s3" {
  24.   bucket = local.head_cloudtrail_s3_bucket_name
  25.   acl = "private"
  26.  
  27.   versioning {
  28.     enabled = false
  29.   }
  30.  
  31.   force_destroy = false
  32. }
  33.  
  34. resource "aws_s3_bucket_public_access_block" "head_cloudtrail_s3_access" {
  35.   bucket = aws_s3_bucket.head_cloudtrail_s3.id
  36.  
  37.   block_public_acls = true
  38.   block_public_policy = true
  39.   ignore_public_acls = true
  40.   restrict_public_buckets = true
  41. }
  42.  
  43. resource "aws_s3_bucket_policy" "head_cloudtrail_s3_policy" {
  44.   bucket = aws_s3_bucket.head_cloudtrail_s3.id
  45.  
  46.   policy = <<POLICY
  47. {
  48.     "Version": "2012-10-17",
  49.     "Statement": [
  50.         {
  51.             "Sid": "AWSCloudTrailAclCheck20150319",
  52.             "Effect": "Allow",
  53.             "Principal": {
  54.               "Service": "cloudtrail.amazonaws.com"
  55.             },
  56.             "Action": "s3:GetBucketAcl",
  57.             "Resource": "arn:aws:s3:::${local.head_cloudtrail_s3_bucket_name}"
  58.         },
  59.         {
  60.             "Sid": "AWSCloudTrailWrite20150319",
  61.             "Effect": "Allow",
  62.             "Principal": {
  63.               "Service": "cloudtrail.amazonaws.com"
  64.             },
  65.             "Action": [
  66.                 "s3:PutObject"
  67.             ],
  68.             "Resource": [
  69.                 "arn:aws:s3:::${local.head_cloudtrail_s3_bucket_name}/head/AWSLogs/${data.aws_caller_identity.current.account_id}/*",
  70.                 "arn:aws:s3:::${local.head_cloudtrail_s3_bucket_name}/prod/AWSLogs/1234556788976/*"
  71.             ],
  72.             "Condition": {
  73.                 "StringEquals": {
  74.                     "s3:x-amz-acl": "bucket-owner-full-control"
  75.                 }
  76.             }
  77.         }
  78.     ]
  79. }
  80. POLICY
  81.  
  82.   depends_on = [
  83.     aws_s3_bucket.head_cloudtrail_s3
  84.   ]
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement