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.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
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.
| Module | Description | Key Inputs |
|---|---|---|
| terraform-aws-modules/s3-bucket/aws | Official S3 bucket module on the Terraform Registry | source, version, bucket |
| local wrapper module | Wraps the community module to append a random suffix to names | bucket_name, suffix_length |
1. Define the Wrapper Module
In your localmodules/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:- Download the S3 bucket community module.
- Generate a random suffix.
- Create the bucket with your base name plus suffix.
- Apply default public-access-block settings from the module.