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

Support AWS v4 provider #71

Merged
merged 2 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions .github/.github-update-disabled

This file was deleted.

11 changes: 10 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"enabled": false
"extends": [
"config:base",
":preserveSemverRanges"
],
"labels": ["auto-update"],
"enabledManagers": ["terraform"],
"terraform": {
"ignorePaths": ["**/context.tf", "examples/**"]
}
}

2 changes: 1 addition & 1 deletion .github/workflows/auto-context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Create Pull Request
if: steps.update.outputs.create_pull_request == 'true'
uses: cloudposse/actions/github/create-pull-request@0.22.0
uses: cloudposse/actions/github/create-pull-request@0.30.0
with:
token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
committer: 'cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/auto-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
fi

- name: Auto Test
uses: cloudposse/actions/github/repository-dispatch@0.22.0
uses: cloudposse/actions/github/repository-dispatch@0.30.0
# match users by ID because logins (user names) are inconsistent,
# for example in the REST API Renovate Bot is `renovate[bot]` but
# in GraphQL it is just `renovate`, plus there is a non-bot
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/chatops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: "Handle common commands"
uses: cloudposse/actions/github/slash-command-dispatch@0.22.0
uses: cloudposse/actions/github/slash-command-dispatch@0.30.0
with:
token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -24,7 +24,7 @@ jobs:
- name: "Checkout commit"
uses: actions/checkout@v2
- name: "Run tests"
uses: cloudposse/actions/github/slash-command-dispatch@0.22.0
uses: cloudposse/actions/github/slash-command-dispatch@0.30.0
with:
token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compiled files
*.tfstate
*.tfstate.backup
*.tfstate.backup*
*.lock.info
**/.terraform.lock.hcl

Expand Down
89 changes: 71 additions & 18 deletions README.md

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,54 @@ usage: |-
expiration_days = 90
}
```

This module supports full S3 [storage lifecycle](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html) configuration:

```hcl
locals {
lifecycle_configuration_rule = {
enabled = true # bool
id = "v2rule"

abort_incomplete_multipart_upload_days = 1 # number

filter_and = null
expiration = {
days = 120 # integer > 0
}
noncurrent_version_expiration = {
newer_noncurrent_versions = 3 # integer > 0
noncurrent_days = 60 # integer >= 0
}
transition = [{
days = 30 # integer >= 0
storage_class = "STANDARD_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
},
{
days = 60 # integer >= 0
storage_class = "ONEZONE_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
}]
noncurrent_version_transition = [{
newer_noncurrent_versions = 3 # integer >= 0
noncurrent_days = 30 # integer >= 0
storage_class = "ONEZONE_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
}]
}
}

module "log_storage" {
source = "cloudposse/s3-log-storage/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
name = "logs"
stage = "test"
namespace = "eg"

lifecycle_configuration_rules = [var.lifecycle_configuration_rule]
}

```

include:
- docs/targets.md
- docs/terraform.md
Expand Down
42 changes: 24 additions & 18 deletions docs/terraform.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,25 @@ stage = "test"
name = "s3-log-storage"

allow_ssl_requests_only = true

lifecycle_configuration_rules = [
{
enabled = true # bool
id = "v2rule"

abort_incomplete_multipart_upload_days = 1 # number

filter_and = null
expiration = null
transition = null
noncurrent_version_expiration = {
newer_noncurrent_versions = 3 # integer > 0
noncurrent_days = 90 # integer >= 0
}
noncurrent_version_transition = [{
newer_noncurrent_versions = 3 # integer >= 0
noncurrent_days = 30 # integer >= 0
storage_class = "ONEZONE_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
}]
}
]
7 changes: 5 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ provider "aws" {
}

module "s3_log_storage" {
source = "../../"
force_destroy = false
source = "../../"
force_destroy = true
force_destroy_enabled = true

lifecycle_configuration_rules = var.lifecycle_configuration_rules

context = module.this.context
}
26 changes: 25 additions & 1 deletion examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,28 @@ variable "allow_ssl_requests_only" {
type = bool
default = true
description = "Set to `true` to require requests to use Secure Socket Layer (HTTPS/SSL). This will explicitly deny access to HTTP requests"
}
}

variable "lifecycle_configuration_rules" {
type = list(object({
enabled = bool
id = string

abort_incomplete_multipart_upload_days = number

# `filter_and` is the `and` configuration block inside the `filter` configuration.
# This is the only place you should specify a prefix.
filter_and = any
expiration = any
transition = list(any)

noncurrent_version_expiration = any
noncurrent_version_transition = list(any)
}))
default = []
description = <<-EOT
A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"
These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.
**NOTE:** Unless you also set `lifecycle_rule_enabled = false` you will also get the default deprecated rules set on your bucket.
EOT
}
4 changes: 2 additions & 2 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.15"
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0, < 4.0"
version = ">= 4.0"
}
local = {
source = "hashicorp/local"
Expand Down
76 changes: 43 additions & 33 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
locals {
lifecycle_rule = {
enabled = var.lifecycle_rule_enabled
prefix = var.lifecycle_prefix
tags = var.lifecycle_tags

abort_incomplete_multipart_upload_days = var.abort_incomplete_multipart_upload_days

enable_glacier_transition = var.enable_glacier_transition
enable_deeparchive_transition = false
enable_standard_ia_transition = true
enable_current_object_expiration = true
enable_noncurrent_version_expiration = var.enable_noncurrent_version_expiration

noncurrent_version_glacier_transition_days = var.noncurrent_version_transition_days
noncurrent_version_deeparchive_transition_days = null
noncurrent_version_expiration_days = var.noncurrent_version_expiration_days

standard_transition_days = var.standard_transition_days
glacier_transition_days = var.glacier_transition_days
deeparchive_transition_days = null
expiration_days = var.expiration_days
}
}

# Terraform prior to 1.1 does not support a `moved` block.
# Terraform 1.1 does not a support move to an object declared in external module package.
# Terraform 1.1 supports `moved` blocks in general, but does not a support
# a move to an object declared in external module package.
# Leaving this here for documentation and in case Terraform later supports it.
/*
moved {
Expand All @@ -45,26 +22,59 @@ moved {
}
*/

locals {
# This is a big hack to enable us to generate something close to a custom error message
force_destroy_error_message = <<-EOT

** ERROR: You must set `force_destroy_enabled = true` to enable `force_destroy`. **n/
** WARNING: Upgrading this module from a version prior to 0.27.0 to this version **n/
** will cause Terraform to delete your existing S3 bucket CAUSING COMPLETE DATA LOSS **n/
** unless you follow the upgrade instructions on the Wiki [here](https://github.com/cloudposse/terraform-aws-s3-log-storage/wiki/Upgrading-to-v0.27.0-(POTENTIAL-DATA-LOSS)). **n/
** See additional instructions for upgrading from v0.27.0 to v0.28.0 [here](https://github.com/cloudposse/terraform-aws-s3-log-storage/wiki/Upgrading-to-v0.28.0-and-AWS-provider-v4-(POTENTIAL-DATA-LOSS)). **n/

EOT
force_destroy_safety = {
true = {
true = "true"
false = "false"
},
false = {
true = local.force_destroy_error_message
false = "false"
}
}
# Generate an error message when `force_destroy == true && force_destroy_enabled == false`
force_destroy = tobool(local.force_destroy_safety[var.force_destroy_enabled][var.force_destroy])

bucket_name = var.bucket_name == null || var.bucket_name == "" ? module.this.id : var.bucket_name
}

module "aws_s3_bucket" {
source = "cloudposse/s3-bucket/aws"
version = "0.47.1"
version = "0.49.0"

bucket_name = module.this.id
bucket_name = local.bucket_name
acl = var.acl
force_destroy = var.force_destroy
policy = var.policy
force_destroy = local.force_destroy
versioning_enabled = var.versioning_enabled

lifecycle_rule_ids = [module.this.id]
lifecycle_rules = [local.lifecycle_rule]
source_policy_documents = var.source_policy_documents
# Support deprecated `policy` input
aknysh marked this conversation as resolved.
Show resolved Hide resolved
policy = var.policy

lifecycle_configuration_rules = var.lifecycle_configuration_rules
# Support deprecated lifecycle inputs
lifecycle_rule_ids = local.deprecated_lifecycle_rule.enabled ? [module.this.id] : null
lifecycle_rules = local.deprecated_lifecycle_rule.enabled ? [local.deprecated_lifecycle_rule] : null

logging = var.access_log_bucket_name == "" ? null : {
bucket_name = var.access_log_bucket_name
prefix = "${var.access_log_bucket_prefix}${module.this.id}/"
prefix = "${var.access_log_bucket_prefix}${local.bucket_name}/"
}

sse_algorithm = var.sse_algorithm
kms_master_key_arn = var.kms_master_key_arn
bucket_key_enabled = var.bucket_key_enabled

allow_encrypted_uploads_only = var.allow_encrypted_uploads_only
allow_ssl_requests_only = var.allow_ssl_requests_only
Expand All @@ -74,7 +84,7 @@ module "aws_s3_bucket" {
ignore_public_acls = var.ignore_public_acls
restrict_public_buckets = var.restrict_public_buckets

s3_object_ownership = "BucketOwnerPreferred"
s3_object_ownership = var.s3_object_ownership

context = module.this.context
}
4 changes: 1 addition & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ clean:
all: module examples/complete

## Run basic sanity checks against the module itself
# Temporarily remove provider pinning test while working on AWS provider v4.0 support
#module: export TESTS ?= installed lint module-pinning provider-pinning validate terraform-docs input-descriptions output-descriptions
module: export TESTS ?= installed lint module-pinning validate terraform-docs input-descriptions output-descriptions
module: export TESTS ?= installed lint module-pinning provider-pinning validate terraform-docs input-descriptions output-descriptions
module: deps
$(call RUN_TESTS, ../)

Expand Down
Loading