Skip to main content

Using Bundle Deployment Metadata

Massdriver adds md_metadata to the params of every deployment. It carries the instance's name prefix, the tags to apply, the alarm webhook, and deployment context, so bundles do not need params for them.

md_metadata holds no secrets.

Two keys keep their v1 names: target holds environment data, and package holds instance data.

Access​

  • OpenTofu and Terraform: var.md_metadata. mass bundle build declares the variable in _massdriver_variables.tf.
  • jq expressions in a step's config block: .params.md_metadata. See The jq context.

Structure​

json
{
"name_prefix": "ecomm-prod-api-a1b2",
"default_tags": {
"managed-by": "massdriver",
"md-project": "ecomm",
"md-environment": "prod",
"md-component": "api",
"md-instance": "ecomm-prod-api"
},
"observability": {
"alarm_webhook_url": "https://..."
},
"deployment": {
"id": "6f1c2b8e-..."
},
"target": {
"contact_email": "jane@example.com"
},
"package": {
"created_at": "2026-01-15T18:21:07Z",
"updated_at": "2026-03-02T09:44:51Z",
"deployment_enqueued_at": "2026-03-02T09:45:03Z",
"previous_status": "PROVISIONED"
}
}

name_prefix​

Type: string

The instance's name prefix: a unique prefix for every cloud resource the instance creates. It is set from the organization's naming convention when the instance is created and does not change. With the default convention it is <project>-<environment>-<component>-<suffix>.

hcl
resource "aws_s3_bucket" "logs" {
bucket = "${var.md_metadata.name_prefix}-logs"
}

default_tags​

Type: map(string)

Tags to apply to every resource the bundle creates. The organization's default tags setting chooses the attributes in this map. managed-by (massdriver) and md-instance (the instance ID) are always present.

hcl
resource "aws_instance" "app" {
tags = merge(
var.md_metadata.default_tags,
{
Name = "${var.md_metadata.name_prefix}-app"
}
)
}

observability.alarm_webhook_url​

Type: string

The environment's alarm webhook. Point cloud alarms at it to report them to Massdriver. See Monitoring & Alarms.

hcl
resource "aws_cloudwatch_metric_alarm" "high_cpu" {
alarm_name = "${var.md_metadata.name_prefix}-high-cpu"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 2
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 120
statistic = "Average"
threshold = 80

alarm_actions = [var.md_metadata.observability.alarm_webhook_url]
}

deployment.id​

Type: string

The ID of the running deployment.

target.contact_email​

Type: string

The email of whoever created the deployment. For a service account it is a generated address, not a mailbox.

package​

Type: object

Instance context at the time the deployment was created.

FieldTypeHolds
created_atISO 8601 stringWhen the instance was created
updated_atISO 8601 stringWhen the instance was last updated
deployment_enqueued_atISO 8601 stringWhen this deployment was created
previous_statusstringThe instance's status before this deployment: INITIALIZED, PROVISIONED, DECOMMISSIONED, or FAILED

An instance that has never been deployed is INITIALIZED:

hcl
locals {
is_first_deployment = var.md_metadata.package.previous_status == "INITIALIZED"
}

resource "kubernetes_job" "migrations" {
count = local.is_first_deployment ? 1 : 0
# ...
}

Environment-specific behavior​

When the organization's default tags include md-environment, its value is the environment's ID without the project, such as prod:

hcl
locals {
is_production = var.md_metadata.default_tags["md-environment"] == "prod"
}

resource "aws_db_instance" "database" {
backup_retention_period = local.is_production ? 30 : 7
# ...
}

The same check in a step's config:

yaml
steps:
- path: src
provisioner: opentofu:1.10
config:
checkov:
enable: true
halt_on_failure: '.params.md_metadata.default_tags["md-environment"] == "prod"'

Best practices​

  1. Name resources from name_prefix. Do not ask users for project or environment names.
  2. Apply default_tags to every resource.
  3. Send alarms to alarm_webhook_url.