Build
The build resource builds a container image from a Dockerfile during provisioning and, optionally, pushes it to one or more registries. Other resources can then reference the built image, letting a lab ship custom images without a separate CI pipeline.
HCL Syntax
Section titled “HCL Syntax”Basic Syntax
Section titled “Basic Syntax”resource "build" "app" { container { context = "./src" dockerfile = "./Dockerfile" }}Full Syntax
Section titled “Full Syntax”resource "build" "app" { container { context = "./src" dockerfile = "./Dockerfile" args = { VERSION = "1.0.0" } ignore = ["node_modules", ".git"] }
registry { name = "registry.example.com/app:latest" }}Fields
| Field | Type | Required | Description |
|---|---|---|---|
container | block | ✓ | Container build configuration |
output | block | — | Files or directories to copy from the containerrepeatable |
registry | block | — | Registry to push the built image torepeatable |
Container
Container build configuration
| Field | Type | Required | Description |
|---|---|---|---|
dockerfile | string | — | Location of Dockerfile inside build context, defaults to ./Dockerfile |
context | string | ✓ | Path to build context |
ignore | list(string) | — | Files to ignore in the build context, same as .dockerignore |
args | map(string) | — | Build args to pass to the container |
Output
Files or directories to copy from the container
| Field | Type | Required | Description |
|---|---|---|---|
source | string | ✓ | Source file or directory in the container |
destination | string | ✓ | Destination for copied file or directory |
Registry
Registry to push the built image to
| Field | Type | Required | Description |
|---|---|---|---|
name | string | ✓ | Full image name including registry and tag |
username | string | — | Registry username for authentication |
password | string | — | Registry password for authentication |
Computed Attributes
These attributes are set by the system and are read-only.
| Attribute | Type | Description |
|---|---|---|
image | string | Full local reference of the built image |
build_checksum | string | Checksum calculated from the build context files |
Examples
Section titled “Examples”Build and reference an image
Section titled “Build and reference an image”resource "build" "app" { container { context = "./app" }}
resource "container" "app" { image { name = resource.build.app.image }}Best Practices
Section titled “Best Practices”- Small contexts: Keep the build context minimal and use
ignoreto exclude files that don’t belong in the image. - Explicit tags: Give pushed images explicit tags in
registry.namerather than relying onlatest.
