Terraform - Azure
Azure Terraform Example
Section titled “Azure Terraform Example”az login# set to ADDS DEV Azure subscription azrdevod0156wrkaz account set --subscription "my-sub-id"
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/my-subscription-id"Creating 'Contributor' role assignment under scope '/subscriptions/my-subscription-id'
# Need this information for Terraform set upCreating 'Contributor' role assignment under scope '/subscriptions/...'The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli{ "appId": "xxxxxx-xxx-xxxx-xxxx-xxxxxxxxxx", "displayName": "azure-cli-2022-xxxx", "password": "xxxxxx~xxxxxx~xxxxx", "tenant": "xxxxx-xxxx-xxxxx-xxxx-xxxxx"}
# Create a Terraform configuration file in the current directory# hconfig.tf see below
# Initilize the terraform projectterraform init
# Format and validate the configurationterraform fmtterraform validate
# Plan changes and output to a planterraform plan -out=tplan
# Apply the planterraform apply tplan
# Inspect stateterraform show
# See state file and list resourcesterraform state list
# We strongly recommend using the required_providers block to set the# Azure Provider source and version being used# Configure the Azure providerterraform { required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 3.0.2" } }
required_version = ">= 1.1.0"}
# Configure the Provider for Microsoft Azureprovider "azurerm" { features {}
subscription_id = "my-subscription-id"}
resource "azurerm_resource_group" "rg" { name = "myterraformtestrg" location = "canadacentral"}
>