Skip to content

Commit

Permalink
explicitly block public access (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajliv authored Aug 18, 2020
1 parent 7a2ef5a commit 59f0fc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ variable "force_destroy" {
default = true
}

# ensure bucket access is "Bucket and objects not public"
variable "block_public_access" {
default = true
}

# bucket for storing tf state
resource "aws_s3_bucket" "bucket" {
bucket = "tf-state-${var.application}"
Expand Down Expand Up @@ -64,6 +69,17 @@ resource "aws_s3_bucket" "bucket" {
}
}

# explicitly block public access
resource "aws_s3_bucket_public_access_block" "bucket" {
count = var.block_public_access ? 1 : 0

bucket = aws_s3_bucket.bucket.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

# lookup the role arn
data "aws_iam_role" "role" {
name = var.role
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Useful for creating a common bucket naming convention and attaching a bucket pol
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| application | the application that will be using this remote state | string | - | yes |
| block\_public\_access | ensure bucket access is "Bucket and objects not public" | bool | `true` | no |
| multipart\_days | | string | `3` | no |
| multipart\_delete | incomplete multipart upload deletion | string | `true` | no |
| role | the primary role that will be used to access the tf remote state | string | - | yes |
Expand All @@ -34,7 +35,7 @@ provider "aws" {
}
module "tf_remote_state" {
source = "github.com/turnerlabs/terraform-remote-state?ref=v3.1.0"
source = "github.com/turnerlabs/terraform-remote-state?ref=v4.0.0"
role = "aws-ent-prod-devops"
application = "my-test-app"
Expand Down

0 comments on commit 59f0fc2

Please sign in to comment.