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

feat: Added outputs for s3 bucket lifecycle rules and policy #234

Merged
merged 2 commits into from
May 25, 2023

Conversation

dhollerbach
Copy link
Contributor

Description

This PR creates two new outputs: 1) a list of lifecycle rules applied to the s3 bucket and, 2) the policy applied to the s3 bucket. Each output is set to an empty string if its respective value is not provided.

Additionally, this PR removes the deprecated skip_get_ec2_platforms argument from the aws providers in all examples directories.

Motivation and Context

While creating tests for my own S3 modules, I ran into a trouble when trying to validate lifecycle rules and policies applied to my S3 bucket. I was able to output the data_iam_policy_document easily enough but lifecycle rules are not available as a data source. My workaround was configuring the proper result in Go itself but it would be much better to output these values in case anyone wants to use them; for tests in my case.

Additionally, while running the pre-commit for these outputs, the validations were failing because the skip_get_ec2_platforms argument is not longer supported using Terraform version 1.4.5, the version used to perform all tests. To pass all validation checks, the skip_get_ec2_platforms argument was removed from the following examples directories:

Breaking Changes

No.

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

outputs.tf Outdated

output "s3_bucket_policy" {
description = "The policy of the bucket, if the bucket is configured with a policy. If not, this will be an empty string."
value = try(jsondecode(aws_s3_bucket_policy.this[0].policy), "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = try(jsondecode(aws_s3_bucket_policy.this[0].policy), "")
value = try(aws_s3_bucket_policy.this[0].policy, "")

outputs.tf Outdated
@@ -23,6 +23,16 @@ output "s3_bucket_hosted_zone_id" {
value = try(aws_s3_bucket.this[0].hosted_zone_id, "")
}

output "s3_bucket_lifecycle_configuration_rules" {
description = "The lifecycle rules of the bucket, if the bucket is configured with lifecycle rules. If not, this will be an empty string."
value = try(jsondecode(jsonencode(aws_s3_bucket_lifecycle_configuration.this[0].rule)), "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = try(jsondecode(jsonencode(aws_s3_bucket_lifecycle_configuration.this[0].rule)), "")
value = try(aws_s3_bucket_lifecycle_configuration.this[0].rule, "")

@antonbabenko antonbabenko changed the title chore: Added outputs for s3 bucket lifecycle rules and policy feat: Added outputs for s3 bucket lifecycle rules and policy May 25, 2023
Copy link

@dhollerbach-nelnet dhollerbach-nelnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I did the jsonencode / jsondecode for my own personal needs but your changes are more appropriate for a broader audience.

@dhollerbach dhollerbach requested a review from antonbabenko May 25, 2023 19:34
@antonbabenko antonbabenko merged commit 24b88e8 into terraform-aws-modules:master May 25, 2023
antonbabenko pushed a commit that referenced this pull request May 25, 2023
## [3.11.0](v3.10.1...v3.11.0) (2023-05-25)

### Features

* Added outputs for s3 bucket lifecycle rules and policy ([#234](#234)) ([24b88e8](24b88e8))
@antonbabenko
Copy link
Member

This PR is included in version 3.11.0 🎉

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants