Skip to main content

Creating a Bundle from an OpenTofu Module

This guide wraps an existing OpenTofu module in a bundle and deploys it.

If you are designing a catalog of bundles, model the bundle interfaces and resource types with the Massdriver Catalog first, then fill in the IaC with this guide.

Prerequisites​

  • The Massdriver CLI, configured for your organization

  • Bundle templates on your templates path, for example the templates directory of the Massdriver Catalog:

    shell
    mass config set default --templates-path ./massdriver-catalog/templates

Step 1: Create the bundle​

shell
mass bundle new

The prompts ask for:

  1. Name and Description.

  2. Template: choose opentofu, or terraform.

  3. Dependencies: the resource types the module consumes. For cloud credentials, choose the credential type and use the conventional name:

    CloudResource typeName
    AWSaws-iam-roleaws_authentication
    GCPgcp-service-accountgcp_authentication
    Azureazure-service-principalazure_service_principal
  4. Output directory: defaults to massdriver.

Without prompts:

shell
mass bundle new -n my-bucket -t opentofu -c aws_authentication=aws-iam-role -o massdriver

Step 2: Add the module​

  1. Copy the module's .tf files into the bundle's src directory, replacing the template's main.tf.

  2. Add a params entry in massdriver.yaml for each module variable:

    shell
    cd massdriver
    mass bundle import

    mass bundle import finds variables declared in each step's directory that are not yet params, dependencies, or md_metadata, and asks before adding each one. -a adds them all.

  3. Review src/providers.tf. Uncomment the provider for your cloud, or keep your module's own provider configuration and use the credential dependency in it, for example var.aws_authentication.data.arn.

  4. To produce resources for other bundles, declare them under resources in massdriver.yaml and create them with massdriver_resource. See Custom Resource Types.

  5. Create the repository once, then check and publish:

    shell
    mass bundle create my-bucket
    mass bundle lint
    mass bundle publish

Step 3: Deploy​

  1. Open or create a project and environment in Massdriver.
  2. Set the cloud credential as an environment default.
  3. Open the Bundles drawer on the canvas and add a component from your bundle.
  4. Open the instance, set its configuration on the Config tab, and deploy.

If the repository was created restricted, grant it to the project first.