Skip to content

Conversation

paikend
Copy link
Contributor

@paikend paikend commented Aug 27, 2025

Description

Added s3_bucket_tags output to expose user-defined tags applied to S3 buckets. This output provides access to the tags that users explicitly set via the tags variable, enabling tag validation and testing in downstream configurations.

Motivation and Context

The module was missing an output for S3 bucket tags, which is commonly needed for:

  • Automated tag validation in Terraform tests
  • Tag consistency checks across infrastructure
  • Integration with other modules that need to reference bucket tags
  • Compliance and governance validation

This addresses the need for accessing user-defined bucket tags without exposing computed-only values like tags_all.

Breaking Changes

This is a non-breaking change. It only adds a new output without modifying any existing functionality or outputs.

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

Testing Details

  • Validated the output returns the expected tags in the complete example
  • Confirmed the output works correctly when no tags are provided (returns empty object)
  • Tested integration with conditional bucket creation scenarios using the try() function
  • Added test case to validate tag accessibility:
run "validate_tags_output" {
  command = plan
  
  variables {
    tags = {
      Environment = "test"
      Project     = "terraform-aws-s3-bucket"
    }
  }
  
  assert {
    condition = module.s3_bucket.s3_bucket_tags.Environment == "test"
    error_message = "S3 bucket tags output should include Environment tag"
  }
  
  assert {
    condition = length(keys(module.s3_bucket.s3_bucket_tags)) == 2
    error_message = "S3 bucket tags output should contain exactly 2 tags"
  }
}

The output safely handles edge cases using try(aws_s3_bucket.this[0].tags, {}) to return an empty object when the bucket resource doesn't exist.

@antonbabenko
Copy link
Member

Looks pretty good, please fix CI before the merge.

@paikend
Copy link
Contributor Author

paikend commented Aug 27, 2025

Sorry, I Fixed it

@antonbabenko antonbabenko merged commit 4586f12 into terraform-aws-modules:master Aug 27, 2025
18 checks passed
antonbabenko pushed a commit that referenced this pull request Aug 27, 2025
## [5.7.0](v5.6.0...v5.7.0) (2025-08-27)

### Features

* Add tags in output.tf [#355](#355) ([#357](#357)) ([4586f12](4586f12))
@antonbabenko
Copy link
Member

This PR is included in version 5.7.0 🎉

@paikend paikend deleted the patch-1 branch August 28, 2025 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants