Terraform with Azure:
Hashicorp Terraform is an open-source tool for provisioning and managing cloud infrastructure. It codifies infrastructure in configuration files that describe the topology of cloud resources. These resources include virtual machines, storage accounts, and networking interfaces. The Terraform CLI provides a simple mechanism to deploy and version the configuration files to Azure.
Automate infrastructure management:
Terraform’s template-based configuration files enable you to define, provision, and configure Azure resources in a repeatable and predictable manner. Automating infrastructure has several benefits:
- Lowers the potential for human errors while deploying and managing infrastructure.
- Deploys the same template multiple times to create identical development, test, and production environments.
- Reduces the cost of development and test environments by creating them on-demand.
Understand infrastructure changes before being applied:
As a resource topology becomes complex, understanding the meaning and impact of infrastructure changes can be difficult.
The Terraform CLI enables users to validate and preview infrastructure changes before application. Previewing infrastructure changes in a safe manner has several benefits:
- Team members can collaborate more effectively by quickly understanding proposed changes and their impact.
- Unintended changes can be caught early in the development process
Getting started with Terraform using Azure Cloud Shell:
Terraform enables the definition, preview, and deployment of cloud infrastructure. Using Terraform, you create configuration files using HCL syntax. The HCL syntax allows you to specify the cloud provider – such as Azure – and the elements that make up your cloud infrastructure. After you create your configuration files, you create an execution plan that allows you to preview your infrastructure changes before they’re deployed. Once you verify the changes, you apply the execution plan to deploy the infrastructure.
Create a Terraform configuration file:
1. Create a directory to hold the Terraform files
mkdir QuickstartTerraformTest
2. Change directories to the demo directory.
cd QuickstartTerraformTest
3. Using your favorite editor, create a Terraform configuration file.
code QuickstartTerraformTest.tf
4. Paste the following HCL into the new file.
provider “azurerm” {
# The “feature” block is required for AzureRM provider 2.x.
# If you are using version 1.x, the “features” block is not allowed.
version = “~>2.0”
features {} }
resource “azurerm_resource_group” “rg” {
name = “QuickstartTerraformTest-rg”
location = “eastus”
}
Delete the resources:
1. Run the terraform destroy that will reverse the current execution plan.
terraform destroy
2. Terraform shows you what will happen if you reverse the execution plan and requires you to confirm. Confirm by entering yes and pressing the Enter key.
3. Once you confirm the execution of the play, the output is similar to the following example, verify that the resource group was deleted by using
az group show
az group show -n “QuickstartTerraformTest-rg”

Leave a comment