Build icon
Run icon
TerraformCLI icon
Log icon

Infrastructure Automation workflow example: Getting started with Kestra

Automate infrastructure with Kestra: build a Docker image, run it as a container, and provision files with Terraform in one declarative pipeline.

Categories
Getting StartedCoreInfrastructure

Automate an end-to-end infrastructure workflow that builds a Docker image, runs it as a container, and provisions resources with Terraform, all from a single declarative Kestra flow. This getting started example shows how to wire image builds, container execution, and Infrastructure as Code together so your DevOps automation runs as one reproducible pipeline instead of disconnected scripts and manual steps.

How it works

  1. build_image uses io.kestra.plugin.docker.Build to build a Docker image from an inline Dockerfile (Python 3.11 Alpine with the kestra package installed). The image tag comes from the docker_image input, and registry credentials are supplied as secrets so the image can be pushed once push is set to true.
  2. run_container uses io.kestra.plugin.docker.Run with pullPolicy: NEVER to run the freshly built local image and inspect the installed Kestra package via pip show kestra.
  3. run_terraform uses io.kestra.plugin.terraform.cli.TerraformCLI to run terraform init, plan, and apply -auto-approve. The inline main.tf fetches Pokémon data over HTTP and writes a formatted pokemon.txt file, captured through outputFiles.
  4. log_pokemon uses io.kestra.plugin.core.log.Log to read and log the generated pokemon.txt, verifying the automation worked end to end.

What you get

  • A working Docker build and run cycle driven entirely by YAML.
  • A Terraform plan and apply step with init, output capture, and inline configuration.
  • Reproducible artifacts (plan_output.txt, apply_output.txt, pokemon.txt) surfaced as task outputs.
  • A clear template for combining containerization and Infrastructure as Code in one flow.

Who it's for

  • Platform and DevOps engineers wiring up CI/CD and provisioning.
  • Data and infrastructure teams new to Kestra who want a hands-on starter.
  • Anyone consolidating Docker builds and Terraform runs into one orchestrated pipeline.

Why orchestrate this with Kestra

Docker and Terraform each run a single step well, but neither sequences a build, a container run, and a provisioning apply together with shared inputs and outputs. Kestra adds event triggers, automatic retries, full execution lineage, and a declarative YAML definition that ties these tools into one auditable workflow. You get a single source of truth for the whole pipeline instead of glue scripts, plus the ability to schedule, trigger, and observe every run.

Prerequisites

  • A running Kestra instance with the Docker and Terraform plugins available.
  • A Docker daemon reachable by the worker for building and running images.

Secrets

  • DOCKERHUB_USERNAME: Docker registry username (used when pushing the image).
  • DOCKERHUB_PASSWORD: Docker registry password or access token.

Quick start

  1. Add the DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD secrets to your Kestra instance.
  2. Create the flow from this blueprint.
  3. Execute it, optionally overriding the docker_image input tag.
  4. Inspect the logged Pokémon details and the captured output files.

How to extend

  • Set push: true on build_image to publish the image to your registry.
  • Replace the inline main.tf with your own Terraform provisioning real cloud resources.
  • Swap the pip show kestra command for your own container smoke test.
  • Add a schedule or webhook trigger to run the pipeline automatically.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.