Connecting Bundles
This guide publishes the catalog's postgres bundle, which depends on the virtual-network resource that the network bundle from part 1 produces. You link the two on the canvas and deploy the database into the network.
You will learn:
- How a resource type defines the contract between two bundles
- How a bundle declares the resources it produces and the dependencies it consumes
- How
mass bundle buildturns a dependency into a typed OpenTofu variable - How to link components on the canvas
Resources and resource types​
A resource is structured JSON that a deployed bundle produces for other bundles to consume. A resource type is the JSON Schema it must match:
- A bundle that produces a resource must emit JSON that matches the resource type.
- A bundle that depends on a resource receives JSON that matches the resource type.
A bundle declares both in its massdriver.yaml:
resources: what the bundle producesdependencies: what the bundle consumes
Resource types are not paired one-to-one with bundles. Several bundles can produce the same resource type, for example a logging bucket, a data lake bucket, and a CDN origin bucket can all produce object-storage. Any of them can then fill a dependency on object-storage.
Step 1: Examine the resource types​
Open resource-types/virtual-network/massdriver.yaml. Abridged:
name: virtual-network
version: 0.0.0
label: Virtual Network
schema:
title: Virtual Network
type: object
additionalProperties: false
required:
- id
- cidr
- subnets
properties:
id:
type: string
cidr:
type: string
region:
type: string
subnets:
type: array
items:
type: object
required: [id, cidr]
properties:
id: { type: string }
cidr: { type: string }
type: { type: string, enum: [public, private] }
nameis how bundles refer to the resource type. Inside your organization no prefix is needed.versionis the version of the contract. A published version is immutable, except0.0.0, which can be republished.labelis the name shown in the UI.schemais the JSON Schema that everyvirtual-networkresource must match.
resource-types/postgres-database/massdriver.yaml defines the resource the postgres bundle produces. Its auth.password field sets $md.sensitive: true, so the value is masked in the UI and API.
See the Resource Type Specification for the full format.
Step 2: Publish the resource type and the bundle​
From the catalog root:
mass resource-type create postgres-database
mass resource-type publish resource-types/postgres-database
mass bundle create postgres
mass bundle publish bundles/postgres
Step 3: Examine the dependency​
In bundles/network/massdriver.yaml, the network bundle produces one resource:
resources:
network:
resource_type: virtual-network@0.0.0
required: true
bundles/network/src/resources.tf emits it with the massdriver_resource resource. field matches the key under resources, and the payload matches the virtual-network schema:
resource "massdriver_resource" "network" {
field = "network"
name = "Demo Network ${var.md_metadata.name_prefix}"
resource = jsonencode({
id = random_pet.main.id
cidr = var.cidr
region = "us-east-1"
subnets = local.subnets
})
}
In bundles/postgres/massdriver.yaml, the postgres bundle depends on it:
dependencies:
network:
resource_type: virtual-network@0.0.0
required: true
A resource pins the exact version it produces. A dependency takes a version range, such as virtual-network@~1 for any 1.x.x release. The catalog uses 0.0.0 on both sides. See Version Resolution.
required: true blocks deployment until the dependency is filled.
Step 4: Generate the dependency variable​
mass bundle build bundles/postgres
mass bundle build writes bundles/postgres/src/_massdriver_variables.tf. Each param and each dependency becomes a typed variable. The network dependency becomes:
variable "network" {
type = object({
cidr = string
id = string
region = optional(string)
subnets = list(object({
availability_zone = optional(string)
cidr = string
id = string
type = optional(string)
}))
})
}
mass bundle publish runs the same build, so you do not need to run it before publishing.
Step 5: Link the components​
- Open the environment canvas from part 1.
- Open the bundles drawer, drag
postgresonto the canvas, enter a Component Name and Component ID, and click Add. - Drag from the
networkcomponent's output to thepostgrescomponent's input to draw a link.
The canvas only lets you link an output to an input of the same resource type.
Step 6: Configure and deploy​
Click the
postgrescomponent and open the Config tab.Open Config options and pick a preset, such as Development (single-AZ, minimal retention).
Open Subnet Placement. Its options are the subnets of the linked network. The param sets
$md.enum, which reads.subnetsfrom thenetworkdependency:yamlsubnet_filter:
title: Subnet Placement
type: string
$md.enum:
connection: network
options: .subnets
value: .idClick Deploy.
When the deployment completes:
- The Dependencies tab shows the
networkdependency, its resource type and accepted version, and the instance filling it. - The Resources tab shows the
postgres-databaseresource. Show resource data shows the payload with the password masked.
Next​
Creating Your Own Bundle turns an existing OpenTofu module into a bundle.