Publish a Terraform Module

Convert your existing Terraform module into a Bluebricks package in 3 simple steps.

Prerequisites

  • Bluebricks CLI installed

  • Authenticated (bricks login)

  • Existing Terraform module with .tf files

Quick Start

You have a Terraform module. Let's publish it.

Step 1: Prepare

Navigate to your Terraform directory and run:

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

This creates:

  • bricks.json with auto-detected variables and outputs

  • Original .tf files remain in place (no copying by default)

Step 2: Publish

Done. Your module is now available to your organization.

What Just Happened?

Prepare Command

bricks blueprint prepare creates a basic package structure locally:

  1. Creates bricks.json with minimal metadata:

    • native.type: "terraform"

    • native.path: "." (current directory, no copying)

    • Package name and version

  2. Keeps your .tf files in place (no copying by default)

That's it - no API calls, no parsing yet. Just a flat structure.

Publish Command

bricks blueprint publish is where the magic happens:

  1. Creates a zip archive of your package

  2. Resolves external module references (if --resolve-modules enabled)

  3. Uploads to Bluebricks platform (POST /v1/package)

  4. Bluebricks control plane enriches the metadata:

    • Parses variables.tf → converts to props in bricks.json

    • Parses outputs.tf → converts to outs in bricks.json

    • Detects provider requirements and dependencies

    • Validates Terraform syntax

  5. Stores enriched package with full metadata

  6. Makes it available to your organization

The Bluebricks control plane does the heavy lifting - parsing, validation, and enrichment all happen during publish.

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 will warn you about external references but won't include them.

Terraform Version

Default version: 1.5.7

Specify a different version in bricks.json:

State Management

Important: No backend.tf Required

Bluebricks automatically manages state using its built-in HTTP backend.

Do not include backend.tf or backend configuration blocks in your Terraform code.

If your Terraform includes backend configuration:

Simply remove the entire backend block. Bluebricks handles state storage, locking, and versioning automatically.

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

State in Bluebricks

When you run a Bluebricks package:

  1. Plan: Bluebricks downloads current state, runs terraform plan

  2. Apply: Runs terraform apply, captures new state

  3. Store: Uploads state to Bluebricks (HTTP backend)

  4. Lock: Uses locking to prevent concurrent modifications

State is automatically managed - you don't need to configure remote backends.

Example: Publishing a VPC Module

You have a VPC module:

Publish it:

Use it:

Example: Publishing with Local Modules

Your module references other local modules:

Publish it:

Bluebricks automatically:

  • Detects ../common/networking reference

  • Copies networking module to bricks_modules/common/networking/

  • Updates your main.tf to use ./bricks_modules/common/networking

  • Packages everything together

Your published module is now self-contained.

Example: Migrating Existing Infrastructure

You have live infrastructure managed by Terraform:

Now Bluebricks manages your infrastructure:

  • State is stored in Bluebricks

  • Locking prevents conflicts

  • Full history and audit trail

  • Team collaboration enabled

Common Options

Prepare Options

  • --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

Publish Options

  • --src: Package directory (default: current directory)

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

  • --state: Include terraform.tfstate file

Variables and Outputs Mapping

How Variables Become Props

Your variables.tf:

Becomes props in bricks.json:

Override with properties.json:

How Outputs Become Outs

Your outputs.tf:

Becomes outs in bricks.json:

Generated Package Structure

After prepare:

After publish with --resolve-modules:

Best Practices

Module Design:

  • Keep modules focused and reusable

  • Define all variables in variables.tf

  • Document all outputs in outputs.tf

  • Use semantic versioning

Publishing:

  • Test locally before publishing

  • Use --resolve-modules for portability

  • Include state for migrations

  • Version your packages properly

State Management:

  • Let Bluebricks manage state (don't configure remote backends)

  • Use --state when migrating existing infrastructure

  • Bluebricks handles locking automatically

Variables:

  • Provide defaults for optional variables

  • Use clear descriptions

  • Use proper types (string, number, bool, list, map)

See also

Last updated

Was this helpful?