Convert a Terraform Module to a Component β
Goal β
- Turn an existing Terraform/OpenTofu module into a Catalyst Component that bundles can reference via
source, with inputs inferred from module variables and basic metadata scaffolded. - Outcome: a reusable, policyβready Component definition living alongside your module, ready to be wired into bundles and generated into stack code.
Prerequisites β
- A Terraform/OpenTofu module directory with variables defined
Steps β
- Run inside the module directory
sh
terramate component create- Review generated files
- Inputs are inferred from module variables
- Initial metadata for the component is created
- Reference from a bundle
- In your bundle stack, add a
componentblock pointing to this componentβssource
Example: Convert terraform-aws-modules/s3-bucket β
- Fetch the module locally and enter it
sh
git clone https://github.com/terraform-aws-modules/terraform-aws-s3-bucket.git
cd terraform-aws-s3-bucket- Scaffold a Component
sh
terramate component create- Review the generated definition
- Inputs are inferred from
variables.tf(e.g.,bucket,versioning,policy, β¦). - Metadata is initialized; update
class,name, andversionto match your catalog.
Example metadata (edit to your org):
hcl
define component metadata {
class = "example.com/aws-s3-bucket"
version = "1.0.0"
name = "AWS S3 Bucket"
...
}- Reference from a bundle
hcl
define bundle stack "storage" {
component "bucket" {
source = "/components/example.com/aws-s3-bucket/v1"
inputs = {
bucket = "my-s3-bucket"
versioning = { enabled = true }
}
}
}Expected result β
- A usable Component definition that can be instantiated by Bundles.
See also β
- Reference: Component Definition