diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index bed3c96..30ba2ae 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,14 +1 @@ -# Use this file to define individuals or teams that are responsible for code in a repository. -# Read more: -# -# Order is important: the last matching pattern takes the most precedence - -# These owners will be the default owners for everything -* @cloudposse/engineering @cloudposse/contributors - -# Cloud Posse must review any changes to Makefiles -**/Makefile @cloudposse/engineering -**/Makefile.* @cloudposse/engineering - -# Cloud Posse must review any changes to GitHub actions -.github/* @cloudposse/engineering +* @sagansystems/platform diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index f3df96b..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: 'bug' -assignees: '' - ---- - -Found a bug? Maybe our [Slack Community](https://slack.cloudposse.com) can help. - -[![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) - -## Describe the Bug -A clear and concise description of what the bug is. - -## Expected Behavior -A clear and concise description of what you expected to happen. - -## Steps to Reproduce -Steps to reproduce the behavior: -1. Go to '...' -2. Run '....' -3. Enter '....' -4. See error - -## Screenshots -If applicable, add screenshots or logs to help explain your problem. - -## Environment (please complete the following information): - -Anything that will help us triage the bug will help. Here are some ideas: - - OS: [e.g. Linux, OSX, WSL, etc] - - Version [e.g. 10.15] - -## Additional Context -Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 76ae6d6..0000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,18 +0,0 @@ -blank_issues_enabled: false - -contact_links: - - - name: Community Slack Team - url: https://cloudposse.com/slack/ - about: |- - Please ask and answer questions here. - - - name: Office Hours - url: https://cloudposse.com/office-hours/ - about: |- - Join us every Wednesday for FREE Office Hours (lunch & learn). - - - name: DevOps Accelerator Program - url: https://cloudposse.com/accelerate/ - about: |- - Own your infrastructure in record time. We build it. You drive it. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 39a8686..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -name: Feature Request -about: Suggest an idea for this project -title: '' -labels: 'feature request' -assignees: '' - ---- - -Have a question? Please checkout our [Slack Community](https://slack.cloudposse.com) or visit our [Slack Archive](https://archive.sweetops.com/). - -[![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) - -## Describe the Feature - -A clear and concise description of what the bug is. - -## Expected Behavior - -A clear and concise description of what you expected to happen. - -## Use Case - -Is your feature request related to a problem/challenge you are trying to solve? Please provide some additional context of why this feature or capability will be valuable. - -## Describe Ideal Solution - -A clear and concise description of what you want to happen. If you don't know, that's okay. - -## Alternatives Considered - -Explain what alternative solutions or features you've considered. - -## Additional Context - -Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md deleted file mode 100644 index e69de29..0000000 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 4b8f32d..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,13 +0,0 @@ -## what -* Describe high-level what changed as a result of these commits (i.e. in plain-english, what do these changes mean?) -* Use bullet points to be concise and to the point. - -## why -* Provide the justifications for the changes (e.g. business case). -* Describe why these changes were made (e.g. why do these commits fix the problem?) -* Use bullet points to be concise and to the point. - -## references -* Link to any supporting github issues or helpful documentation to add some context (e.g. stackoverflow). -* Use `closes #123`, if this PR closes a GitHub issue `#123` - diff --git a/.github/auto-release.yml b/.github/auto-release.yml deleted file mode 100644 index 2836185..0000000 --- a/.github/auto-release.yml +++ /dev/null @@ -1,40 +0,0 @@ -name-template: 'v$RESOLVED_VERSION' -tag-template: '$RESOLVED_VERSION' -version-template: '$MAJOR.$MINOR.$PATCH' -version-resolver: - major: - labels: - - 'major' - minor: - labels: - - 'minor' - - 'enhancement' - patch: - labels: - - 'patch' - - 'fix' - - 'bugfix' - - 'bug' - - 'hotfix' - default: 'minor' - -categories: - - title: '🚀 Enhancements' - labels: - - 'enhancement' - - title: '🐛 Bug Fixes' - labels: - - 'fix' - - 'bugfix' - - 'bug' - - 'hotfix' - -change-template: | -
- $TITLE @$AUTHOR (#$NUMBER) - - $BODY -
- -template: | - $CHANGES diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml deleted file mode 100644 index e21fbfe..0000000 --- a/.github/workflows/auto-release.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: auto-release - -on: - push: - branches: - - master - -jobs: - semver: - runs-on: ubuntu-latest - steps: - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 - with: - publish: true - prerelease: false - config-name: auto-release.yml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/chatops.yml b/.github/workflows/chatops.yml deleted file mode 100644 index 0d94310..0000000 --- a/.github/workflows/chatops.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: chatops -on: - issue_comment: - types: [created] - -jobs: - default: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: "Handle common commands" - uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 - with: - token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} - reaction-token: ${{ secrets.GITHUB_TOKEN }} - repository: cloudposse/actions - commands: rebuild-readme, terraform-fmt - permission: triage - issue-type: pull-request - - test: - runs-on: ubuntu-latest - steps: - - name: "Checkout commit" - uses: actions/checkout@v2 - - name: "Run tests" - uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 - with: - token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} - reaction-token: ${{ secrets.GITHUB_TOKEN }} - repository: cloudposse/actions - commands: test - permission: triage - issue-type: pull-request - reactions: false - - diff --git a/.gitignore b/.gitignore index 408848f..36944f0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.tfstate *.tfstate.backup *.terraform.tfstate* +**/.terraform.lock.hcl # Module directory .terraform diff --git a/README.md b/README.md index bc34f47..ddb0746 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ + + # terraform-aws-s3-website [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-s3-website.svg)](https://github.com/cloudposse/terraform-aws-s3-website/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) + [![README Header][readme_header_img]][readme_header_link] @@ -25,8 +28,8 @@ --> -Terraform module to provision S3-backed Websites - +Terraform module to provision S3-backed Websites. +**IMPORTANT:** This module provisions a globally accessible S3 bucket for unauthenticated users because it is designed for hosting public static websites. Normally, AWS recommends that S3 buckets should not publicly accessible in order to protect S3 data from unauthorized users. --- @@ -58,19 +61,46 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are +## Security & Compliance [](https://bridgecrew.io/) + +Security scanning is graciously provided by Bridgecrew. Bridgecrew is the leading fully hosted, cloud-native solution providing continuous Terraform security and compliance. + +| Benchmark | Description | +|--------|---------------| +| [![Infrastructure Security](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/general)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=INFRASTRUCTURE+SECURITY) | Infrastructure Security Compliance | +| [![CIS KUBERNETES](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/cis_kubernetes)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=CIS+KUBERNETES+V1.5) | Center for Internet Security, KUBERNETES Compliance | +| [![CIS AWS](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/cis_aws)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=CIS+AWS+V1.2) | Center for Internet Security, AWS Compliance | +| [![CIS AZURE](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/cis_azure)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=CIS+AZURE+V1.1) | Center for Internet Security, AZURE Compliance | +| [![PCI-DSS](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/pci)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=PCI-DSS+V3.2) | Payment Card Industry Data Security Standards Compliance | +| [![NIST-800-53](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/nist)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=NIST-800-53) | National Institute of Standards and Technology Compliance | +| [![ISO27001](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/iso)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=ISO27001) | Information Security Management System, ISO/IEC 27001 Compliance | +| [![SOC2](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/soc2)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=SOC2)| Service Organization Control 2 Compliance | +| [![CIS GCP](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/cis_gcp)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=CIS+GCP+V1.1) | Center for Internet Security, GCP Compliance | +| [![HIPAA](https://www.bridgecrew.cloud/badges/github/cloudposse/terraform-aws-s3-website/hipaa)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=cloudposse%2Fterraform-aws-s3-website&benchmark=HIPAA) | Health Insurance Portability and Accountability Compliance | + + ## Usage -**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases. -Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-s3-website/releases). +**IMPORTANT:** We do not pin modules to versions in our examples because of the +difficulty of keeping the versions in the documentation in sync with the latest released versions. +We highly recommend that in your code you pin the version to the exact version you are +using so that your infrastructure remains stable, and update versions in a +systematic way so that they do not catch you by surprise. + +Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)), +the registry shows many of our inputs as required when in fact they are optional. +The table below correctly indicates which inputs are required. #### Create s3 website bucket ```hcl module "website" { - source = "git::https://github.com/cloudposse/terraform-aws-s3-website.git?ref=master" + source = "cloudposse/s3-website/aws" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" namespace = "eg" stage = "prod" name = "app" @@ -90,7 +120,9 @@ Required one of the `parent_zone_id` or `parent_zone_name` ```hcl module "website_with_cname" { - source = "git::https://github.com/cloudposse/terraform-aws-s3-website.git?ref=master" + source = "cloudposse/s3-website/aws" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" namespace = "eg" stage = "prod" name = "app" @@ -116,69 +148,98 @@ Available targets: ``` + ## Requirements | Name | Version | |------|---------| -| terraform | >= 0.12.0 | -| aws | ~> 2.0 | -| local | ~> 1.2 | -| null | ~> 2.0 | +| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [aws](#requirement\_aws) | >= 2.0 | +| [local](#requirement\_local) | >= 1.2 | ## Providers | Name | Version | |------|---------| -| aws | ~> 2.0 | +| [aws](#provider\_aws) | >= 2.0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [default\_label](#module\_default\_label) | cloudposse/label/null | 0.24.1 | +| [dns](#module\_dns) | cloudposse/route53-alias/aws | 0.12.0 | +| [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 0.20.0 | +| [this](#module\_this) | cloudposse/label/null | 0.24.1 | + +## Resources + +| Name | Type | +|------|------| +| [aws_s3_bucket.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | +| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource | +| [aws_iam_policy_document.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | +| [aws_iam_policy_document.deployment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | +| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| attributes | Additional attributes (e.g. `policy` or `role`) | `list(string)` | `[]` | no | -| cors\_allowed\_headers | List of allowed headers | `list(string)` |
[
"*"
]
| no | -| cors\_allowed\_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` |
[
"GET"
]
| no | -| cors\_allowed\_origins | List of allowed origins (e.g. example.com, test.com) | `list(string)` |
[
"*"
]
| no | -| cors\_expose\_headers | List of expose header in the response | `list(string)` |
[
"ETag"
]
| no | -| cors\_max\_age\_seconds | Time in seconds that browser can cache the response | `number` | `3600` | no | -| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | `string` | `"-"` | no | -| deployment\_actions | List of actions to permit deployment ARNs to perform | `list(string)` |
[
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation",
"s3:AbortMultipartUpload"
]
| no | -| deployment\_arns | (Optional) Map of deployment ARNs to lists of S3 path prefixes to grant `deployment_actions` permissions | `map(any)` | `{}` | no | -| error\_document | An absolute path to the document to return in case of a 4XX error | `string` | `"404.html"` | no | -| force\_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | `bool` | `false` | no | -| hostname | Name of website bucket in `fqdn` format (e.g. `test.example.com`). IMPORTANT! Do not add trailing dot (`.`) | `string` | n/a | yes | -| index\_document | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders | `string` | `"index.html"` | no | -| lifecycle\_rule\_enabled | Enable or disable lifecycle rule | `bool` | `false` | no | -| logs\_expiration\_days | Number of days after which to expunge the objects | `number` | `90` | no | -| logs\_glacier\_transition\_days | Number of days after which to move the data to the glacier storage tier | `number` | `60` | no | -| logs\_standard\_transition\_days | Number of days to persist in the standard storage tier before moving to the glacier tier | `number` | `30` | no | -| name | The Name of the application or solution (e.g. `bastion` or `portal`) | `string` | n/a | yes | -| namespace | Namespace (e.g. `eg` or `cp`) | `string` | `""` | no | -| noncurrent\_version\_expiration\_days | Specifies when noncurrent object versions expire | `number` | `90` | no | -| noncurrent\_version\_transition\_days | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | `number` | `30` | no | -| parent\_zone\_id | ID of the hosted zone to contain the record | `string` | `""` | no | -| parent\_zone\_name | Name of the hosted zone to contain the record | `string` | `""` | no | -| prefix | Prefix identifying one or more objects to which the rule applies | `string` | `""` | no | -| redirect\_all\_requests\_to | A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored | `string` | `""` | no | -| region | AWS region this bucket should reside in | `string` | `""` | no | -| replication\_source\_principal\_arns | (Optional) List of principal ARNs to grant replication access from different AWS accounts | `list(string)` | `[]` | no | -| routing\_rules | A json array containing routing rules describing redirect behavior and when redirects are applied | `string` | `""` | no | -| stage | Stage (e.g. `prod`, `dev`, `staging`) | `string` | `""` | no | -| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')`) | `map(string)` | `{}` | no | -| versioning\_enabled | Enable or disable versioning | `bool` | `false` | no | +| [additional\_tag\_map](#input\_additional\_tag\_map) | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | +| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | +| [cors\_allowed\_headers](#input\_cors\_allowed\_headers) | List of allowed headers | `list(string)` |
[
"*"
]
| no | +| [cors\_allowed\_methods](#input\_cors\_allowed\_methods) | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` |
[
"GET"
]
| no | +| [cors\_allowed\_origins](#input\_cors\_allowed\_origins) | List of allowed origins (e.g. example.com, test.com) | `list(string)` |
[
"*"
]
| no | +| [cors\_expose\_headers](#input\_cors\_expose\_headers) | List of expose header in the response | `list(string)` |
[
"ETag"
]
| no | +| [cors\_max\_age\_seconds](#input\_cors\_max\_age\_seconds) | Time in seconds that browser can cache the response | `number` | `3600` | no | +| [delimiter](#input\_delimiter) | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| [deployment\_actions](#input\_deployment\_actions) | List of actions to permit deployment ARNs to perform | `list(string)` |
[
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation",
"s3:AbortMultipartUpload"
]
| no | +| [deployment\_arns](#input\_deployment\_arns) | (Optional) Map of deployment ARNs to lists of S3 path prefixes to grant `deployment_actions` permissions | `map(any)` | `{}` | no | +| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | +| [encryption\_enabled](#input\_encryption\_enabled) | When set to 'true' the resource will have AES256 encryption enabled by default | `bool` | `false` | no | +| [environment](#input\_environment) | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | +| [error\_document](#input\_error\_document) | An absolute path to the document to return in case of a 4XX error | `string` | `"404.html"` | no | +| [force\_destroy](#input\_force\_destroy) | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | `bool` | `false` | no | +| [hostname](#input\_hostname) | Name of website bucket in `fqdn` format (e.g. `test.example.com`). IMPORTANT! Do not add trailing dot (`.`) | `string` | n/a | yes | +| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | +| [index\_document](#input\_index\_document) | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders | `string` | `"index.html"` | no | +| [label\_key\_case](#input\_label\_key\_case) | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no | +| [label\_order](#input\_label\_order) | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | +| [label\_value\_case](#input\_label\_value\_case) | The letter case of output label values (also used in `tags` and `id`).
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Default value: `lower`. | `string` | `null` | no | +| [lifecycle\_rule\_enabled](#input\_lifecycle\_rule\_enabled) | Enable or disable lifecycle rule | `bool` | `false` | no | +| [logs\_enabled](#input\_logs\_enabled) | Enable logs for s3 bucket | `bool` | `true` | no | +| [logs\_expiration\_days](#input\_logs\_expiration\_days) | Number of days after which to expunge the objects | `number` | `90` | no | +| [logs\_glacier\_transition\_days](#input\_logs\_glacier\_transition\_days) | Number of days after which to move the data to the glacier storage tier | `number` | `60` | no | +| [logs\_standard\_transition\_days](#input\_logs\_standard\_transition\_days) | Number of days to persist in the standard storage tier before moving to the glacier tier | `number` | `30` | no | +| [name](#input\_name) | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | +| [namespace](#input\_namespace) | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | +| [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | Specifies when noncurrent object versions expire | `number` | `90` | no | +| [noncurrent\_version\_transition\_days](#input\_noncurrent\_version\_transition\_days) | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | `number` | `30` | no | +| [parent\_zone\_id](#input\_parent\_zone\_id) | ID of the hosted zone to contain the record | `string` | `""` | no | +| [parent\_zone\_name](#input\_parent\_zone\_name) | Name of the hosted zone to contain the record | `string` | `""` | no | +| [prefix](#input\_prefix) | Prefix identifying one or more objects to which the rule applies | `string` | `""` | no | +| [redirect\_all\_requests\_to](#input\_redirect\_all\_requests\_to) | A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored | `string` | `""` | no | +| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | +| [replication\_source\_principal\_arns](#input\_replication\_source\_principal\_arns) | (Optional) List of principal ARNs to grant replication access from different AWS accounts | `list(string)` | `[]` | no | +| [routing\_rules](#input\_routing\_rules) | A json array containing routing rules describing redirect behavior and when redirects are applied | `string` | `""` | no | +| [stage](#input\_stage) | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | +| [tags](#input\_tags) | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | +| [versioning\_enabled](#input\_versioning\_enabled) | Enable or disable versioning | `bool` | `true` | no | ## Outputs | Name | Description | |------|-------------| -| hostname | Bucket hostname | -| s3\_bucket\_arn | ARN identifier of website bucket | -| s3\_bucket\_domain\_name | Name of website bucket | -| s3\_bucket\_hosted\_zone\_id | The Route 53 Hosted Zone ID for this bucket's region | -| s3\_bucket\_name | DNS record of website bucket | -| s3\_bucket\_website\_domain | The domain of the website endpoint | -| s3\_bucket\_website\_endpoint | The website endpoint URL | - +| [hostname](#output\_hostname) | Bucket hostname | +| [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | ARN identifier of the website bucket | +| [s3\_bucket\_domain\_name](#output\_s3\_bucket\_domain\_name) | Name of the website bucket | +| [s3\_bucket\_hosted\_zone\_id](#output\_s3\_bucket\_hosted\_zone\_id) | The Route 53 Hosted Zone ID for this bucket's region | +| [s3\_bucket\_name](#output\_s3\_bucket\_name) | DNS record of the website bucket | +| [s3\_bucket\_website\_domain](#output\_s3\_bucket\_website\_domain) | The domain of the website endpoint | +| [s3\_bucket\_website\_endpoint](#output\_s3\_bucket\_website\_endpoint) | The website endpoint URL | + @@ -189,6 +250,7 @@ Like this project? Please give it a ★ on [our GitHub](https://github.com/cloud Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) + ## Related Projects Check out these related projects. @@ -200,8 +262,6 @@ Check out these related projects. - [terraform-aws-lb-s3-bucket](https://github.com/cloudposse/terraform-aws-lb-s3-bucket) - Terraform module to provision an S3 bucket with built in IAM policy to allow AWS Load Balancers to ship access logs - - ## References For additional context, refer to some of these links. @@ -280,7 +340,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. ## Copyright -Copyright © 2017-2020 [Cloud Posse, LLC](https://cpco.io/copyright) +Copyright © 2017-2021 [Cloud Posse, LLC](https://cpco.io/copyright) @@ -337,8 +397,10 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply ### Contributors + | [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]
[Andriy Knysh][aknysh_homepage] | [![Vladimir][SweetOps_avatar]][SweetOps_homepage]
[Vladimir][SweetOps_homepage] | |---|---|---| + [osterman_homepage]: https://github.com/osterman [osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png diff --git a/README.yaml b/README.yaml index 735096c..4840317 100644 --- a/README.yaml +++ b/README.yaml @@ -50,14 +50,17 @@ related: url: "https://github.com/cloudposse/terraform-aws-lb-s3-bucket" # Short description of this project description: |- - Terraform module to provision S3-backed Websites + Terraform module to provision S3-backed Websites. + **IMPORTANT:** This module provisions a globally accessible S3 bucket for unauthenticated users because it is designed for hosting public static websites. Normally, AWS recommends that S3 buckets should not publicly accessible in order to protect S3 data from unauthorized users. # How to use this project usage: |- #### Create s3 website bucket ```hcl module "website" { - source = "git::https://github.com/cloudposse/terraform-aws-s3-website.git?ref=master" + source = "cloudposse/s3-website/aws" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" namespace = "eg" stage = "prod" name = "app" @@ -77,7 +80,9 @@ usage: |- ```hcl module "website_with_cname" { - source = "git::https://github.com/cloudposse/terraform-aws-s3-website.git?ref=master" + source = "cloudposse/s3-website/aws" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" namespace = "eg" stage = "prod" name = "app" diff --git a/context.tf b/context.tf new file mode 100644 index 0000000..81f99b4 --- /dev/null +++ b/context.tf @@ -0,0 +1,202 @@ +# +# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label +# All other instances of this file should be a copy of that one +# +# +# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf +# and then place it in your Terraform module to automatically get +# Cloud Posse's standard configuration inputs suitable for passing +# to Cloud Posse modules. +# +# Modules should access the whole context as `module.this.context` +# to get the input variables with nulls for defaults, +# for example `context = module.this.context`, +# and access individual variables as `module.this.`, +# with final values filled in. +# +# For example, when using defaults, `module.this.context.delimiter` +# will be null, and `module.this.delimiter` will be `-` (hyphen). +# + +module "this" { + source = "cloudposse/label/null" + version = "0.24.1" # requires Terraform >= 0.13.0 + + enabled = var.enabled + namespace = var.namespace + environment = var.environment + stage = var.stage + name = var.name + delimiter = var.delimiter + attributes = var.attributes + tags = var.tags + additional_tag_map = var.additional_tag_map + label_order = var.label_order + regex_replace_chars = var.regex_replace_chars + id_length_limit = var.id_length_limit + label_key_case = var.label_key_case + label_value_case = var.label_value_case + + context = var.context +} + +# Copy contents of cloudposse/terraform-null-label/variables.tf here + +variable "context" { + type = any + default = { + enabled = true + namespace = null + environment = null + stage = null + name = null + delimiter = null + attributes = [] + tags = {} + additional_tag_map = {} + regex_replace_chars = null + label_order = [] + id_length_limit = null + label_key_case = null + label_value_case = null + } + description = <<-EOT + Single object for setting entire context at once. + See description of individual variables for details. + Leave string and numeric variables as `null` to use default value. + Individual variable settings (non-null) override settings in context object, + except for attributes, tags, and additional_tag_map, which are merged. + EOT + + validation { + condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"]) + error_message = "Allowed values: `lower`, `title`, `upper`." + } + + validation { + condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"]) + error_message = "Allowed values: `lower`, `title`, `upper`, `none`." + } +} + +variable "enabled" { + type = bool + default = null + description = "Set to false to prevent the module from creating any resources" +} + +variable "namespace" { + type = string + default = null + description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'" +} + +variable "environment" { + type = string + default = null + description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'" +} + +variable "stage" { + type = string + default = null + description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'" +} + +variable "name" { + type = string + default = null + description = "Solution name, e.g. 'app' or 'jenkins'" +} + +variable "delimiter" { + type = string + default = null + description = <<-EOT + Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`. + Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. + EOT +} + +variable "attributes" { + type = list(string) + default = [] + description = "Additional attributes (e.g. `1`)" +} + +variable "tags" { + type = map(string) + default = {} + description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`" +} + +variable "additional_tag_map" { + type = map(string) + default = {} + description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`." +} + +variable "label_order" { + type = list(string) + default = null + description = <<-EOT + The naming order of the id output and Name tag. + Defaults to ["namespace", "environment", "stage", "name", "attributes"]. + You can omit any of the 5 elements, but at least one must be present. + EOT +} + +variable "regex_replace_chars" { + type = string + default = null + description = <<-EOT + Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. + If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. + EOT +} + +variable "id_length_limit" { + type = number + default = null + description = <<-EOT + Limit `id` to this many characters (minimum 6). + Set to `0` for unlimited length. + Set to `null` for default, which is `0`. + Does not affect `id_full`. + EOT + validation { + condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0 + error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length." + } +} + +variable "label_key_case" { + type = string + default = null + description = <<-EOT + The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`. + Possible values: `lower`, `title`, `upper`. + Default value: `title`. + EOT + + validation { + condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case) + error_message = "Allowed values: `lower`, `title`, `upper`." + } +} + +variable "label_value_case" { + type = string + default = null + description = <<-EOT + The letter case of output label values (also used in `tags` and `id`). + Possible values: `lower`, `title`, `upper` and `none` (no transformation). + Default value: `lower`. + EOT + + validation { + condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case) + error_message = "Allowed values: `lower`, `title`, `upper`, `none`." + } +} +#### End of copy of cloudposse/terraform-null-label/variables.tf diff --git a/docs/terraform.md b/docs/terraform.md index 24ccb98..74a4260 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -1,63 +1,92 @@ + ## Requirements | Name | Version | |------|---------| -| terraform | >= 0.12.0 | -| aws | ~> 2.0 | -| local | ~> 1.2 | -| null | ~> 2.0 | +| [terraform](#requirement\_terraform) | >= 0.13.0 | +| [aws](#requirement\_aws) | >= 2.0 | +| [local](#requirement\_local) | >= 1.2 | ## Providers | Name | Version | |------|---------| -| aws | ~> 2.0 | +| [aws](#provider\_aws) | >= 2.0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [default\_label](#module\_default\_label) | cloudposse/label/null | 0.24.1 | +| [dns](#module\_dns) | cloudposse/route53-alias/aws | 0.12.0 | +| [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 0.20.0 | +| [this](#module\_this) | cloudposse/label/null | 0.24.1 | + +## Resources + +| Name | Type | +|------|------| +| [aws_s3_bucket.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | +| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource | +| [aws_iam_policy_document.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | +| [aws_iam_policy_document.deployment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | +| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| attributes | Additional attributes (e.g. `policy` or `role`) | `list(string)` | `[]` | no | -| cors\_allowed\_headers | List of allowed headers | `list(string)` |
[
"*"
]
| no | -| cors\_allowed\_methods | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` |
[
"GET"
]
| no | -| cors\_allowed\_origins | List of allowed origins (e.g. example.com, test.com) | `list(string)` |
[
"*"
]
| no | -| cors\_expose\_headers | List of expose header in the response | `list(string)` |
[
"ETag"
]
| no | -| cors\_max\_age\_seconds | Time in seconds that browser can cache the response | `number` | `3600` | no | -| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | `string` | `"-"` | no | -| deployment\_actions | List of actions to permit deployment ARNs to perform | `list(string)` |
[
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation",
"s3:AbortMultipartUpload"
]
| no | -| deployment\_arns | (Optional) Map of deployment ARNs to lists of S3 path prefixes to grant `deployment_actions` permissions | `map(any)` | `{}` | no | -| error\_document | An absolute path to the document to return in case of a 4XX error | `string` | `"404.html"` | no | -| force\_destroy | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | `bool` | `false` | no | -| hostname | Name of website bucket in `fqdn` format (e.g. `test.example.com`). IMPORTANT! Do not add trailing dot (`.`) | `string` | n/a | yes | -| index\_document | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders | `string` | `"index.html"` | no | -| lifecycle\_rule\_enabled | Enable or disable lifecycle rule | `bool` | `false` | no | -| logs\_expiration\_days | Number of days after which to expunge the objects | `number` | `90` | no | -| logs\_glacier\_transition\_days | Number of days after which to move the data to the glacier storage tier | `number` | `60` | no | -| logs\_standard\_transition\_days | Number of days to persist in the standard storage tier before moving to the glacier tier | `number` | `30` | no | -| name | The Name of the application or solution (e.g. `bastion` or `portal`) | `string` | n/a | yes | -| namespace | Namespace (e.g. `eg` or `cp`) | `string` | `""` | no | -| noncurrent\_version\_expiration\_days | Specifies when noncurrent object versions expire | `number` | `90` | no | -| noncurrent\_version\_transition\_days | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | `number` | `30` | no | -| parent\_zone\_id | ID of the hosted zone to contain the record | `string` | `""` | no | -| parent\_zone\_name | Name of the hosted zone to contain the record | `string` | `""` | no | -| prefix | Prefix identifying one or more objects to which the rule applies | `string` | `""` | no | -| redirect\_all\_requests\_to | A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored | `string` | `""` | no | -| region | AWS region this bucket should reside in | `string` | `""` | no | -| replication\_source\_principal\_arns | (Optional) List of principal ARNs to grant replication access from different AWS accounts | `list(string)` | `[]` | no | -| routing\_rules | A json array containing routing rules describing redirect behavior and when redirects are applied | `string` | `""` | no | -| stage | Stage (e.g. `prod`, `dev`, `staging`) | `string` | `""` | no | -| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')`) | `map(string)` | `{}` | no | -| versioning\_enabled | Enable or disable versioning | `bool` | `false` | no | +| [additional\_tag\_map](#input\_additional\_tag\_map) | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no | +| [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no | +| [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | +| [cors\_allowed\_headers](#input\_cors\_allowed\_headers) | List of allowed headers | `list(string)` |
[
"*"
]
| no | +| [cors\_allowed\_methods](#input\_cors\_allowed\_methods) | List of allowed methods (e.g. GET, PUT, POST, DELETE, HEAD) | `list(string)` |
[
"GET"
]
| no | +| [cors\_allowed\_origins](#input\_cors\_allowed\_origins) | List of allowed origins (e.g. example.com, test.com) | `list(string)` |
[
"*"
]
| no | +| [cors\_expose\_headers](#input\_cors\_expose\_headers) | List of expose header in the response | `list(string)` |
[
"ETag"
]
| no | +| [cors\_max\_age\_seconds](#input\_cors\_max\_age\_seconds) | Time in seconds that browser can cache the response | `number` | `3600` | no | +| [delimiter](#input\_delimiter) | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| [deployment\_actions](#input\_deployment\_actions) | List of actions to permit deployment ARNs to perform | `list(string)` |
[
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:GetBucketLocation",
"s3:AbortMultipartUpload"
]
| no | +| [deployment\_arns](#input\_deployment\_arns) | (Optional) Map of deployment ARNs to lists of S3 path prefixes to grant `deployment_actions` permissions | `map(any)` | `{}` | no | +| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | +| [encryption\_enabled](#input\_encryption\_enabled) | When set to 'true' the resource will have AES256 encryption enabled by default | `bool` | `false` | no | +| [environment](#input\_environment) | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | +| [error\_document](#input\_error\_document) | An absolute path to the document to return in case of a 4XX error | `string` | `"404.html"` | no | +| [force\_destroy](#input\_force\_destroy) | Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`) | `bool` | `false` | no | +| [hostname](#input\_hostname) | Name of website bucket in `fqdn` format (e.g. `test.example.com`). IMPORTANT! Do not add trailing dot (`.`) | `string` | n/a | yes | +| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | +| [index\_document](#input\_index\_document) | Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders | `string` | `"index.html"` | no | +| [label\_key\_case](#input\_label\_key\_case) | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no | +| [label\_order](#input\_label\_order) | The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no | +| [label\_value\_case](#input\_label\_value\_case) | The letter case of output label values (also used in `tags` and `id`).
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Default value: `lower`. | `string` | `null` | no | +| [lifecycle\_rule\_enabled](#input\_lifecycle\_rule\_enabled) | Enable or disable lifecycle rule | `bool` | `false` | no | +| [logs\_enabled](#input\_logs\_enabled) | Enable logs for s3 bucket | `bool` | `true` | no | +| [logs\_expiration\_days](#input\_logs\_expiration\_days) | Number of days after which to expunge the objects | `number` | `90` | no | +| [logs\_glacier\_transition\_days](#input\_logs\_glacier\_transition\_days) | Number of days after which to move the data to the glacier storage tier | `number` | `60` | no | +| [logs\_standard\_transition\_days](#input\_logs\_standard\_transition\_days) | Number of days to persist in the standard storage tier before moving to the glacier tier | `number` | `30` | no | +| [name](#input\_name) | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | +| [namespace](#input\_namespace) | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | +| [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | Specifies when noncurrent object versions expire | `number` | `90` | no | +| [noncurrent\_version\_transition\_days](#input\_noncurrent\_version\_transition\_days) | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | `number` | `30` | no | +| [parent\_zone\_id](#input\_parent\_zone\_id) | ID of the hosted zone to contain the record | `string` | `""` | no | +| [parent\_zone\_name](#input\_parent\_zone\_name) | Name of the hosted zone to contain the record | `string` | `""` | no | +| [prefix](#input\_prefix) | Prefix identifying one or more objects to which the rule applies | `string` | `""` | no | +| [redirect\_all\_requests\_to](#input\_redirect\_all\_requests\_to) | A hostname to redirect all website requests for this bucket to. If this is set `index_document` will be ignored | `string` | `""` | no | +| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | +| [replication\_source\_principal\_arns](#input\_replication\_source\_principal\_arns) | (Optional) List of principal ARNs to grant replication access from different AWS accounts | `list(string)` | `[]` | no | +| [routing\_rules](#input\_routing\_rules) | A json array containing routing rules describing redirect behavior and when redirects are applied | `string` | `""` | no | +| [stage](#input\_stage) | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | +| [tags](#input\_tags) | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | no | +| [versioning\_enabled](#input\_versioning\_enabled) | Enable or disable versioning | `bool` | `true` | no | ## Outputs | Name | Description | |------|-------------| -| hostname | Bucket hostname | -| s3\_bucket\_arn | ARN identifier of website bucket | -| s3\_bucket\_domain\_name | Name of website bucket | -| s3\_bucket\_hosted\_zone\_id | The Route 53 Hosted Zone ID for this bucket's region | -| s3\_bucket\_name | DNS record of website bucket | -| s3\_bucket\_website\_domain | The domain of the website endpoint | -| s3\_bucket\_website\_endpoint | The website endpoint URL | - +| [hostname](#output\_hostname) | Bucket hostname | +| [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | ARN identifier of the website bucket | +| [s3\_bucket\_domain\_name](#output\_s3\_bucket\_domain\_name) | Name of the website bucket | +| [s3\_bucket\_hosted\_zone\_id](#output\_s3\_bucket\_hosted\_zone\_id) | The Route 53 Hosted Zone ID for this bucket's region | +| [s3\_bucket\_name](#output\_s3\_bucket\_name) | DNS record of the website bucket | +| [s3\_bucket\_website\_domain](#output\_s3\_bucket\_website\_domain) | The domain of the website endpoint | +| [s3\_bucket\_website\_endpoint](#output\_s3\_bucket\_website\_endpoint) | The website endpoint URL | + diff --git a/examples/complete/fixtures.us-west-1.tfvars b/examples/complete/fixtures.us-west-1.tfvars deleted file mode 100644 index 3ee7c4c..0000000 --- a/examples/complete/fixtures.us-west-1.tfvars +++ /dev/null @@ -1,14 +0,0 @@ -region = "us-west-1" - -namespace = "eg" - -stage = "test" - -# name and hostname will be set up in test file, see 'examples_complete_test.go' -#name = "s3-website-test" - -#hostname = "s3-website-test.testing.cloudposse.co" - -parent_zone_name = "testing.cloudposse.co" - -force_destroy = true diff --git a/examples/complete/main.tf b/examples/complete/main.tf deleted file mode 100644 index 1918c1a..0000000 --- a/examples/complete/main.tf +++ /dev/null @@ -1,13 +0,0 @@ -provider "aws" { - region = var.region -} - -module "s3_website" { - source = "../../" - namespace = var.namespace - stage = var.stage - name = var.name - hostname = var.hostname - parent_zone_name = var.parent_zone_name - force_destroy = var.force_destroy -} diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf deleted file mode 100644 index d0769f7..0000000 --- a/examples/complete/outputs.tf +++ /dev/null @@ -1,34 +0,0 @@ -output "hostname" { - value = var.hostname - description = "Bucket hostname" -} - -output "s3_bucket_name" { - value = module.s3_website.s3_bucket_name - description = "DNS record of website bucket" -} - -output "s3_bucket_domain_name" { - value = module.s3_website.s3_bucket_domain_name - description = "Name of of website bucket" -} - -output "s3_bucket_arn" { - value = module.s3_website.s3_bucket_arn - description = "Name of of website bucket" -} - -output "s3_bucket_website_endpoint" { - value = module.s3_website.s3_bucket_website_endpoint - description = "The website endpoint URL" -} - -output "s3_bucket_website_domain" { - value = module.s3_website.s3_bucket_website_domain - description = "The domain of the website endpoint" -} - -output "s3_bucket_hosted_zone_id" { - value = module.s3_website.s3_bucket_hosted_zone_id - description = "The Route 53 Hosted Zone ID for this bucket's region" -} diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf deleted file mode 100644 index 98ccf36..0000000 --- a/examples/complete/variables.tf +++ /dev/null @@ -1,34 +0,0 @@ -variable "region" { - type = string - description = "AWS region" -} - -variable "name" { - type = string - description = "The Name of the application or solution (e.g. `bastion` or `portal`)" -} - -variable "namespace" { - type = string - description = "Namespace (e.g. `eg` or `cp`)" -} - -variable "stage" { - type = string - description = "Stage (e.g. `prod`, `dev`, `staging`)" -} - -variable "hostname" { - type = string - description = "Name of website bucket in `fqdn` format (e.g. `test.example.com`). IMPORTANT! Do not add trailing dot (`.`)" -} - -variable "parent_zone_name" { - type = string - description = "Name of the hosted zone to contain the record" -} - -variable "force_destroy" { - type = bool - description = "Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`)" -} diff --git a/main.tf b/main.tf index 7e55c4d..0d53d89 100644 --- a/main.tf +++ b/main.tf @@ -16,37 +16,41 @@ locals { } module "logs" { - source = "git::https://github.com/cloudposse/terraform-aws-s3-log-storage.git?ref=tags/0.13.1" - name = var.name - stage = var.stage - namespace = var.namespace - delimiter = var.delimiter - attributes = compact(concat(var.attributes, ["logs"])) + source = "cloudposse/s3-log-storage/aws" + version = "0.20.0" + attributes = ["logs"] + enabled = var.logs_enabled standard_transition_days = var.logs_standard_transition_days glacier_transition_days = var.logs_glacier_transition_days expiration_days = var.logs_expiration_days + force_destroy = var.force_destroy + versioning_enabled = var.logs_object_versioning_enabled + + context = module.this.context } module "default_label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0" - namespace = var.namespace - stage = var.stage - name = var.name - delimiter = var.delimiter - attributes = compact(concat(var.attributes, ["origin"])) - tags = var.tags + source = "cloudposse/label/null" + version = "0.24.1" + attributes = ["origin"] + context = module.this.context } resource "aws_s3_bucket" "default" { - bucket = var.hostname + #bridgecrew:skip=BC_AWS_S3_1:The bucket used for a public static website. (https://docs.bridgecrew.io/docs/s3_1-acl-read-permissions-everyone) + #bridgecrew:skip=BC_AWS_S3_14:Skipping `Ensure all data stored in the S3 bucket is securely encrypted at rest` check until bridgecrew will support dynamic blocks (https://github.com/bridgecrewio/checkov/issues/776). + #bridgecrew:skip=CKV_AWS_52:Skipping `Ensure S3 bucket has MFA delete enabled` due to issue using `mfa_delete` by terraform (https://github.com/hashicorp/terraform-provider-aws/issues/629). acl = "public-read" + bucket = var.hostname tags = module.default_label.tags - region = var.region force_destroy = var.force_destroy - logging { - target_bucket = module.logs.bucket_id - target_prefix = module.logs.prefix + dynamic "logging" { + for_each = var.logs_enabled ? ["true"] : [] + content { + target_bucket = module.logs.bucket_id + target_prefix = module.logs.prefix + } } dynamic "website" { @@ -90,6 +94,18 @@ resource "aws_s3_bucket" "default" { days = var.noncurrent_version_expiration_days } } + + dynamic "server_side_encryption_configuration" { + for_each = var.encryption_enabled ? ["true"] : [] + + content { + rule { + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" + } + } + } + } } # AWS only supports a single bucket policy on a bucket. You can combine multiple Statements into a single policy, but not attach multiple policies. @@ -236,10 +252,13 @@ data "aws_iam_policy_document" "deployment" { } module "dns" { - source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.8.0" + source = "cloudposse/route53-alias/aws" + version = "0.12.0" aliases = compact([signum(length(var.parent_zone_id)) == 1 || signum(length(var.parent_zone_name)) == 1 ? var.hostname : ""]) parent_zone_id = var.parent_zone_id parent_zone_name = var.parent_zone_name target_dns_name = aws_s3_bucket.default.website_domain target_zone_id = aws_s3_bucket.default.hosted_zone_id + + context = module.this.context } diff --git a/outputs.tf b/outputs.tf index 77f89a1..1fe845a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -5,17 +5,17 @@ output "hostname" { output "s3_bucket_name" { value = aws_s3_bucket.default.id - description = "DNS record of website bucket" + description = "DNS record of the website bucket" } output "s3_bucket_domain_name" { value = aws_s3_bucket.default.bucket_domain_name - description = "Name of website bucket" + description = "Name of the website bucket" } output "s3_bucket_arn" { value = aws_s3_bucket.default.arn - description = "ARN identifier of website bucket" + description = "ARN identifier of the website bucket" } output "s3_bucket_website_endpoint" { diff --git a/variables.tf b/variables.tf index ffd2604..e5c4777 100644 --- a/variables.tf +++ b/variables.tf @@ -1,38 +1,3 @@ -variable "name" { - type = string - description = "The Name of the application or solution (e.g. `bastion` or `portal`)" -} - -variable "namespace" { - type = string - description = "Namespace (e.g. `eg` or `cp`)" - default = "" -} - -variable "stage" { - type = string - description = "Stage (e.g. `prod`, `dev`, `staging`)" - default = "" -} - -variable "attributes" { - type = list(string) - default = [] - description = "Additional attributes (e.g. `policy` or `role`)" -} - -variable "tags" { - type = map(string) - default = {} - description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`)" -} - -variable "delimiter" { - type = string - default = "-" - description = "Delimiter to be used between `name`, `namespace`, `stage`, etc." -} - variable "hostname" { type = string description = "Name of website bucket in `fqdn` format (e.g. `test.example.com`). IMPORTANT! Do not add trailing dot (`.`)" @@ -93,6 +58,12 @@ variable "cors_rules" { ] } +variable "logs_enabled" { + type = bool + description = "Enable logs for s3 bucket" + default = true +} + variable "logs_standard_transition_days" { type = number description = "Number of days to persist in the standard storage tier before moving to the glacier tier" @@ -111,6 +82,12 @@ variable "logs_expiration_days" { default = 90 } +variable "logs_object_versioning_enabled" { + description = "Enable object versioning on the logs bucket" + type = bool + default = false +} + variable "lifecycle_rule_enabled" { type = bool default = false @@ -135,15 +112,9 @@ variable "noncurrent_version_expiration_days" { description = "Specifies when noncurrent object versions expire" } -variable "region" { - type = string - default = "" - description = "AWS region this bucket should reside in" -} - variable "versioning_enabled" { type = bool - default = false + default = true description = "Enable or disable versioning" } @@ -170,3 +141,9 @@ variable "deployment_actions" { default = ["s3:PutObject", "s3:PutObjectAcl", "s3:GetObject", "s3:DeleteObject", "s3:ListBucket", "s3:ListBucketMultipartUploads", "s3:GetBucketLocation", "s3:AbortMultipartUpload"] description = "List of actions to permit deployment ARNs to perform" } + +variable "encryption_enabled" { + type = bool + default = false + description = "When set to 'true' the resource will have AES256 encryption enabled by default" +} diff --git a/versions.tf b/versions.tf index 4f0c9ac..2300bcd 100644 --- a/versions.tf +++ b/versions.tf @@ -1,9 +1,14 @@ terraform { - required_version = ">= 0.12.0" + required_version = ">= 0.13.0" required_providers { - aws = "~> 2.0" - local = "~> 1.2" - null = "~> 2.0" + aws = { + source = "hashicorp/aws" + version = ">= 2.0" + } + local = { + source = "hashicorp/local" + version = ">= 1.2" + } } }