Creating Bundle Templates
A bundle template is a directory that mass bundle new copies to start a new bundle. Templates keep new bundles in your organization consistent.
Directory Structure​
A templates directory holds one subdirectory per template. Each template has a massdriver.yaml at its root:
templates/
├── opentofu-module/
│ ├── massdriver.yaml
│ ├── operator.md
│ └── src/
│ ├── _providers.tf
│ └── main.tf
├── helm-chart/
│ ├── massdriver.yaml
│ └── chart/
│ ├── Chart.yaml
│ ├── values.yaml
│ └── templates/
└── my-custom-template/
├── massdriver.yaml
└── ...
A subdirectory named alpha is ignored.
mass bundle new renders the files at the template's root, such as massdriver.yaml and operator.md, with Liquid. Files in subdirectories are copied as they are, so Helm templates and other files that use {{ }} are not changed.
Creating a Template​
1. Create the Template Directory​
mkdir -p my-templates/my-opentofu-bundle
cd my-templates/my-opentofu-bundle
2. Write the massdriver.yaml Template​
name: "{{ name }}"
description: "{{ description }}"
source_url: github.com/YOUR_ORG/{{ name }}
version: 0.1.0
steps:
- path: src
provisioner: opentofu
# Params imported from existing IaC, or a default
{%- if paramsSchema.size > 0 %}
{{ paramsSchema }}
{% else %}
params:
examples:
- __name: Development
instance_type: t3.small
- __name: Production
instance_type: t3.large
required:
- instance_type
properties:
instance_type:
type: string
title: Instance Type
description: EC2 instance type
default: t3.small
{% endif %}
# Dependencies chosen when the bundle is created
{%- if connections.size > 0 %}
dependencies:
{%- for conn in connections %}
{{ conn.name }}:
resource_type: {{ conn.resourceType }}
required: true
{%- endfor %}
{% else %}
dependencies: {}
{% endif %}
resources: {}
ui:
ui:order:
- "*"
Template Variables​
| Variable | Description |
|---|---|
name | Bundle name |
description | Bundle description |
connections | The chosen dependencies. Each has name and resourceType. |
paramsSchema | YAML params block imported from an existing OpenTofu module or Helm values.yaml, when --params-directory is given or a path is entered at the prompt |
templateName | Name of the template |
outputDir | Directory the bundle is written to |
3. Add IaC Files​
src/main.tf
resource "aws_instance" "main" {
ami = var.ami
instance_type = var.instance_type
tags = var.md_metadata.default_tags
}
src/_providers.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
massdriver = {
source = "massdriver-cloud/massdriver"
}
}
}
provider "aws" {
region = var.region
assume_role {
role_arn = var.aws_authentication.arn
external_id = var.aws_authentication.external_id
}
default_tags {
tags = var.md_metadata.default_tags
}
}
The fields of var.aws_authentication follow the schema of the resource type it depends on.
4. Add an Operator Guide (Optional)​
operator.md is documentation for the bundle's users. At the template's root, it is rendered with the same variables:
## {{ name }}
{{ description }}
### Configuration
Configure the instance type based on your workload requirements.
### Troubleshooting
Check CloudWatch logs for any deployment issues.
Configuring the CLI​
Point the CLI at your templates directory with an environment variable:
export MASSDRIVER_TEMPLATES_PATH=/path/to/my-templates
Or with templates_path in a profile in ~/.config/massdriver/config.yaml:
profiles:
default:
templates_path: /path/to/my-templates
The environment variable takes precedence over the config file.
Using Templates​
List the templates:
mass bundle template list
Available templates:
helm-chart
my-custom-template
opentofu-module
Create a bundle interactively:
mass bundle new
Or with flags:
mass bundle new \
--name my-new-bundle \
--template-name opentofu-module \
--output-directory ./my-new-bundle \
--connections aws_authentication=aws-iam-role@~1
--connections takes <name>=<resource type> and can be repeated. --params-directory imports params from an existing OpenTofu module directory or Helm values.yaml.
Template Practices​
Include Cloud Credentials​
Include the cloud credential dependency for the template's cloud:
| Cloud | Resource Type | Suggested Name |
|---|---|---|
| AWS | aws-iam-role | aws_authentication |
| GCP | gcp-service-account | gcp_authentication |
| Azure | azure-service-principal | azure_authentication |
The Bicep provisioner reads Azure credentials from a dependency named azure_authentication.
Provide Presets​
Add examples to params so the form offers presets:
params:
examples:
- __name: Development
instance_type: t3.small
storage_size: 20
- __name: Production
instance_type: t3.large
storage_size: 100
Organize by Use Case​
templates/
├── aws-lambda-api/ # API Gateway + Lambda
├── aws-ecs-service/ # ECS Fargate service
├── gcp-cloud-run/ # Cloud Run service
├── k8s-deployment/ # Generic Kubernetes deployment
└── internal-api/ # Your organization's internal API pattern
Version Templates​
Keep templates in version control and tag releases:
git tag v1.0.0
git push origin v1.0.0
Example: OpenTofu Template for an S3 Bucket​
s3-bucket/
├── massdriver.yaml
├── operator.md
└── src/
├── _providers.tf
└── main.tf
massdriver.yaml:
name: "{{ name }}"
description: "{{ description }}"
source_url: github.com/YOUR_ORG/{{ name }}
version: 0.1.0
steps:
- path: src
provisioner: opentofu
params:
examples:
- __name: Development
bucket_name: my-dev-bucket
versioning_enabled: false
- __name: Production
bucket_name: my-prod-bucket
versioning_enabled: true
required:
- bucket_name
properties:
bucket_name:
type: string
title: Bucket Name
versioning_enabled:
type: boolean
title: Enable Versioning
default: false
dependencies:
aws_authentication:
resource_type: aws-iam-role@~1
required: true
resources:
bucket:
resource_type: aws-s3-bucket@~1
required: true
ui:
ui:order:
- bucket_name
- versioning_enabled
mass bundle build writes the variable declarations for src/.
Reference Templates​
The application-templates repository has templates for AWS, GCP, Azure, and Kubernetes.