Terraform Cloud Shell development

Terraform works great from a Bash command line such as macOS Terminal or Bash on Windows or Linux. Running your Terraform configurations in the Bash experience of the Azure Cloud Shell has some unique advantages to speed up your development cycle.

This concepts article covers Cloud Shell features that help you write Terraform scripts that deploy to Azure.

Open Azure Cloud Shell

Azure Cloud Shell is a free, interactive shell that you can use to run the steps in this article. Common Azure tools are preinstalled and configured in Cloud Shell for you to use with your account. Just select the Copy button to copy the code, paste it in Cloud Shell, and then press Enter to run it. There are a few ways to open Cloud Shell:

Select Try It in the upper-right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser. https://shell.azure.com/bash
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell in the portal

Automatic credential configuration

Terraform is installed and immediately available in Cloud Shell. Terraform scripts authenticate with Azure when logged in to the Cloud Shell to manage infrastructure without any additional configuration. Automatic authentication bypasses the need to manually create an Active Directory service principal and configure the Azure Terraform provider variables.

Using Modules and Providers

Azure Terraform modules require credentials to access and make changes to the resources in your Azure subscription. When working in the Cloud Shell, add the following code to your scripts to use Azure Terraform modules in the Cloud Shell:

# Configure the Microsoft Azure Provider
provider "azurerm" {
}

The Cloud Shell passes required values for the azurerm provider through environment variables when using any of the terraform CLI commands.

Other Cloud Shell developer tools

Files and shell states persist in Azure Storage between Cloud Shell sessions. Use Azure Storage Explorer to copy and upload files to the Cloud Shell from your local computer.

The Azure CLI is available in the Cloud Shell and is a great tool for testing configurations and checking your work after a terraform apply or terraform destroy completes.

Next steps

Create a small VM cluster using the Module Registry Create a small VM cluster using custom HCL