Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform Provider v5 Support #93

Merged
merged 9 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"extends": [
"config:base",
":preserveSemverRanges"
":preserveSemverRanges",
":rebaseStalePrs"
],
"baseBranches": ["main", "master", "/^release\\/v\\d{1,2}$/"],
"baseBranches": ["main"],
"labels": ["auto-update"],
"dependencyDashboardAutoclose": true,
"enabledManagers": ["terraform"],
"terraform": {
"ignorePaths": ["**/context.tf", "examples/**"]
"ignorePaths": ["**/context.tf"]
}
}
1 change: 1 addition & 0 deletions .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'examples/**'
- 'test/**'
- 'README.*'

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ permissions:

jobs:
terraform-module:
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main
uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ We highly recommend that in your code you pin the version to the exact version y
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

Expand Down Expand Up @@ -153,31 +149,33 @@ Available targets:

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0, < 4.0.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.2 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0, < 4.0.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_default_label"></a> [default\_label](#module\_default\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_dns"></a> [dns](#module\_dns) | cloudposse/route53-alias/aws | 0.13.0 |
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 0.20.0 |
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 1.4.2 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources

| Name | Type |
|------|------|
| [aws_s3_bucket.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_ownership_controls.s3_bucket_ownership_controls](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_public_access_block.s3_allow_public_access](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | 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 |
Expand Down
10 changes: 6 additions & 4 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0, < 4.0.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 |
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.2 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0, < 4.0.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_default_label"></a> [default\_label](#module\_default\_label) | cloudposse/label/null | 0.25.0 |
| <a name="module_dns"></a> [dns](#module\_dns) | cloudposse/route53-alias/aws | 0.13.0 |
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 0.20.0 |
| <a name="module_logs"></a> [logs](#module\_logs) | cloudposse/s3-log-storage/aws | 1.4.2 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources

| Name | Type |
|------|------|
| [aws_s3_bucket.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [aws_s3_bucket_ownership_controls.s3_bucket_ownership_controls](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_public_access_block.s3_allow_public_access](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | 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 |
Expand Down
14 changes: 14 additions & 0 deletions examples/complete/versions.tf
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 = ">= 4.9"
milldr marked this conversation as resolved.
Show resolved Hide resolved
}
local = {
source = "hashicorp/local"
version = ">= 1.2"
}
}
}
47 changes: 37 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
enabled = module.this.enabled
bucket_arn = "arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}"
bucket_arn = "arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default[*].id)}"

website_config = {
redirect_all = [
Expand All @@ -19,10 +19,12 @@ locals {
}

module "logs" {
source = "cloudposse/s3-log-storage/aws"
version = "0.20.0"
source = "cloudposse/s3-log-storage/aws"
version = "1.4.2"

enabled = local.enabled && var.logs_enabled

attributes = ["logs"]
enabled = local.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
Expand All @@ -38,13 +40,36 @@ module "default_label" {
context = module.this.context
}

resource "aws_s3_bucket_public_access_block" "s3_allow_public_access" {
milldr marked this conversation as resolved.
Show resolved Hide resolved
milldr marked this conversation as resolved.
Show resolved Hide resolved
milldr marked this conversation as resolved.
Show resolved Hide resolved
milldr marked this conversation as resolved.
Show resolved Hide resolved
count = local.enabled ? 1 : 0

# The bucket used for a public static website.
#bridgecrew:skip=BC_AWS_S3_19:Skipping `Ensure S3 bucket has block public ACLS enabled`
#bridgecrew:skip=BC_AWS_S3_20:Skipping `Ensure S3 Bucket BlockPublicPolicy is set to True`
#bridgecrew:skip=BC_AWS_S3_21:Skipping `Ensure S3 bucket IgnorePublicAcls is set to True`
#bridgecrew:skip=BC_AWS_S3_22:Skipping `Ensure S3 bucket RestrictPublicBucket is set to True`
bucket = aws_s3_bucket.default[0].id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}

resource "aws_s3_bucket_ownership_controls" "s3_bucket_ownership_controls" {
count = local.enabled ? 1 : 0

bucket = aws_s3_bucket.default[0].id
rule {
object_ownership = "BucketOwnerEnforced"
}
}

resource "aws_s3_bucket" "default" {
count = local.enabled ? 1 : 0

#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
force_destroy = var.force_destroy
Expand Down Expand Up @@ -115,6 +140,8 @@ resource "aws_s3_bucket_policy" "default" {

bucket = aws_s3_bucket.default[0].id
policy = data.aws_iam_policy_document.default[0].json

depends_on = [aws_s3_bucket_public_access_block.s3_allow_public_access[0]]
}

data "aws_iam_policy_document" "default" {
Expand Down Expand Up @@ -155,7 +182,7 @@ data "aws_iam_policy_document" "default" {

# Support replication ARNs
dynamic "statement" {
for_each = flatten(data.aws_iam_policy_document.replication.*.statement)
for_each = flatten(data.aws_iam_policy_document.replication[*].statement)
content {
actions = lookup(statement.value, "actions", null)
effect = lookup(statement.value, "effect", null)
Expand Down Expand Up @@ -193,7 +220,7 @@ data "aws_iam_policy_document" "default" {

# Support deployment ARNs
dynamic "statement" {
for_each = flatten(data.aws_iam_policy_document.deployment.*.statement)
for_each = flatten(data.aws_iam_policy_document.deployment[*].statement)
content {
actions = lookup(statement.value, "actions", null)
effect = lookup(statement.value, "effect", null)
Expand Down Expand Up @@ -287,8 +314,8 @@ module "dns" {
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 = join("", aws_s3_bucket.default.*.website_domain)
target_zone_id = join("", aws_s3_bucket.default.*.hosted_zone_id)
target_dns_name = join("", aws_s3_bucket.default[*].website_domain)
target_zone_id = join("", aws_s3_bucket.default[*].hosted_zone_id)

context = module.this.context
}
12 changes: 6 additions & 6 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ output "hostname" {
}

output "s3_bucket_name" {
value = join("", aws_s3_bucket.default.*.id)
value = join("", aws_s3_bucket.default[*].id)
description = "DNS record of the website bucket"
}

output "s3_bucket_domain_name" {
value = join("", aws_s3_bucket.default.*.bucket_domain_name)
value = join("", aws_s3_bucket.default[*].bucket_domain_name)
description = "Name of the website bucket"
}

output "s3_bucket_arn" {
value = join("", aws_s3_bucket.default.*.arn)
value = join("", aws_s3_bucket.default[*].arn)
description = "ARN identifier of the website bucket"
}

output "s3_bucket_website_endpoint" {
value = join("", aws_s3_bucket.default.*.website_endpoint)
value = join("", aws_s3_bucket.default[*].website_endpoint)
description = "The website endpoint URL"
}

output "s3_bucket_website_domain" {
value = join("", aws_s3_bucket.default.*.website_domain)
value = join("", aws_s3_bucket.default[*].website_domain)
description = "The domain of the website endpoint"
}

output "s3_bucket_hosted_zone_id" {
value = join("", aws_s3_bucket.default.*.hosted_zone_id)
value = join("", aws_s3_bucket.default[*].hosted_zone_id)
description = "The Route 53 Hosted Zone ID for this bucket's region"
}
30 changes: 22 additions & 8 deletions test/src/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
module github.com/cloudposse/terraform-aws-s3-website

go 1.13
go 1.20

require (
github.com/aws/aws-sdk-go v1.34.6 // indirect
github.com/gruntwork-io/terratest v0.34.7
github.com/stretchr/testify v1.6.1
)

require (
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-textseg v1.0.0 // indirect
github.com/apparentlymart/go-textseg/v12 v12.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/gruntwork-io/terratest v0.16.0
github.com/pquerna/otp v1.2.0 // indirect
github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect
golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/hcl/v2 v2.8.2 // indirect
github.com/hashicorp/terraform-json v0.9.0 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/zclconf/go-cty v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
Loading