Commit 70d08fd4 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

feat: Upgraded AWS provider to 4.5, fixed object_lock_enabled (#149)

parent 20c898d7
repos: repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform - repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.64.0 rev: v1.66.0
hooks: hooks:
- id: terraform_fmt - id: terraform_fmt
- id: terraform_validate - id: terraform_validate
...@@ -23,7 +23,7 @@ repos: ...@@ -23,7 +23,7 @@ repos:
- '--args=--only=terraform_standard_module_structure' - '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote' - '--args=--only=terraform_workspace_remote'
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 rev: v4.2.0
hooks: hooks:
- id: check-merge-conflict - id: check-merge-conflict
- id: end-of-file-fixer - id: end-of-file-fixer
...@@ -110,13 +110,13 @@ inputs = { ...@@ -110,13 +110,13 @@ inputs = {
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 | | <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5 |
## Providers ## Providers
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.75 | | <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.5 |
## Modules ## Modules
...@@ -175,6 +175,7 @@ No modules. ...@@ -175,6 +175,7 @@ No modules.
| <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no | | <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no |
| <a name="input_logging"></a> [logging](#input\_logging) | Map containing access bucket logging configuration. | `map(string)` | `{}` | no | | <a name="input_logging"></a> [logging](#input\_logging) | Map containing access bucket logging configuration. | `map(string)` | `{}` | no |
| <a name="input_object_lock_configuration"></a> [object\_lock\_configuration](#input\_object\_lock\_configuration) | Map containing S3 object locking configuration. | `any` | `{}` | no | | <a name="input_object_lock_configuration"></a> [object\_lock\_configuration](#input\_object\_lock\_configuration) | Map containing S3 object locking configuration. | `any` | `{}` | no |
| <a name="input_object_lock_enabled"></a> [object\_lock\_enabled](#input\_object\_lock\_enabled) | Whether S3 bucket should have an Object Lock configuration enabled. | `bool` | `false` | no |
| <a name="input_object_ownership"></a> [object\_ownership](#input\_object\_ownership) | Object ownership. Valid values: BucketOwnerEnforced, BucketOwnerPreferred or ObjectWriter. 'BucketOwnerEnforced': ACLs are disabled, and the bucket owner automatically owns and has full control over every object in the bucket. 'BucketOwnerPreferred': Objects uploaded to the bucket change ownership to the bucket owner if the objects are uploaded with the bucket-owner-full-control canned ACL. 'ObjectWriter': The uploading account will own the object if the object is uploaded with the bucket-owner-full-control canned ACL. | `string` | `"ObjectWriter"` | no | | <a name="input_object_ownership"></a> [object\_ownership](#input\_object\_ownership) | Object ownership. Valid values: BucketOwnerEnforced, BucketOwnerPreferred or ObjectWriter. 'BucketOwnerEnforced': ACLs are disabled, and the bucket owner automatically owns and has full control over every object in the bucket. 'BucketOwnerPreferred': Objects uploaded to the bucket change ownership to the bucket owner if the objects are uploaded with the bucket-owner-full-control canned ACL. 'ObjectWriter': The uploading account will own the object if the object is uploaded with the bucket-owner-full-control canned ACL. | `string` | `"ObjectWriter"` | no |
| <a name="input_owner"></a> [owner](#input\_owner) | Bucket owner's display name and ID. Conflicts with `acl` | `map(string)` | `{}` | no | | <a name="input_owner"></a> [owner](#input\_owner) | Bucket owner's display name and ID. Conflicts with `acl` | `map(string)` | `{}` | no |
| <a name="input_policy"></a> [policy](#input\_policy) | (Optional) A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. | `string` | `null` | no | | <a name="input_policy"></a> [policy](#input\_policy) | (Optional) A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. | `string` | `null` | no |
......
...@@ -6,8 +6,9 @@ If you find a bug, please open an issue with supporting configuration to reprodu ...@@ -6,8 +6,9 @@ If you find a bug, please open an issue with supporting configuration to reprodu
## List of backwards incompatible changes ## List of backwards incompatible changes
- Terraform AWS provider minimum version is now `v3.75.0` in order to have forward compatibility with Terraform AWS provider `v4.x`. Using the latest version of `v4` is highly recommended, if possible. - Terraform AWS provider minimum version is now `v4.5.0` in order to have forward compatibility with Terraform AWS provider `v4.x`. Using the latest version of `v4` is highly recommended, if possible.
- Main group of changes is related to refactoring of `aws_s3_bucket` resource into several smaller resources. Read [`S3 bucket refactor` section in the official Terraform AWS Provider Version 4 Upgrade Guide](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#s3-bucket-refactor) and [discussion around these changes](https://github.com/hashicorp/terraform-provider-aws/issues/23106) can help even when using AWS provider version 3.75 or newer. - If you are using AWS provider `v3.75` the latest supported version of this module is `v3.0.1`
- Main group of changes is related to refactoring of `aws_s3_bucket` resource into several smaller resources. Read [`S3 bucket refactor` section in the official Terraform AWS Provider Version 4 Upgrade Guide](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#s3-bucket-refactor) and [discussion around these changes](https://github.com/hashicorp/terraform-provider-aws/issues/23106).
- `modules/object`: Changed resource type from `aws_bucket_s3_object` to `aws_s3_object`. After upgrade, on the next apply, Terraform will recreate the object. If you prefer to not have Terraform recreate the object, import the object using `aws_s3_object`. [Read more](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object#import). - `modules/object`: Changed resource type from `aws_bucket_s3_object` to `aws_s3_object`. After upgrade, on the next apply, Terraform will recreate the object. If you prefer to not have Terraform recreate the object, import the object using `aws_s3_object`. [Read more](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object#import).
## Additional changes ## Additional changes
...@@ -91,7 +92,7 @@ module "s3_bucket" { ...@@ -91,7 +92,7 @@ module "s3_bucket" {
terraform { terraform {
required_providers { required_providers {
aws = ">= 3.75" # or anything higher than 3.75.0 aws = ">= 4.5" # or anything higher than 4.5.0
} }
} }
``` ```
......
...@@ -30,14 +30,14 @@ Note that this example may create resources which cost money. Run `terraform des ...@@ -30,14 +30,14 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 | | <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
## Providers ## Providers
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.75 | | <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.5 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
## Modules ## Modules
......
...@@ -116,8 +116,8 @@ module "s3_bucket" { ...@@ -116,8 +116,8 @@ module "s3_bucket" {
# Note: Object Lock configuration can be enabled only on new buckets # Note: Object Lock configuration can be enabled only on new buckets
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object_lock_configuration # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object_lock_configuration
object_lock_enabled = true
object_lock_configuration = { object_lock_configuration = {
object_lock_enabled = false
rule = { rule = {
default_retention = { default_retention = {
mode = "GOVERNANCE" mode = "GOVERNANCE"
......
...@@ -4,7 +4,7 @@ terraform { ...@@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
version = ">= 3.75" version = ">= 4.5"
} }
random = { random = {
source = "hashicorp/random" source = "hashicorp/random"
......
...@@ -20,7 +20,7 @@ Note that this example may create resources which cost money. Run `terraform des ...@@ -20,7 +20,7 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 | | <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 | | <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
...@@ -28,7 +28,7 @@ Note that this example may create resources which cost money. Run `terraform des ...@@ -28,7 +28,7 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.75 | | <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.5 |
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 | | <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
......
...@@ -4,7 +4,7 @@ terraform { ...@@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
version = ">= 3.75" version = ">= 4.5"
} }
random = { random = {
source = "hashicorp/random" source = "hashicorp/random"
......
...@@ -20,14 +20,14 @@ Note that this example may create resources which cost money. Run `terraform des ...@@ -20,14 +20,14 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 | | <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
## Providers ## Providers
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.75 | | <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.5 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
## Modules ## Modules
......
...@@ -4,7 +4,7 @@ terraform { ...@@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
version = ">= 3.75" version = ">= 4.5"
} }
random = { random = {
source = "hashicorp/random" source = "hashicorp/random"
......
...@@ -22,15 +22,15 @@ Note that this example may create resources which cost money. Run `terraform des ...@@ -22,15 +22,15 @@ Note that this example may create resources which cost money. Run `terraform des
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.75 | | <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
## Providers ## Providers
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.75 | | <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.5 |
| <a name="provider_aws.replica"></a> [aws.replica](#provider\_aws.replica) | >= 3.75 | | <a name="provider_aws.replica"></a> [aws.replica](#provider\_aws.replica) | >= 4.5 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
## Modules ## Modules
......
...@@ -4,7 +4,7 @@ terraform { ...@@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
version = ">= 3.75" version = ">= 4.5"
} }
random = { random = {
source = "hashicorp/random" source = "hashicorp/random"
......
...@@ -17,17 +17,9 @@ resource "aws_s3_bucket" "this" { ...@@ -17,17 +17,9 @@ resource "aws_s3_bucket" "this" {
bucket = var.bucket bucket = var.bucket
bucket_prefix = var.bucket_prefix bucket_prefix = var.bucket_prefix
tags = var.tags
force_destroy = var.force_destroy force_destroy = var.force_destroy
object_lock_enabled = var.object_lock_enabled
# Max 1 block - object_lock_configuration tags = var.tags
dynamic "object_lock_configuration" {
for_each = compact([try(var.object_lock_configuration["object_lock_enabled"] ? "Enabled" : null, tobool(var.object_lock_configuration["object_lock_enabled"]) ? "Enabled" : null, title(lower(var.object_lock_configuration["object_lock_enabled"])), null)])
content {
object_lock_enabled = "Enabled"
}
}
lifecycle { lifecycle {
ignore_changes = [ ignore_changes = [
...@@ -37,7 +29,7 @@ resource "aws_s3_bucket" "this" { ...@@ -37,7 +29,7 @@ resource "aws_s3_bucket" "this" {
cors_rule, cors_rule,
lifecycle_rule, lifecycle_rule,
logging, logging,
object_lock_configuration[0].rule, object_lock_configuration,
replication_configuration, replication_configuration,
request_payer, request_payer,
server_side_encryption_configuration, server_side_encryption_configuration,
...@@ -343,7 +335,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" { ...@@ -343,7 +335,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
} }
resource "aws_s3_bucket_object_lock_configuration" "this" { resource "aws_s3_bucket_object_lock_configuration" "this" {
count = local.create_bucket && try(var.object_lock_configuration.rule.default_retention, null) != null ? 1 : 0 count = local.create_bucket && var.object_lock_enabled && try(var.object_lock_configuration.rule.default_retention, null) != null ? 1 : 0
bucket = aws_s3_bucket.this[0].id bucket = aws_s3_bucket.this[0].id
expected_bucket_owner = var.expected_bucket_owner expected_bucket_owner = var.expected_bucket_owner
......
...@@ -154,6 +154,12 @@ variable "object_lock_configuration" { ...@@ -154,6 +154,12 @@ variable "object_lock_configuration" {
default = {} default = {}
} }
variable "object_lock_enabled" {
description = "Whether S3 bucket should have an Object Lock configuration enabled."
type = bool
default = false
}
variable "block_public_acls" { variable "block_public_acls" {
description = "Whether Amazon S3 should block public ACLs for this bucket." description = "Whether Amazon S3 should block public ACLs for this bucket."
type = bool type = bool
......
...@@ -4,7 +4,7 @@ terraform { ...@@ -4,7 +4,7 @@ terraform {
required_providers { required_providers {
aws = { aws = {
source = "hashicorp/aws" source = "hashicorp/aws"
version = ">= 3.75" version = ">= 4.5"
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment