-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Account-level Public Access Block module, and minor fixes…
… as fallback (#299)
- Loading branch information
1 parent
8b855f8
commit 69f0f4e
Showing
17 changed files
with
343 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# S3 account-level Public Access Block | ||
|
||
Configuration in this directory creates S3 account-level Public Access Block. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.70 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
No providers. | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_account_public_access"></a> [account\_public\_access](#module\_account\_public\_access) | ../../modules/account-public-access | n/a | | ||
|
||
## Resources | ||
|
||
No resources. | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_s3_account_public_access_block_id"></a> [s3\_account\_public\_access\_block\_id](#output\_s3\_account\_public\_access\_block\_id) | AWS account ID | | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
provider "aws" { | ||
region = local.region | ||
|
||
# Make it faster by skipping something | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
} | ||
|
||
locals { | ||
region = "eu-west-1" | ||
} | ||
|
||
module "account_public_access" { | ||
source = "../../modules/account-public-access" | ||
|
||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "s3_account_public_access_block_id" { | ||
description = "AWS account ID" | ||
value = module.account_public_access.s3_account_public_access_block_id | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.70" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# S3 account-level Public Access Block | ||
|
||
Manages S3 account-level Public Access Block configuration. | ||
|
||
## Note | ||
|
||
Each AWS account may only have one S3 Public Access Block configuration. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.74 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.74 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_s3_account_public_access_block.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_account_public_access_block) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | AWS account ID | `string` | `null` | no | | ||
| <a name="input_block_public_acls"></a> [block\_public\_acls](#input\_block\_public\_acls) | Whether Amazon S3 should block public ACLs for buckets in this account. | `bool` | `false` | no | | ||
| <a name="input_block_public_policy"></a> [block\_public\_policy](#input\_block\_public\_policy) | Whether Amazon S3 should block public bucket policies for buckets in this account. | `bool` | `false` | no | | ||
| <a name="input_create"></a> [create](#input\_create) | Whether to create this resource or not? | `bool` | `true` | no | | ||
| <a name="input_ignore_public_acls"></a> [ignore\_public\_acls](#input\_ignore\_public\_acls) | Whether Amazon S3 should ignore public ACLs for buckets in this account. | `bool` | `false` | no | | ||
| <a name="input_restrict_public_buckets"></a> [restrict\_public\_buckets](#input\_restrict\_public\_buckets) | Whether Amazon S3 should restrict public bucket policies for buckets in this account. | `bool` | `false` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_s3_account_public_access_block_id"></a> [s3\_account\_public\_access\_block\_id](#output\_s3\_account\_public\_access\_block\_id) | AWS account ID | | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "aws_s3_account_public_access_block" "this" { | ||
count = var.create ? 1 : 0 | ||
|
||
account_id = var.account_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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "s3_account_public_access_block_id" { | ||
description = "AWS account ID" | ||
value = try(aws_s3_account_public_access_block.this[0].id, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
variable "create" { | ||
description = "Whether to create this resource or not?" | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "account_id" { | ||
description = "AWS account ID" | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "block_public_acls" { | ||
description = "Whether Amazon S3 should block public ACLs for buckets in this account." | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "block_public_policy" { | ||
description = "Whether Amazon S3 should block public bucket policies for buckets in this account." | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "ignore_public_acls" { | ||
description = "Whether Amazon S3 should ignore public ACLs for buckets in this account." | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "restrict_public_buckets" { | ||
description = "Whether Amazon S3 should restrict public bucket policies for buckets in this account." | ||
type = bool | ||
default = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 3.74" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Wrapper for module: `modules/account-public-access` | ||
|
||
The configuration in this directory contains an implementation of a single module wrapper pattern, which allows managing several copies of a module in places where using the native Terraform 0.13+ `for_each` feature is not feasible (e.g., with Terragrunt). | ||
|
||
You may want to use a single Terragrunt configuration file to manage multiple resources without duplicating `terragrunt.hcl` files for each copy of the same module. | ||
|
||
This wrapper does not implement any extra functionality. | ||
|
||
## Usage with Terragrunt | ||
|
||
`terragrunt.hcl`: | ||
|
||
```hcl | ||
terraform { | ||
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers/account-public-access" | ||
# Alternative source: | ||
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers/account-public-access?ref=master" | ||
} | ||
inputs = { | ||
defaults = { # Default values | ||
create = true | ||
tags = { | ||
Terraform = "true" | ||
Environment = "dev" | ||
} | ||
} | ||
items = { | ||
my-item = { | ||
# omitted... can be any argument supported by the module | ||
} | ||
my-second-item = { | ||
# omitted... can be any argument supported by the module | ||
} | ||
# omitted... | ||
} | ||
} | ||
``` | ||
|
||
## Usage with Terraform | ||
|
||
```hcl | ||
module "wrapper" { | ||
source = "terraform-aws-modules/s3-bucket/aws//wrappers/account-public-access" | ||
defaults = { # Default values | ||
create = true | ||
tags = { | ||
Terraform = "true" | ||
Environment = "dev" | ||
} | ||
} | ||
items = { | ||
my-item = { | ||
# omitted... can be any argument supported by the module | ||
} | ||
my-second-item = { | ||
# omitted... can be any argument supported by the module | ||
} | ||
# omitted... | ||
} | ||
} | ||
``` | ||
|
||
## Example: Manage multiple S3 buckets in one Terragrunt layer | ||
|
||
`eu-west-1/s3-buckets/terragrunt.hcl`: | ||
|
||
```hcl | ||
terraform { | ||
source = "tfr:///terraform-aws-modules/s3-bucket/aws//wrappers" | ||
# Alternative source: | ||
# source = "git::[email protected]:terraform-aws-modules/terraform-aws-s3-bucket.git//wrappers?ref=master" | ||
} | ||
inputs = { | ||
defaults = { | ||
force_destroy = true | ||
attach_elb_log_delivery_policy = true | ||
attach_lb_log_delivery_policy = true | ||
attach_deny_insecure_transport_policy = true | ||
attach_require_latest_tls_policy = true | ||
} | ||
items = { | ||
bucket1 = { | ||
bucket = "my-random-bucket-1" | ||
} | ||
bucket2 = { | ||
bucket = "my-random-bucket-2" | ||
tags = { | ||
Secure = "probably" | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module "wrapper" { | ||
source = "../../modules/account-public-access" | ||
|
||
for_each = var.items | ||
|
||
account_id = try(each.value.account_id, var.defaults.account_id, null) | ||
block_public_acls = try(each.value.block_public_acls, var.defaults.block_public_acls, false) | ||
block_public_policy = try(each.value.block_public_policy, var.defaults.block_public_policy, false) | ||
create = try(each.value.create, var.defaults.create, true) | ||
ignore_public_acls = try(each.value.ignore_public_acls, var.defaults.ignore_public_acls, false) | ||
restrict_public_buckets = try(each.value.restrict_public_buckets, var.defaults.restrict_public_buckets, false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output "wrapper" { | ||
description = "Map of outputs of a wrapper." | ||
value = module.wrapper | ||
# sensitive = false # No sensitive module output found | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "defaults" { | ||
description = "Map of default values which will be used for each item." | ||
type = any | ||
default = {} | ||
} | ||
|
||
variable "items" { | ||
description = "Maps of items to create a wrapper from. Values are passed through to the module." | ||
type = any | ||
default = {} | ||
} |
Oops, something went wrong.