diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9729b21e..96d7f3cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.21.0 + rev: v1.27.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 diff --git a/README.md b/README.md index 0c94e019..39440e8f 100644 --- a/README.md +++ b/README.md @@ -77,30 +77,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 +## 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 | Whether Amazon S3 should block public ACLs for this bucket. | `bool` | `false` | no | +| block\_public\_policy | 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 | 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 | 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 diff --git a/examples/complete/README.md b/examples/complete/README.md index 417ea522..966dfe84 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -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. +## Providers + +| Name | Version | +|------|---------| +| aws | n/a | +| random | n/a | + +## Inputs + +No input. + ## Outputs | Name | Description | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 4af31468..01c589a0 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -174,4 +174,10 @@ module "s3_bucket" { } } } + + // S3 bucket-level Public Access Block configuration + block_public_acls = true + block_public_policy = true + ignore_public_acls = true + restrict_public_buckets = true } diff --git a/examples/s3-replication/README.md b/examples/s3-replication/README.md index c4a10321..b95b6d10 100644 --- a/examples/s3-replication/README.md +++ b/examples/s3-replication/README.md @@ -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. +## Providers + +| Name | Version | +|------|---------| +| aws | n/a | +| aws.replica | n/a | +| random | n/a | + +## Inputs + +No input. + ## Outputs | Name | Description | diff --git a/main.tf b/main.tf index 4ea6f158..dcda139b 100644 --- a/main.tf +++ b/main.tf @@ -251,3 +251,16 @@ data "aws_iam_policy_document" "elb_log_delivery" { ] } } + +resource "aws_s3_bucket_public_access_block" "this" { + count = var.create_bucket ? 1 : 0 + + // Chain resources (s3_bucket -> s3_bucket_policy -> s3_bucket_public_access_block) + // to prevent "A conflicting conditional operation is currently in progress against this resource." + bucket = (var.attach_elb_log_delivery_policy || var.attach_policy) ? aws_s3_bucket_policy.this[0].id : 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 +} diff --git a/variables.tf b/variables.tf index f659aa68..699dd1fa 100644 --- a/variables.tf +++ b/variables.tf @@ -117,3 +117,27 @@ variable "object_lock_configuration" { type = any default = {} } + +variable "block_public_acls" { + description = "Whether Amazon S3 should block public ACLs for this bucket." + type = bool + default = false +} + +variable "block_public_policy" { + description = "Whether Amazon S3 should block public bucket policies for this bucket." + type = bool + default = false +} + +variable "ignore_public_acls" { + description = "Whether Amazon S3 should ignore public ACLs for this bucket." + type = bool + default = false +} + +variable "restrict_public_buckets" { + description = "Whether Amazon S3 should restrict public bucket policies for this bucket." + type = bool + default = false +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 00000000..ac4ff303 --- /dev/null +++ b/versions.tf @@ -0,0 +1,7 @@ +terraform { + required_version = "~> 0.12.6" + + required_providers { + aws = "~> 2.35" + } +}