Skip to content

Commit

Permalink
Merge pull request #17 from terraform-modules/change-variable-names
Browse files Browse the repository at this point in the history
Change variable names
  • Loading branch information
badra001 committed Jun 22, 2020
2 parents f0e1cd1 + feb3072 commit 69489e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
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 = { }
}

0 comments on commit 69489e6

Please sign in to comment.