Skip to content

Conversation

@olivierkessler
Copy link

@olivierkessler olivierkessler commented Nov 23, 2025

Description

Allows using conditionals when extending this module to enable/disable features (replication, logging, inventory)

Motivation and Context

Basically we've been experiencing the same issue as the person in the aforementioned issue. We extend this module and need to enable/disable replication, logging and inventory using feature flags/variables.

This cannot be done in a single central child module (the one linked to this PR would be the parent), given that'd require a conditional with one side being a properly structured map and the other side being an empty map, which terraform doesn't seem to allow.

Impact : One option today for users is to deploy infrastructure for replication, logging and inventory, even if they don't need it. The other option is having N child modules on user side, for all combinations of (replication, logging, inventory).

Solution : Allowing those configurations to be nullable, does not break backward compatibility but enable users to have a single extended/child module that can be controlled via feature flags.

What does not work today :

module "child_module" {
  source  = "terraform-aws-modules/s3-bucket/aws"

   ...
  logging = var.enable_logging ? {
    target_bucket = var.logging_bucket_id
    target_prefix = "logs/${var.bucket_name}"
    target_object_key_format = {
      partitioned_prefix = {
        partition_date_source = "DeliveryTime"
      }
    }
  } : {}

What works thanks to this PR:

module "child_module" {
  source  = "terraform-aws-modules/s3-bucket/aws"

   ...
  logging = var.enable_logging ? {
    target_bucket = var.logging_bucket_id
    target_prefix = "logs/${var.bucket_name}"
    target_object_key_format = {
      partitioned_prefix = {
        partition_date_source = "DeliveryTime"
      }
    }
  } : null 

Breaking Changes

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

* Allow using conditionals when extending the module to pass configuration
* Applies to the inventory, the logging and the replication
* Solves issue 297
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