Course · Training · Workshop

Terraform for AWS, Azure or GCP

Two days hands-on: define cloud infrastructure as code with Terraform, manage state and modules as a team, and roll out changes across several stages with GitLab CI/CD pipelines and Terragrunt.

The first cloud resources are often created by clicking through the portal or with a few scripts. Once several people, several environments and weekly changes are involved, questions come up: who changed what, what is actually running, and how do you build the same environment a second time? Terraform describes infrastructure declaratively in HCL, shows every change in a plan before it is executed and records the resources it manages in the state. In this course you build an infrastructure of network, virtual machines and a web server step by step in your own Azure resource group. On the first day you write resources, variables, conditions and loops, move the state to a remote backend and import existing resources. On the second day you develop your own module with version tags in GitLab, check it in a pipeline with terraform validate, terraform fmt, Trivy and terraform-docs, and structure several stages with Terragrunt. You also cover the topics that matter in a team: state locking, versions of Terraform, providers and modules, handling secrets and approvals before an apply. The concepts are cloud-independent and transfer to AWS and GCP. The course also explains when Terraform and when OpenTofu is the right fit. At the end you have a repository with infrastructure code, a versioned module, a pipeline and a multi-stage setup that you can use as a template for your own projects.

What participants say

This was the second course from letsboot. Like the first one, also with this one the trainers know-how was excellent. letsboot is generally very flexible in adjusting their course material and the trainers easily respond and adjust to our project related questions.
Andreas Andreas
Software-Entwickler, Schweizerischer Nationalfonds

These customers booked courses in the same topic cluster.More customers →

Content

This Terraform training is aimed at engineers who build cloud infrastructure as code and run it as a team. You work in your own Azure resource group and extend the same infrastructure chapter by chapter: from the first network to a multi-stage setup with a pipeline.

The course consists of the following topics and can be adapted to the audience. The first day covers the language, the workflow and the state, the second day modules, teamwork, security, pipelines and Terragrunt. For in-house courses we agree on the focus areas and the depth of each chapter.

Infrastructure as Code and the Terraform workflow

  • Infrastructure as Code: defining, versioning and reproducibly building infrastructure
  • Terraform compared with other IaC tools, and where Terraform does not help
  • The workflow of terraform init, validate, plan, apply and destroy
  • The dependency graph and the order of resources
  • Providers, resources and data sources, and the structure of a Terraform project
  • Hands-On: Start the labmachine and check the Azure login with terraform, terragrunt and az

First infrastructure with Terraform

  • Authenticating to Azure: Azure CLI, managed identity and service principal
  • Configuring the azurerm provider and using the provider documentation in the Registry
  • Referencing existing resources with data sources
  • Reading planned changes in the plan and checking them in the Azure portal after the apply
  • Hands-On: Create a virtual network, subnet, network interface and a Linux VM in your own resource group

Variables, expressions and loops

  • Input variables, outputs and locals
  • Primitive and complex types: list, set, map and object
  • Conditions and loops with count and for_each
  • Functions, dynamic blocks and external data with yamldecode and csvdecode
  • Provisioners and cloud-init, and when to use which
  • Hands-On: Assign a public IP by condition, add a network security group, provision a web server with cloud-init and create several VMs with count

Provider versions and state

  • required_providers, version constraints and the dependency lock file
  • The purpose of the state file and the limits of local state
  • Remote backends with state locking on Azure Blob Storage, GCS and AWS S3
  • Editing state and refactoring code with terraform state mv and moved blocks
  • Bringing existing resources under management with terraform import and import blocks
  • Hands-On: Migrate the state to a remote backend on Azure Blob Storage, switch from count to for_each and import a manually created availability set

Modules

  • Structure of a module: variables, outputs and versions
  • Module sources: local path, Git repository with tag, and registry
  • Public and private modules, and looping over modules
  • Semantic versioning for modules and input validation
  • Hands-On: Move the VM resources into your own module, publish it in a GitLab repository with a version tag and reference it via the Git URL

Terraform in teams

  • Concurrent changes: state locking, a central apply pipeline and responsibilities
  • Pinning versions of Terraform, providers and modules and keeping them current with Renovate
  • Roles and permissions, and collaboration between infrastructure teams
  • Handover to configuration management and app deployment
  • Terraform and OpenTofu: licence, feature differences and switching between the two
  • Demo: Ansible dynamic inventory from Terraform outputs

Security in IaC

  • Providing credentials via environment variables or a secret manager such as Vault
  • Sensitive values in outputs and state, state encryption and ephemeral values
  • Least privilege for code, pipelines, state and the cloud hierarchy
  • Approval workflows for critical changes, logging and backup of the state
  • IaC scanners such as Trivy, Checkov and KICS
  • Demo: Check a Terraform project for misconfigurations with trivy config

Pipelines for modules and deployments

  • Structure of a module pipeline: linting, validation, security scan, documentation, tests and release
  • pre-commit and terraform-docs for the same checks locally and in the pipeline
  • Deployment pipelines: passing the saved plan as an artifact to the apply job
  • Drift detection with scheduled plan runs and terraform plan -detailed-exitcode
  • Deployment options: plain Terraform, Terragrunt, Atlantis and HCP Terraform
  • Hands-On: Build a GitLab CI/CD pipeline for your module with terraform validate, terraform fmt, Trivy and terraform-docs, optionally a deployment pipeline with plan and apply

Terragrunt and multi-staging

  • Several stages with plain Terraform: duplicated code, backends and variables per stage
  • Terragrunt: terragrunt.hcl per unit, central configuration in root.hcl
  • Generating remote state and provider configuration with remote_state and generate
  • Reusing variables per stage and defining dependencies between modules
  • Planning and applying several units together with terragrunt run –all (formerly run-all)
  • Alternatives: Terraform workspaces, HCP Terraform, Terraform Enterprise and Atlantis
  • Hands-On: Create a network module, build a stage with Terragrunt, reuse stage variables and define provider and remote state centrally

Tests and going deeper

  • terraform test: tests in .tftest.hcl files with run and assert blocks and mock providers
  • Using public modules from the Registry and migrating the state
  • Dynamic blocks for repeating configuration blocks
  • Turning existing infrastructure into code with aztfexport or Terraformer
  • Recommendations on module size, interfaces between teams and the boundary to Helm and Ansible
  • Hands-On: Add a load balancer, define security rules as a dynamic block and write terraform test for your module

At the end of the two days you have built an infrastructure with network and virtual machines as code, kept the state in a remote backend, versioned your own module and checked it in a pipeline, and set up a multi-stage setup with Terragrunt. The repository with all exercises and solutions serves as a template for your own projects.

The actual course content may differ from the above depending on the trainer, delivery, duration and the composition of participants.

Request this course in-house

By submitting you accept our Privacy Policy.

Request a public date

No suitable public date? Register without obligation — once there is enough interest we schedule a new public date and let you know first.

Number of participants (approx.)

More than 3 participants? Best to request a dedicated in-house date directly.

By submitting you accept our Privacy Policy.

More about Terraform

Terraform is an Infrastructure as Code (IaC) tool by HashiCorp. Infrastructure is described declaratively in the HashiCorp Configuration Language (HCL); providers translate the configuration into API calls for AWS, Azure, GCP and many other platforms. The workflow of init, plan and apply shows every change before it is executed, and the state records which resources Terraform manages.

Mitchell Hashimoto and HashiCorp released Terraform in 2014 as an open-source project under the Mozilla Public License. In August 2023 HashiCorp moved Terraform to the Business Source License (BSL). In response, OpenTofu was created, a fork hosted by the Linux Foundation that keeps the Mozilla Public License. HashiCorp has been part of IBM since 2025. The hosted service Terraform Cloud has been called HCP Terraform since 2024. The CDK for Terraform (CDKTF) was discontinued in December 2025; HashiCorp recommends moving back to HCL.

Further resources:

Related courses