# 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](https://bluebricks.co/docs/core-concepts/packages/blueprints-overview): a versioned, reusable package that anyone on your team can deploy. You deploy blueprints into [collections](https://bluebricks.co/docs/core-concepts/collections), 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](https://bluebricks.co/docs/bricks-cli/bricks-cli) installed and authenticated (`bricks login`)
* A [collection](https://bluebricks.co/docs/core-concepts/collections) 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](https://bluebricks.co/docs/core-concepts/packages/blueprints-overview/creating-blueprints).

### 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](https://bluebricks.co/docs/core-concepts/environments/creating-environments).

## 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](https://bluebricks.co/docs/core-concepts/environments/creating-environments). For auto-trigger behavior on push and PR, see [GitOps Environments](https://bluebricks.co/docs/core-concepts/environments/gitops-environments).

## 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](https://bluebricks.co/docs/workflows/bluebricks-git-repository-guide/git-repository-folder-structure).

## 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="https://454695563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL1aVoJ67VgVl8Uv83TuE%2Fuploads%2FRQqsJ5vfHGnj6KEDKqhE%2FCreating%20environments.png?alt=media&#x26;token=e931ade2-2811-447c-8cfd-1fe9d6f3015e">Creating environments.png</a></td><td><a href="../core-concepts/environments/creating-environments">creating-environments</a></td></tr><tr><td><strong>GitOps Environments</strong><br>Set up automatic plan and apply on every push</td><td><a href="https://454695563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL1aVoJ67VgVl8Uv83TuE%2Fuploads%2FTWIYJBIdZqLd0kZMqjG6%2FGitOps.png?alt=media&#x26;token=d9f1eba0-7731-4dfe-a596-cdbec1fef8b8">GitOps.png</a></td><td><a href="../core-concepts/environments/gitops-environments">gitops-environments</a></td></tr><tr><td><strong>Day 2 Operations</strong><br>Scale, update, and manage deployed infrastructure</td><td><a href="https://454695563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL1aVoJ67VgVl8Uv83TuE%2Fuploads%2FXcS7iFZQ8vFScJ0woHvq%2FDay%202%20Operations.png?alt=media&#x26;token=88f677fc-b288-478a-9a8a-cba2951ee4d1">Day 2 Operations.png</a></td><td><a href="../managing-infrastructure/managing-infrastructure">managing-infrastructure</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="https://454695563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL1aVoJ67VgVl8Uv83TuE%2Fuploads%2FtTdEFjE3h05ZtZo1VkY1%2FPackages.png?alt=media&#x26;token=81a0ca28-4273-49c9-969f-68d5ec46dd25">Packages.png</a></td><td><a href="../core-concepts/packages">packages</a></td></tr><tr><td><strong>Composition Patterns</strong><br>Wire multiple packages together</td><td><a href="https://454695563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL1aVoJ67VgVl8Uv83TuE%2Fuploads%2FRA9Pd9T6zyTE7NKToPlH%2FComposition%20patterns.png?alt=media&#x26;token=f07f9a44-02f6-4a0c-90d4-9d1b3234341e">Composition patterns.png</a></td><td><a href="../core-concepts/packages/blueprints-overview/blueprint-composition-patterns">blueprint-composition-patterns</a></td></tr><tr><td><strong>Inputs and Outputs</strong><br>Expose the right configuration to deployers</td><td><a href="https://454695563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FL1aVoJ67VgVl8Uv83TuE%2Fuploads%2FKdJMPZvf8KJ782j2PL70%2Finputs%20outputs.png?alt=media&#x26;token=1ca07313-781a-4343-942a-175ec8d807eb">inputs outputs.png</a></td><td><a href="../core-concepts/packages/inputs-and-outputs">inputs-and-outputs</a></td></tr></tbody></table>
