Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Terraform Hands On Workshop (DevOpsDays Graz)

Terraform Hands On Workshop (DevOpsDays Graz)

Infrastructure as Code is essential, if you want to rely on sustainable, fast, and reproducible deployments across multiple cloud platforms. In this workshop, we will explore how to automate the deployment of resources using Terraform. Not very experienced or a beginner? No problem, we will go through the concepts of Terraform from scratch together and write the code piece by piece. The final goal is to create your first Terraform configuration, and to conduct the corresponding commands to deploy the resources. Terraform can be used to create, change, and to destroy resources across different cloud providers, the dedicated code for that will be written in HCL (HashiCorp Configuration Language). Each cloud provider defines their own APIs and models of the resources, therefore the Terraform configuration varies according to the preferred cloud provider – which will be Azure for this workshop.

* Introduction to Terraform
* What is Terraform?
* Concepts of Terraform: Resource Blocks, Terraform Block, Provider Block, State File, HCL Notation
* Commands: Init, Validate, Format, Plan, Apply, Destroy
* Terraform usage across multiple cloud platforms – examples
* Terraform automation for CI/CD platforms
* Set up the stage
* Setting up the development environment using a dev container with GitHub Codespaces (prepared for you)
* Login to the subscription using the Azure CLI
* Create the Terraform configuration using the official HashiCorp Style Guide
* Conducting the Terraform commands to deploy the resources on Azure
* Changing the resources with adapting the Terraform configuration
* Destroying the resources on Azure
* Deploy and destroy resources on Azure using Terraform
* Conclusion and derived Best Practice

Avatar for Patrick Koch

Patrick Koch

September 11, 2025
Tweet

More Decks by Patrick Koch

Other Decks in Programming

Transcript

  1. Content  Introduction to Terraform Source GitHub Codespaces icon: https://education.github.com/experiences/primer_codespaces,

    Azure Icon: Azure Public Service Icons V14, Ubuntu Icon: https://en.m.wikipedia.org/wiki/File:Logo-ubuntu_cof-orange-hex.svg, Terraform Icon: HashiCorp Brand Kit
  2. Content  GitHub Codespaces  Terraform Configuration and Workflow Source

    GitHub Codespaces icon: https://education.github.com/experiences/primer_codespaces, Azure Icon: Azure Public Service Icons V14, Ubuntu Icon: https://en.m.wikipedia.org/wiki/File:Logo-ubuntu_cof-orange-hex.svg, Terraform Icon: HashiCorp Brand Kit
  3. on-site / dev environment in the cloud user Terraform configuration

    in a GitHub Codespace Ubuntu virtual machine Source GitHub Codespaces icon: https://education.github.com/experiences/primer_codespaces, Azure Icons: Azure Public Service Icons V14, Ubuntu Icon: https://en.m.wikipedia.org/wiki/File:Logo-ubuntu_cof-orange-hex.svg, Terraform Icon: HashiCorp Brand Kit Goal
  4. Create a new GitHub repository  Arbitrary name, public 

    Add the ".devcontainer" directory from the GitHub repo below in your newly created GitHub repository  https://github.com/patkoch/azure_terraform_codespace
  5. Create a Terraform configuration for a Linux Virtual Machine Source

    GitHub Codespaces icon: https://education.github.com/experiences/primer_codespaces, Azure Icons: Azure Public Service Icons V14, Ubuntu Icon: https://en.m.wikipedia.org/wiki/File:Logo-ubuntu_cof-orange-hex.svg, Terraform Icon: HashiCorp Brand Kit
  6. terraform.tf terraform { required_providers { azurerm = { source =

    "hashicorp/azurerm" version = "~> 4.43" } } } https://github.com/patkoch/terraform-azure-virtual-machine-linux/blob/main/terraform.tf
  7. main.tf resource "azurerm_resource_group" "example" { name = "example-resources" location =

    "West Europe" } …. Change the name of the vm and the name of the resource group https://github.com/patkoch/terraform-azure-virtual-machine-linux/blob/main/main.tf
  8. variables.tf variable "virtual_machine_name" { type = string default = "dodgrz-25"

    description = "Name of the virtual machine" } variable "virtual_machine_admin_username" { type = string default = "adminuser" description = "Admin user name" } ... https://github.com/patkoch/terraform-azure-virtual-machine-linux/blob/main/variables.tf
  9. Deploying the virtual machine  https://github.com/patkoch/terraform-azure-virtual-machine-linux  Create a RSA

    key pair  ssh-keygen -t rsa -f id_rsa  terraform init  terraform fmt # format  terraform validate # validate  terraform plan –out tfplan # create an execution plan  terraform apply tfplan # deploy the resources
  10. Connect to the Ubuntu VM  chmod 600 id_rsa 

    ssh -i id_rsa adminuser@<public IP of the virtual machine>  ls –la  exit