From 68dfcc63c416cdad07fddbc94e971193216a1d8d Mon Sep 17 00:00:00 2001 From: Don Badrak Date: Mon, 22 Jun 2020 14:30:25 -0400 Subject: [PATCH 1/4] ignore logs, .terraform --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1fef4ab..4df0dc1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ # .tfvars files *.tfvars + +.terraform/* +logs From 6bad39ba9739a92c587a9a47800811e44993f1ff Mon Sep 17 00:00:00 2001 From: Don Badrak Date: Mon, 22 Jun 2020 14:30:35 -0400 Subject: [PATCH 2/4] add tags --- variables.tf | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/variables.tf b/variables.tf index 429b59f..771bef0 100644 --- a/variables.tf +++ b/variables.tf @@ -1,16 +1,22 @@ variable "bucket_name" { description = "AWS Bucket Name" - type = string + type = string } variable "bucket_folders" { description = "List of folders (keys) to create after creation of bucket" - type = list(string) - default = [ ] + type = list(string) + default = [] } variable "kms_key_id" { description = "AWS KMS Key ID (one per bucket)" - type = string - default = "" + type = string + default = "" +} + +variable "tags" { + description = "AWS Tags" + type = map(string) + default = { } } From ecfd8a46d7be0497781bc948789a6270968b2837 Mon Sep 17 00:00:00 2001 From: Don Badrak Date: Mon, 22 Jun 2020 14:30:51 -0400 Subject: [PATCH 3/4] change resource names --- main.tf | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/main.tf b/main.tf index 6cb18d3..18b081d 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,9 @@ +locals { + enforced_tags = { + "boc:safeguard" = "title26" + } +} + #--- # s3 bucket #--- @@ -22,7 +28,14 @@ resource "aws_s3_bucket" "this" { prevent_destroy = true } -data "aws_iam_policy_document" "t26_s3" { + tags = merge( + var.tags, + local.enforced_tags, + map("Name", var.bucket_name) + ) +} + +data "aws_iam_policy_document" "this" { statement { sid = "DenyIncorrectEncryptionHeader" effect = "Deny" @@ -31,7 +44,7 @@ data "aws_iam_policy_document" "t26_s3" { type = "AWS" identifiers = ["*"] } - resources = ["${aws_s3_bucket.t26.arn}/*"] + resources = ["${aws_s3_bucket.this.arn}/*"] condition { test = "StringNotEquals" variable = "s3:x-amz-server-side-encryption" @@ -46,22 +59,21 @@ data "aws_iam_policy_document" "t26_s3" { type = "AWS" identifiers = ["*"] } - resources = ["${aws_s3_bucket.t26.arn}/*"] + resources = ["${aws_s3_bucket.this.arn}/*"] condition { test = "Null" variable = "s3:x-amz-server-side-encryption" - values = ["true"] + values = ["true"] } } +} - tags = merge( - var.tags, - local.enforced_tags, - map( "Name", var.bucket_name) - ) - +resource "null_resource" "s3_create_wait" { + triggers = { + bucket = aws_s3_bucket.this.id + } provisioner "local-exec" { - when = create + when = create command = "sleep 120" } } @@ -69,8 +81,8 @@ data "aws_iam_policy_document" "t26_s3" { resource "aws_s3_bucket_object" "this_objects" { bucket = aws_s3_bucket.this.id count = length(var.bucket_folders) - key = format("%s/",element(var.bucket_folders,count.index)) + key = format("%s/", element(var.bucket_folders, count.index)) source = "/dev/null" - depends_on [aws_s3_bucket.this] + depends_on = [aws_s3_bucket.this] } From feb30724bbf732f89b79bdd0d60772d18c51c9ce Mon Sep 17 00:00:00 2001 From: Don Badrak Date: Mon, 22 Jun 2020 14:32:47 -0400 Subject: [PATCH 4/4] change depends_on --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 18b081d..431f310 100644 --- a/main.tf +++ b/main.tf @@ -84,5 +84,5 @@ resource "aws_s3_bucket_object" "this_objects" { key = format("%s/", element(var.bucket_folders, count.index)) source = "/dev/null" - depends_on = [aws_s3_bucket.this] + depends_on = [null_resource.s3_create_wait] }