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 1 commit
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: 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"
}
}
}
39 changes: 29 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,28 @@ 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
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" {
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 +132,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]
}

data "aws_iam_policy_document" "default" {
Expand Down Expand Up @@ -155,7 +174,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 +212,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 +306,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"
}
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.13.0"
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0, < 4.0.0"
version = ">= 4.9"
}
local = {
source = "hashicorp/local"
Expand Down