> For the complete documentation index, see [llms.txt](https://bluebricks.co/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bluebricks.co/docs/orchestration/packages/blueprints-overview/from-code-to-blueprint.md).

# From Code to Blueprint

Bluebricks lets you take Infrastructure as Code (IaC), such as Terraform, OpenTofu, Helm, CloudFormation, or Bicep, and publish it as a [blueprint](/docs/orchestration/packages/blueprints-overview.md): a versioned, reusable package that anyone on your team can deploy. You deploy blueprints into [collections](/docs/orchestration/collections.md), which represent your target cloud accounts and their configuration.

This guide walks you through publishing a blueprint. You can do this two ways:

* **CLI**: publish a blueprint from your terminal, then create an environment separately to deploy it. Works with any Git host or local directory.
* **Bluebricks app**: create a blueprint and an environment in one step, with automatic runs on every push. Works with GitHub repositories or any public Git URL.

## Prerequisites

* The [Bricks CLI](/docs/bricks-cli/bricks-cli.md) installed and authenticated (`bricks login`)
* A [collection](/docs/orchestration/collections.md) with at least one connected cloud account
* Infrastructure as Code in a Git repository or local directory

## How to publish a blueprint from the CLI

The fastest way to turn code into a blueprint is to publish directly from your terminal. This works with any Git host (GitHub, GitLab, Azure DevOps) or a local directory.

### Single module

If you have a Terraform or OpenTofu module with `main.tf`, `variables.tf`, and `outputs.tf`, you can publish it as a blueprint in two steps:

```bash
cd path/to/your/terraform-module
bricks blueprint publish
```

If no `bricks.yaml` or `bricks.json` exists in the directory, the CLI auto-detects your IaC type, generates a `bricks.json` with the correct metadata, packages your code, and uploads the blueprint to Bluebricks. If a config file already exists, the CLI uses it as-is. Your blueprint is now available in your organization and ready to deploy (see [Deploy after publishing](#deploy-after-publishing) below).

{% hint style="warning" %}
The CLI classifies all `.tf` files as OpenTofu. If you are using Terraform, the behavior is the same, but the IaC type in the blueprint metadata will show as `opentofu`.
{% endhint %}

{% hint style="info" %}
If both `bricks.yaml` and `bricks.json` exist in the same directory, the CLI uses `bricks.yaml` and ignores `bricks.json`.
{% endhint %}

If your code lives in a subdirectory rather than the repository root, use the `--src` flag:

```bash
bricks blueprint publish --src ./infra/compute
```

### Multiple packages

If your infrastructure needs more than one module (for example, a VPC and a compute layer), you can compose multiple packages into a single blueprint using `bricks blueprint init`, `add`, and `publish`. For the full walkthrough, including wiring inputs and data references between packages, see [Creating Blueprints](/docs/orchestration/packages/blueprints-overview/creating-blueprints.md).

### Deploy after publishing

Once published, deploy the blueprint by creating an environment:

{% tabs %}
{% tab title="Bluebricks app" %}
Go to **Environments** > **Create environment** > **From blueprint**, then select your blueprint.
{% endtab %}

{% tab title="CLI" %}

```bash
bricks install
```

The CLI prompts you to select a blueprint and a target collection.
{% endtab %}
{% endtabs %}

For the full walkthrough, see [Creating Environments](/docs/orchestration/environments/creating-environments.md).

## How to update a blueprint

When you change your IaC code and want to publish a new version, bump the version and republish.

### Bump the version

```bash
bricks blueprint bump --minor
```

This increments the version in your `bricks.json` (for example, from 1.0.0 to 1.1.0). You can also use `--major` or `--patch` depending on the scope of the change. If you omit the flag, the CLI defaults to a minor bump.

### Update nested packages

If your blueprint composes other packages and you want to pull in their latest published versions:

```bash
bricks blueprint update --all
```

To update a specific package:

```bash
bricks blueprint update terraform_aws_vpc
```

### Republish

After bumping and updating, publish the new version:

```bash
bricks blueprint publish
```

Environments pinned to the latest version of this blueprint will pick up the new version on their next run. Environments pinned to a specific version are not affected until you update their configuration.

## How to publish from the Bluebricks app

You can also create a blueprint through the **From code** flow in the Bluebricks app. This connects your repository, creates the blueprint and environment, and auto-triggers runs on every push. Go to **Environments** > **Create environment** > **From code** to get started.

For the full walkthrough, see [Creating Environments](/docs/orchestration/environments/creating-environments.md). For auto-trigger behavior on push and PR, see [GitOps Environments](/docs/orchestration/environments/gitops-environments.md).

## Structuring your repository

Bluebricks is flexible about repository layout, whether your code is at the root, in a subdirectory, or spread across a mono-repo with multiple blueprints. For recommended patterns and folder structures, see [Git Repository Folder Structure](/docs/orchestration/bluebricks-git-repository-guide/git-repository-folder-structure.md).

## What's next?

<table data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Creating environments</strong><br>Deploy your blueprint into a collection</td><td><a href="/files/mbJmfgO5H6vqqqvo0l8E">/files/mbJmfgO5H6vqqqvo0l8E</a></td><td><a href="/pages/wmrjXfTYHjDOou8bKtw7">/pages/wmrjXfTYHjDOou8bKtw7</a></td></tr><tr><td><strong>GitOps Environments</strong><br>Set up automatic plan and apply on every push</td><td><a href="/files/SwjNpAvcBB7iFIXkvPqX">/files/SwjNpAvcBB7iFIXkvPqX</a></td><td><a href="/pages/dEO0qG5EiBiMxvwfKOPo">/pages/dEO0qG5EiBiMxvwfKOPo</a></td></tr><tr><td><strong>Day 2 Operations</strong><br>Scale, update, and manage deployed infrastructure</td><td><a href="/files/YUtDiVulGDfnpbNXFMJB">/files/YUtDiVulGDfnpbNXFMJB</a></td><td><a href="/pages/8nGEvmy9vBAjR8w4oyvl">/pages/8nGEvmy9vBAjR8w4oyvl</a></td></tr></tbody></table>

<table data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>Packages</strong><br>Create reusable building blocks used to deploy infrastructure</td><td><a href="/files/kJjU1J5en9mTArv4ytat">/files/kJjU1J5en9mTArv4ytat</a></td><td><a href="/pages/RaVuz2bcyctXGY0ErjIj">/pages/RaVuz2bcyctXGY0ErjIj</a></td></tr><tr><td><strong>Composition Patterns</strong><br>Wire multiple packages together</td><td><a href="/files/TRTAlCljrj8pzEJxdATW">/files/TRTAlCljrj8pzEJxdATW</a></td><td><a href="/pages/MSfXwjSeTcxWsrbAF4AQ">/pages/MSfXwjSeTcxWsrbAF4AQ</a></td></tr><tr><td><strong>Inputs and Outputs</strong><br>Expose the right configuration to deployers</td><td><a href="/files/S9u8WSHE0JQebYN6iXb1">/files/S9u8WSHE0JQebYN6iXb1</a></td><td><a href="/pages/7krvs94XFpdBRktHXu4D">/pages/7krvs94XFpdBRktHXu4D</a></td></tr></tbody></table>
