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.

Use Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. Cloud Shell lets you use either bash or PowerShell to work with Azure services. You can use the Cloud Shell pre-installed commands to run the code in this article without having to install anything on your local environment.

To launch Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell. Example of Try It for Azure Cloud Shell
Go to https://shell.azure.com or select the Launch Cloud Shell button to open Cloud Shell in your browser. Launch Cloud Shell in a new window
Select the Cloud Shell button on the top-right menu bar in the Azure portal. Cloud Shell button in the Azure portal

To run the code in this article in Azure Cloud Shell:

  1. Launch Cloud Shell.

  2. Select the Copy button on a code block to copy the code.

  3. Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.

  4. Press Enter to run the code.

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