Thursday, April 21, 2022

Infrastructure as Code (IaC) Session 1: Basics

 What is Infrastructure as  Code?


Prepare Workspace

  1. Install
    1. Terraform: (https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/azure-get-started)
    2. Azure CLI: open PowerShell as administrator
      $ Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
    3. Visual Studio Code
      1. Terraform by HashiCorp
      2. Azure Terraform by Microsoft
      3. Azure Cloudshell (Powershell)
      4. Azure CLI tools
  2. Activate Azure Account
Create or open a project folder. Open the folder in VSCode. Create a file named main.tf.
Open a powershell terminal and issue:
$ az login
Paste the following to the main.tf file:
provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "aingelrg1" {
  name     = "Session1"
  location = "southeastasia"
}

On the terminal, follow through each of the commands
$ terraform init
Initialize terraform and check dependencies

$ terraform plan
Simulate what needs to happen in Azure

$ terraform apply
Execute the instruction in Azure. You need to type "yes" to confirm the execution.

$ terraform show

$ terraform destroy
Delete from Azure

You can checkout some samples at the following Git Repos:
https://github.com/hashicorp/terraform-provider-azurerm/tree/main/examples
https://github.com/aingelc12ell/jaira-terraform-azure/



No comments:

Post a Comment