Slide 1

Slide 1 text

PATRICK KOCH Azure Infrastructure as Code: Hands-on Workshop

Slide 2

Slide 2 text

Content  GitHub Codespaces  Azure CLI  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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Dev Container and GitHub Codespace Source GitHub Codespaces icon: https://education.github.com/experiences/primer_codespaces

Slide 5

Slide 5 text

Create a new GitHub repository  Arbitrary name  Add the ".devcontainer" directory from the GitHub repo below in your newly created GitHub repository  https://github.com/patkoch/azure_terraform_codespace

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Azure – Login to the Portal  https://portal.azure.com/

Slide 8

Slide 8 text

Azure CLI – Authentication to a subscription  az login

Slide 9

Slide 9 text

Terraform Terraform Icon: HashiCorp Brand Kit

Slide 10

Slide 10 text

Azure Resource Manager Source: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/overview

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Create the Terraform files  main.tf  outputs.tf  providers.tf  terraform.tf  variables.tf

Slide 13

Slide 13 text

terraform.tf terraform { required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 2.65" } } } https://github.com/patkoch/terraform-azure-virtual-machine-linux/blob/main/terraform.tf

Slide 14

Slide 14 text

providers.tf provider "azurerm" { features {} } https://github.com/patkoch/terraform-azure-virtual-machine-linux/blob/main/providers.tf

Slide 15

Slide 15 text

outputs.tf output "virtual_machine_name" { value = azurerm_virtual_machine.example.name } https://github.com/patkoch/terraform-azure-virtual-machine-linux/blob/main/outputs.tf

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

variables.tf variable "virtual_machine_name" { type = string default = "glt-24" 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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Connect to the Ubuntu VM  chmod 600 id_rsa  ssh -i id_rsa adminuser@  ls –la  exit

Slide 20

Slide 20 text

Destroy the Virtual Machine  terraform destroy

Slide 21

Slide 21 text

Stop and destroy the Codespace

Slide 22

Slide 22 text

Thank you! :) Please provide a feedback! Connect via LinkedIn!