# Install on MAC OS
brew install hashicorp/tap/terraform
# Verify Terraform Version
terraform version
# To Upgrade on MAC OS
brew upgrade hashicorp/tap/terraform
# Verify Terraform Version
terraform version
# Verify Installation
terraform help
terraform help plan
# Enable Tab Completion
terraform -install-autocomplete
# AZ CLI Current Version (if installed)
az --version
# Install Azure CLI (if not installed)
brew update && brew install azure-cli
# Upgrade az cli version
az --version
brew upgrade azure-cli
[or]
az upgrade
az --version
# Azure CLI Login
az login
# List Subscriptions
az account list
# Set Specific Subscription (if we have multiple subscriptions)
az account set --subscription="SUBSCRIPTION_ID"
terraform init: Initialize a Terraform working directory
terraform plan: Generate and show an execution plan
terraform apply: Builds or changes infrastructure
# Change Directory to v2 folder
cd ../
cd v2-terraform-azurerm-resource-group
# Initialize Terraform
terraform init
# Validate terraform templates
terraform validate
# Dry run to see what resources gets created
terraform plan
# Create Resource Group in Azure
terraform apply
Verify if resource group created in Azure using Management Console
Step-05: Make changes to Resource Group and Deploy¶
Add tags to Resource Group as below
# Create a Azure Resource Group
resource "azurerm_resource_group" "aksdev" {
name = "aks-rg2-tf"
location = "Central US"
# Add Tags
tags = {
"environment" = "k8sdev"
}
}
Run terraform plan and apply
# Dry run to see what resources gets created
terraform plan
# Create Resource Group in Azure
terraform apply
Verify if resource group created in Azure using Management Console
Step-06: Modify Resource Group Name and Understand what happens¶
Change Resource Group name from aks-rg2-tf to aks-rg2-tf2 in main.tf
# Understand what happens with this change
terraform plan
# Apply changes
terraform apply
Verify if resource group with new name got re-created in Azure using Management Console
Step-07-04: Why you need to the execution in this order (refresh, plan, make a decision, apply) ?¶
There are changes happened in your infra manually and not via terraform.
Now decision to be made if you want those changes or not.
Choice-1: If you dont want those changes proceed with terraform apply so manual changes will be removed.
Choice-2: If you want those changes, refer terraform.tfstate file about changes and embed them in your terraform manifests (example: main.tf) and proceed with flow (referesh, plan, review execution plan and apply)
Step-07-05: I picked choice-2, so i will update the tags in main.tf¶
# Delete newly created Resource Group in Azure
terraform destroy
# Delete State (Deleting for github repo case for course purpose)
rm -rf .terraform
rm -rf terraform.tfstate