Publish a Terraform Module

Convert an existing Terraform module into a Bluebricks package using the prepare and publish CLI workflow

Overview

Convert your existing Terraform module into a Bluebricks package in two steps: prepare locally, then publish to your organization.

Prerequisites

  • Bricks CLI installed and authenticated (bricks login)

  • Existing Terraform module with .tf files

How to publish a Terraform module

1

Prepare your module

Navigate to your Terraform directory and run:

cd /path/to/your-terraform-module
bricks blueprint prepare --source . --iac-type terraform

This creates a bricks.json with auto-detected variables and outputs. Your original .tf files remain in place.

2

Publish to your organization

bricks blueprint publish

Your module is now available to your organization.

What each command does

bricks blueprint prepare generates a bricks.json in your current directory. No files are moved or copied, and no API calls are made. Your .tf files stay exactly where they are.

bricks blueprint publish uploads your package to Bluebricks. Variables and outputs are auto-discovered from your .tf files, external module references are resolved (if --resolve-modules is enabled), and the package is made available to your organization.

Working with existing modules

Local module references

If your Terraform uses local modules:

Bluebricks automatically handles this with --resolve-modules (enabled by default):

What happens:

  1. Finds all modules referenced with ../

  2. Copies them to bricks_modules/ directory

  3. Updates references to point to ./bricks_modules/

  4. Includes everything in the published package

Your module becomes self-contained and portable.

Disable module resolution

If you don't want to include external modules:

Bluebricks warns you about external references but won't include them.

Terraform version

Default version: 1.5.7

Specify a different version in bricks.json:

For the full version limits table and examples, see version pinning.

State management

Bluebricks automatically manages state using its built-in HTTP backend. Do not include backend.tf or backend configuration blocks in your Terraform code.

For details on managed state, locking, and encryption, see Terraform/OpenTofu.

To work locally with remote state for debugging or development, see Develop Terraform Locallyarrow-up-right.

Publishing with existing state

If you're migrating existing Terraform infrastructure, include your state file:

Requirements:

  • Place terraform.tfstate in your Terraform directory

  • Bluebricks packages it with your module

  • State is stored securely in Bluebricks

Variables and outputs mapping

Variables and outputs are auto-discovered during publish. Bluebricks parses your variables.tf and outputs.tf, then converts them to props and outs in bricks.json. See Terraform/OpenTofu inputs and outputs for the full mapping details and examples.

Examples

chevron-rightPublishing a VPC modulehashtag
chevron-rightPublishing with local moduleshashtag

Bluebricks automatically detects ../common/networking, copies it to bricks_modules/common/networking/, updates your references, and packages everything together. Your published module is now self-contained.

chevron-rightMigrating existing infrastructurehashtag

Bluebricks stores your state securely, enables locking to prevent conflicts, and provides a full audit trail.

Common options

chevron-rightPrepare optionshashtag
  • --source: Path to Terraform directory

  • --iac-type: Must be terraform

  • --output: Where to create package (default: current directory)

  • --package-name: Custom package name (default: directory name)

  • --refactor: Create bricks.json without moving files

chevron-rightPublish optionshashtag
  • --src: Package directory (default: current directory)

  • --resolve-modules: Include external modules (default: true)

  • --state: Include terraform.tfstate file

Generated package structure

chevron-rightAfter preparehashtag
chevron-rightAfter publish with --resolve-moduleshashtag

Best practices

  • Test locally before publishing

  • Use --resolve-modules for portability

  • Include state with --state when migrating existing infrastructure

  • Version your packages with semantic versioning

See also

Last updated

Was this helpful?