Source
yaml
id: infrastructure-automation
namespace: tutorial
description: Infrastructure Automation
inputs:
  - id: docker_image
    type: STRING
    defaults: kestra/myimage:latest
tasks:
  - id: build_image
    type: io.kestra.plugin.docker.Build
    dockerfile: |
      FROM python:3.11-alpine
      RUN pip install --no-cache-dir kestra
    tags:
      - "{{ inputs.docker_image }}"
    push: false # you can change this to true after adding credentials
    credentials:
      registry: https://index.docker.io/v1/
      username: "{{ kv('DOCKERHUB_USERNAME', errorOnMissing=false) }}"
      password: "{{ kv('DOCKERHUB_PASSWORD', errorOnMissing=false) }}"
  - id: run_container
    type: io.kestra.plugin.docker.Run
    pullPolicy: NEVER # to use the local image we've just built
    containerImage: "{{ inputs.docker_image }}"
    commands:
      - pip
      - show
      - kestra
  - id: run_terraform
    type: io.kestra.plugin.terraform.cli.TerraformCLI
    beforeCommands:
      - terraform init
    commands:
      - terraform plan 2>&1 | tee plan_output.txt
      - terraform apply -auto-approve 2>&1 | tee apply_output.txt
    outputFiles:
      - "*.txt"
    inputFiles:
      main.tf: |
        terraform {
          required_providers {
            http = {
              source = "hashicorp/http"
            }
            local = {
              source = "hashicorp/local"
            }
          }
        }
        provider "http" {}
        provider "local" {}
        variable "pokemon_names" {
          type    = list(string)
          default = ["pikachu", "psyduck", "charmander", "bulbasaur"]
        }
        data "http" "pokemon" {
          count = length(var.pokemon_names)
          url   = "https://pokeapi.co/api/v2/pokemon/${var.pokemon_names[count.index]}"
        }
        locals {
          pokemon_details = [for i in range(length(var.pokemon_names)) : {
            name  = jsondecode(data.http.pokemon[i].response_body)["name"]
            types = join(", ", [for type in jsondecode(data.http.pokemon[i].response_body)["types"] : type["type"]["name"]])
          }]
          file_content = join("\n\n", [for detail in local.pokemon_details : "Name: ${detail.name}\nTypes: ${detail.types}"])
        }
        resource "local_file" "pokemon_details_file" {
          filename = "${path.module}/pokemon.txt"
          content  = local.file_content
        }
        output "file_path" {
          value = local_file.pokemon_details_file.filename
        }
  - id: log_pokemon
    type: io.kestra.plugin.core.log.Log
    message: "{{ read(outputs.run_terraform.outputFiles['pokemon.txt']) }}"
About this blueprint
Getting Started API DevOps
This flow is a simple example of an infrastructure automation use case. It builds a Docker image, runs a container, and uses Terraform to create a file with details about Pokémon.
The flow has four tasks:
- The first task builds a Docker image.
 - The second task runs a container using the image.
 - The third task uses Terraform to create a file with details about Pokémon.
 - The fourth task logs the details about Pokémon.
 
More Related Blueprints