Skip to main content

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 build turns 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 produces
  • dependencies: 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:

yaml
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] }
  • name is how bundles refer to the resource type. Inside your organization no prefix is needed.
  • version is the version of the contract. A published version is immutable, except 0.0.0, which can be republished.
  • label is the name shown in the UI.
  • schema is the JSON Schema that every virtual-network resource 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:

shell
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:

yaml
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:

hcl
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:

yaml
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​

shell
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:

hcl
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.

  1. Open the environment canvas from part 1.
  2. Open the bundles drawer, drag postgres onto the canvas, enter a Component Name and Component ID, and click Add.
  3. Drag from the network component's output to the postgres component'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​

  1. Click the postgres component and open the Config tab.

  2. Open Config options and pick a preset, such as Development (single-AZ, minimal retention).

  3. Open Subnet Placement. Its options are the subnets of the linked network. The param sets $md.enum, which reads .subnets from the network dependency:

    yaml
    subnet_filter:
    title: Subnet Placement
    type: string
    $md.enum:
    connection: network
    options: .subnets
    value: .id
  4. Click Deploy.

When the deployment completes:

  • The Dependencies tab shows the network dependency, its resource type and accepted version, and the instance filling it.
  • The Resources tab shows the postgres-database resource. Show resource data shows the payload with the password masked.

Next​

Creating Your Own Bundle turns an existing OpenTofu module into a bundle.