Skip to content

Commit

Permalink
Merge pull request #1 from bluesentry/public-access
Browse files Browse the repository at this point in the history
Public access
  • Loading branch information
chris-mackubin authored Feb 7, 2020
2 parents 223f73b + 5d4ab76 commit dbdc377
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 99 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.21.0
rev: v1.25.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v2.5.0
hooks:
- id: check-merge-conflict
68 changes: 0 additions & 68 deletions CHANGELOG.md

This file was deleted.

7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

62 changes: 40 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# AWS S3 bucket Terraform module
[![GitHub Release](https://img.shields.io/github/v/release/bluesentry/tf-module.s3?style=plastic)](https://github.com/bluesentry/tf-module.s3/releases/latest)
![Terraform Compatibility](https://img.shields.io/badge/terraform-%3E%3D%200.12-blue?style=plastic)


Terraform module which creates S3 bucket on AWS with all (or almost all) features provided by Terraform AWS provider.

This type of resources are supported:

* [S3 Bucket](https://www.terraform.io/docs/providers/aws/r/s3_bucket.html)
* [S3 Bucket Policy](https://www.terraform.io/docs/providers/aws/r/s3_bucket_policy.html)
* [S3 Bucket Public Access Block](https://www.terraform.io/docs/providers/aws/r/s3_bucket_public_access_block.html)

These features of S3 bucket configurations are supported:

Expand All @@ -23,6 +27,10 @@ These features of S3 bucket configurations are supported:

Only Terraform 0.12 is supported.

## Module Development

Please review the [repo-setup](repo-setup.md) documentation related to local environment setup before modifying this repo.

## Usage

### Private bucket with versioning enabled
Expand Down Expand Up @@ -77,30 +85,40 @@ module "s3_bucket" {
* [Cross-Region Replication](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/tree/master/examples/s3-replication) - S3 bucket with Cross-Region Replication (CRR) enabled

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| acceleration\_status | (Optional) Sets the accelerate configuration of an existing bucket. Can be Enabled or Suspended. | string | `"null"` | no |
| acl | (Optional) The canned ACL to apply. Defaults to 'private'. | string | `"private"` | no |
| attach\_elb\_log\_delivery\_policy | Controls if S3 bucket should have ELB log delivery policy attached | bool | `"false"` | no |
| attach\_policy | Controls if S3 bucket should have bucket policy attached (set to `true` to use value of `policy` as bucket policy) | bool | `"false"` | no |
| bucket | (Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name. | string | `"null"` | no |
| bucket\_prefix | (Optional, Forces new resource) Creates a unique bucket name beginning with the specified prefix. Conflicts with bucket. | string | `"null"` | no |
| cors\_rule | Map containing a rule of Cross-Origin Resource Sharing. | any | `{}` | no |
| create\_bucket | Controls if S3 bucket should be created | bool | `"true"` | no |
| force\_destroy | (Optional, Default:false ) A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. | bool | `"false"` | no |
| lifecycle\_rule | List of maps containing configuration of object lifecycle management. | any | `[]` | no |
| logging | Map containing access bucket logging configuration. | map(string) | `{}` | no |
| object\_lock\_configuration | Map containing S3 object locking configuration. | any | `{}` | no |
| policy | (Optional) A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. | string | `"null"` | no |
| region | (Optional) If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee. | string | `"null"` | no |
| replication\_configuration | Map containing cross-region replication configuration. | any | `{}` | no |
| request\_payer | (Optional) Specifies who should bear the cost of Amazon S3 data transfer. Can be either BucketOwner or Requester. By default, the owner of the S3 bucket would incur the costs of any data transfer. See Requester Pays Buckets developer guide for more information. | string | `"null"` | no |
| server\_side\_encryption\_configuration | Map containing server-side encryption configuration. | any | `{}` | no |
| tags | (Optional) A mapping of tags to assign to the bucket. | map(string) | `{}` | no |
| versioning | Map containing versioning configuration. | map(string) | `{}` | no |
| website | Map containing static web-site hosting or redirect configuration. | map(string) | `{}` | no |
|------|-------------|------|---------|:-----:|
| acceleration\_status | (Optional) Sets the accelerate configuration of an existing bucket. Can be Enabled or Suspended. | `string` | n/a | yes |
| acl | (Optional) The canned ACL to apply. Defaults to 'private'. | `string` | `"private"` | no |
| attach\_elb\_log\_delivery\_policy | Controls if S3 bucket should have ELB log delivery policy attached | `bool` | `false` | no |
| attach\_policy | Controls if S3 bucket should have bucket policy attached (set to `true` to use value of `policy` as bucket policy) | `bool` | `false` | no |
| block\_public\_acls | (Optional) Whether Amazon S3 should block public ACLs for this bucket. | `bool` | `false` | no |
| block\_public\_policy | (Optional) Whether Amazon S3 should block public bucket policies for this bucket. | `bool` | `false` | no |
| bucket | (Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name. | `string` | n/a | yes |
| bucket\_prefix | (Optional, Forces new resource) Creates a unique bucket name beginning with the specified prefix. Conflicts with bucket. | `string` | n/a | yes |
| cors\_rule | Map containing a rule of Cross-Origin Resource Sharing. | `any` | `{}` | no |
| create\_bucket | Controls if S3 bucket should be created | `bool` | `true` | no |
| force\_destroy | (Optional, Default:false ) A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. | `bool` | `false` | no |
| ignore\_public\_acls | (Optional) Whether Amazon S3 should ignore public ACLs for this bucket. | `bool` | `false` | no |
| lifecycle\_rule | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no |
| logging | Map containing access bucket logging configuration. | `map(string)` | `{}` | no |
| object\_lock\_configuration | Map containing S3 object locking configuration. | `any` | `{}` | no |
| policy | (Optional) A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. | `string` | n/a | yes |
| region | (Optional) If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee. | `string` | n/a | yes |
| replication\_configuration | Map containing cross-region replication configuration. | `any` | `{}` | no |
| request\_payer | (Optional) Specifies who should bear the cost of Amazon S3 data transfer. Can be either BucketOwner or Requester. By default, the owner of the S3 bucket would incur the costs of any data transfer. See Requester Pays Buckets developer guide for more information. | `string` | n/a | yes |
| restrict\_public\_buckets | (Optional) Whether Amazon S3 should restrict public bucket policies for this bucket. | `bool` | `false` | no |
| server\_side\_encryption\_configuration | Map containing server-side encryption configuration. | `any` | `{}` | no |
| tags | (Optional) A mapping of tags to assign to the bucket. | `map(string)` | `{}` | no |
| versioning | Map containing versioning configuration. | `map(string)` | `{}` | no |
| website | Map containing static web-site hosting or redirect configuration. | `map(string)` | `{}` | no |

## Outputs

Expand All @@ -119,7 +137,7 @@ module "s3_bucket" {

## Authors

Module managed by [Anton Babenko](https://github.com/antonbabenko).
Module started from a fork of [terraform-aws-modules/terraform-aws-s3-bucket](terraform-aws-modules/terraform-aws-s3-bucket) by [Anton Babenko](https://github.com/antonbabenko).

## License

Expand Down
11 changes: 11 additions & 0 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Providers

| Name | Version |
|------|---------|
| aws | n/a |
| random | n/a |

## Inputs

No input.

## Outputs

| Name | Description |
Expand Down
12 changes: 12 additions & 0 deletions examples/s3-replication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Providers

| Name | Version |
|------|---------|
| aws | n/a |
| aws.replica | n/a |
| random | n/a |

## Inputs

No input.

## Outputs

| Name | Description |
Expand Down
10 changes: 10 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,13 @@ data "aws_iam_policy_document" "elb_log_delivery" {
]
}
}

resource "aws_s3_bucket_public_access_block" "this" {
count = var.create_bucket && (var.block_public_acls || var.block_public_policy || var.ignore_public_acls || var.restrict_public_buckets) ? 1 : 0

bucket = aws_s3_bucket.this[0].id
block_public_acls = var.block_public_acls
block_public_policy = var.block_public_policy
ignore_public_acls = var.ignore_public_acls
restrict_public_buckets = var.restrict_public_buckets
}
21 changes: 21 additions & 0 deletions repo-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Setup for developing on this repository

This repo is utilizing git hooks and [pre-commit](https://pre-commit.com/) to run some checks and automate readme documentation prior to committing to git

Install using homebrew:
```bash
brew install pre-commit gawk terraform-docs tflint
```

Install the git hook for you local environment to run the configured `pre-commit` actions automatically on `git commit`
```bash
pre-commit install
```

If you want to run all the pre-commit configured checks without doing a commit.
```bash
pre-commit run --all-files
```

### Firewall Note
If you are working from a location that restricts outgoing requests on non-standard ports. Note that pre-commit pulls dependent github repos via port `9418`
24 changes: 24 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,27 @@ variable "object_lock_configuration" {
type = any
default = {}
}

variable "block_public_acls" {
description = "(Optional) Whether Amazon S3 should block public ACLs for this bucket."
type = bool
default = false
}

variable "block_public_policy" {
description = "(Optional) Whether Amazon S3 should block public bucket policies for this bucket."
type = bool
default = false
}

variable "ignore_public_acls" {
description = "(Optional) Whether Amazon S3 should ignore public ACLs for this bucket."
type = bool
default = false
}

variable "restrict_public_buckets" {
description = "(Optional) Whether Amazon S3 should restrict public bucket policies for this bucket."
type = bool
default = false
}

0 comments on commit dbdc377

Please sign in to comment.