Why Use Wrapper Modules?
- Consistency
Enforce company-wide naming conventions, tag policies, and resource configurations through standardized inputs. - Scoped Customization
Override only the settings you need, leaving the underlying community module intact for easier upstream upgrades. - Maintainability
Minimize drift from official releases by wrapping instead of forking—updating to new versions becomes straightforward.
Common Use Cases
| Use Case | Description |
|---|---|
| Standardizing Inputs | Enforce naming conventions, tagging policies, or sizing guidelines for all deployments. |
| Adding Defaults | Provide default values for certain inputs (e.g., instance types, region) while allowing overrides. |
| Injecting Organization Settings | Preconfigure logging levels, monitoring hooks, or security controls across all modules. |
Implementation Example
-
Create your wrapper module directory:
modules/my-wrapper/ -
In
modules/my-wrapper/main.tf, call the community module and map your inputs:
- Declare only the variables your team needs in
variables.tf:
By exposing only selected inputs, you maintain a clear contract for your internal teams while still benefitting from community-driven improvements.
- In your root Terraform or Terragrunt configuration, invoke
modules/my-wrapperinstead of the community module directly.
Choosing Between Community, Custom, and Wrapper Modules
| Criteria | Community Modules | Custom Modules | Wrapper Modules |
|---|---|---|---|
| Reusability | High | Low | Medium |
| Development Speed | Fast | Slow | Moderate |
| Maintenance Overhead | Low | High | Medium |
| Upstream Compatibility | Direct upgrades | N/A | Retained with mapping |
| Flexibility | Limited to inputs | Full control | Control over inputs only |
When to Use What
- Community Modules: Go-to for rapid prototyping or teams with minimal customization needs.
- Custom Modules: Best for specialized architectures requiring bespoke resource definitions.
- Wrapper Modules: Ideal for enforcing organizational governance on top of community best practices.
Avoid forking community modules unless you require deep structural changes. Wrapping keeps you in sync with upstream fixes and feature releases.