-
-
Couldn't load subscription status.
- Fork 3.8k
fix: Adds replication config dependency to lifecycle config #361
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
Merged
antonbabenko
merged 6 commits into
terraform-aws-modules:master
from
nvnivs:fix-MissingRequestBodyError
Oct 15, 2025
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba905cd
chore: creates example to replicate issue
nvnivs c255cb1
fix: lifecycle config depends on replication
nvnivs 6ac1b06
chore: formatting fixes
9debc42
chore: fix linting deffects
898c9f5
chore: simplifies example
d09c21c
chore: removes lifecycle-n-replication example
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| resource "aws_iam_role" "replication" { | ||
| name = "s3-bucket-replication-${random_pet.this.id}" | ||
|
|
||
| assume_role_policy = <<POLICY | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Action": "sts:AssumeRole", | ||
| "Principal": { | ||
| "Service": "s3.amazonaws.com" | ||
| }, | ||
| "Effect": "Allow", | ||
| "Sid": "" | ||
| } | ||
| ] | ||
| } | ||
| POLICY | ||
| } | ||
|
|
||
| resource "aws_iam_policy" "replication" { | ||
| name = "s3-bucket-replication-${random_pet.this.id}" | ||
|
|
||
| policy = <<POLICY | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Action": [ | ||
| "s3:GetReplicationConfiguration", | ||
| "s3:ListBucket" | ||
| ], | ||
| "Effect": "Allow", | ||
| "Resource": [ | ||
| "arn:aws:s3:::${local.bucket_name}" | ||
| ] | ||
| }, | ||
| { | ||
| "Action": [ | ||
| "s3:GetObjectVersion", | ||
| "s3:GetObjectVersionAcl" | ||
| ], | ||
| "Effect": "Allow", | ||
| "Resource": [ | ||
| "arn:aws:s3:::${local.bucket_name}/*" | ||
| ] | ||
| }, | ||
| { | ||
| "Action": [ | ||
| "s3:ReplicateObject", | ||
| "s3:ReplicateDelete" | ||
| ], | ||
| "Effect": "Allow", | ||
| "Resource": "arn:aws:s3:::${local.replica_bucket_name}/*" | ||
| } | ||
| ] | ||
| } | ||
| POLICY | ||
| } | ||
|
|
||
| resource "aws_iam_policy_attachment" "replication" { | ||
| name = "s3-bucket-replication-${random_pet.this.id}" | ||
| roles = [aws_iam_role.replication.name] | ||
| policy_arn = aws_iam_policy.replication.arn | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| locals { | ||
| bucket_name = "origin-s3-bucket-${random_pet.this.id}" | ||
| replica_bucket_name = "replica-s3-bucket-${random_pet.this.id}" | ||
|
|
||
| origin_region = "eu-west-1" | ||
| replica_region = "eu-central-1" | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = local.origin_region | ||
| alias = "source" | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = local.replica_region | ||
| alias = "replica" | ||
| } | ||
|
|
||
| resource "random_pet" "this" { | ||
| length = 2 | ||
| } | ||
|
|
||
| module "s3_bucket" { | ||
| source = "../../" | ||
|
|
||
| providers = { | ||
| aws = aws.source | ||
| } | ||
|
|
||
| bucket = local.bucket_name | ||
|
|
||
| force_destroy = true | ||
|
|
||
| # Versioning | ||
| versioning = { | ||
| enabled = true | ||
| } | ||
|
|
||
| # Replication | ||
| replication_configuration = { | ||
| role = aws_iam_role.replication.arn | ||
|
|
||
| rules = [ | ||
| { | ||
| id = "custom-additional-rule", | ||
| priority = 15, | ||
| delete_marker_replication = true | ||
|
|
||
| destination = { | ||
| bucket = "arn:aws:s3:::${local.replica_bucket_name}" | ||
| replica_kms_key_id = aws_kms_key.replica.arn | ||
| storage_class = "STANDARD_IA" | ||
| } | ||
|
|
||
| filter = { | ||
| prefix = "" | ||
| } | ||
|
|
||
| source_selection_criteria = { | ||
| sse_kms_encrypted_objects = { | ||
| enabled = true | ||
| } | ||
| } | ||
|
|
||
| }, | ||
| ] | ||
| } | ||
|
|
||
| # Lifecycle | ||
| lifecycle_rule = [ | ||
| { | ||
| id = "abort-incomplete-multipart-upload" | ||
| status = "Enabled" | ||
|
|
||
| abort_incomplete_multipart_upload = { | ||
| days_after_initiation = 35 | ||
| } | ||
|
|
||
| filter = { | ||
| } | ||
|
|
||
| noncurrent_version_expiration = { | ||
| noncurrent_days = 35 | ||
| } | ||
| }, | ||
| ] | ||
|
|
||
| depends_on = [module.bucket_replica] | ||
| } | ||
|
|
||
| resource "aws_kms_key" "replica" { | ||
| provider = aws.replica | ||
|
|
||
| description = "S3 bucket replication KMS key" | ||
| deletion_window_in_days = 7 | ||
| } | ||
|
|
||
| module "bucket_replica" { | ||
| source = "../../" | ||
|
|
||
| providers = { | ||
| aws = aws.replica | ||
| } | ||
|
|
||
| versioning = { | ||
| enabled = true | ||
| } | ||
|
|
||
| bucket = local.replica_bucket_name | ||
|
|
||
| force_destroy = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| output "s3_bucket_id" { | ||
| description = "The name of the bucket." | ||
| value = module.s3_bucket.s3_bucket_id | ||
| } | ||
|
|
||
| output "s3_bucket_arn" { | ||
| description = "The ARN of the bucket. Will be of format arn:aws:s3:::bucketname." | ||
| value = module.s3_bucket.s3_bucket_arn | ||
| } | ||
|
|
||
| output "s3_bucket_bucket_domain_name" { | ||
| description = "The bucket domain name. Will be of format bucketname.s3.amazonaws.com." | ||
| value = module.s3_bucket.s3_bucket_bucket_domain_name | ||
| } | ||
|
|
||
| output "s3_bucket_bucket_regional_domain_name" { | ||
| description = "The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL." | ||
| value = module.s3_bucket.s3_bucket_bucket_regional_domain_name | ||
| } | ||
|
|
||
| output "s3_bucket_hosted_zone_id" { | ||
| description = "The Route 53 Hosted Zone ID for this bucket's region." | ||
| value = module.s3_bucket.s3_bucket_hosted_zone_id | ||
| } | ||
|
|
||
| output "s3_bucket_region" { | ||
| description = "The AWS region this bucket resides in." | ||
| value = module.s3_bucket.s3_bucket_region | ||
| } | ||
|
|
||
| output "s3_bucket_website_endpoint" { | ||
| description = "The website endpoint, if the bucket is configured with a website. If not, this will be an empty string." | ||
| value = module.s3_bucket.s3_bucket_website_endpoint | ||
| } | ||
|
|
||
| output "s3_bucket_website_domain" { | ||
| description = "The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records. " | ||
| value = module.s3_bucket.s3_bucket_website_domain | ||
| } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = ">= 5.70" | ||
| } | ||
| random = { | ||
| source = "hashicorp/random" | ||
| version = ">= 2.0" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.