Skip to main content
In this example, we’ll create a wrapper module around the official Terraform S3 bucket community module. This lets you inherit all best practices while enforcing your own naming conventions and configuration rules.

Why Use a Wrapper Module?

A wrapper module allows you to:
  • Leverage community-tested code.
  • Enforce company-specific policies (e.g., naming standards).
  • Extend or override default settings without modifying upstream code.

1. Define the Wrapper Module

In your local modules/s3-bucket directory, replace the direct resource blocks with a call to the community module:

2. Add a Random Suffix

Generate a unique suffix automatically so that bucket names remain globally unique:
We set special = false and upper = false to keep the suffix alphanumeric and lowercase only.

3. Update Module Outputs

Since the wrapper no longer defines the bucket resource directly, forward the community module outputs:

4. Configure Terragrunt

In your Terragrunt live configuration, reference the local wrapper module. Notice we no longer supply a suffix manually:
The final bucket name is not known until apply time since it depends on the random suffix.

5. Deploy with Terragrunt

Run:
Terragrunt will:
  1. Download the S3 bucket community module.
  2. Generate a random suffix.
  3. Create the bucket with your base name plus suffix.
  4. Apply default public-access-block settings from the module.
Confirm the bucket exists:

Learn More

Watch Video