Skip to content

Change variable names #17

Merged
merged 4 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

# .tfvars files
*.tfvars

.terraform/*
logs
38 changes: 25 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
locals {
enforced_tags = {
"boc:safeguard" = "title26"
}
}

#---
# s3 bucket
#---
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -46,31 +59,30 @@ 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"
}
}

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 = [null_resource.s3_create_wait]
}
16 changes: 11 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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 = { }
}