Skip to content

binario200/my-terraform-azure-journey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Managing Azure Infrastructure with Terraform

Here I will share my learnings using Terraform at Microsoft Azure.

After installing Terraform the next step is configuring the Terraform access to Azure (you will need azure subscription)

Also you I will be using Azure CLI command, you can fins how to install the Azure CLI here

Configure Terraform access to Azure

To enable Terraform to provision resources into Azure, create an Azure AD service principal. The service principal grants your Terraform scripts to provision resources in your Azure subscription.

Having installed your Azure CLI and subscription, loging to you Azure account from your terminal:

az login

If you find connecting issues with your corporate proxy try any of these solutions or [this] (https://blog.jhnr.ch/2017/09/24/use-azure-cli-with-corporate-proxy-server/)

Query the information of you azure subscription

az account list --query "[].{name:name, subscriptionId:id, tenantId:tenantId}"

Set your subscription for you azure cli session

export SUBSCRIPTION_ID=$(az account list --query "[].{subscriptionId:id}")

az account set --subscription="${SUBSCRIPTION_ID}"

Now create the Azure AD service principal

az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${SUBSCRIPTION_ID}"

Your appId, password, sp_name, and tenant are returned. Make a note of the appId and password.

Configure Terraform environment variables

To configure Terraform to use your Azure AD service principal, set the following environment variables, which are then used by the Azure Terraform modules.

export ARM_SUBSCRIPTION_ID=your_subscription_id
export ARM_CLIENT_ID=your_appId
export ARM_CLIENT_SECRET=your_password
export ARM_TENANT_ID=your_tenant_id

Running a test

Continuing at your azure cli session, use the test.tf file and run the Terraform commands. the test.tf will download the azure terraform provider and then it will create a resource group at your subscription.

terraform init
terraform apply

You can apply the terraform destroy command to remove your test resource grupo with terraform.

terraform destroy

About

Terraform recipes to configure and manage infrastructure at Azure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published