Using Locally with the HashiCorp Terraform AzureRM Provider

Preview

Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in

Using Locally with the HashiCorp Terraform AzureRM Provider

HashiCorp Terraform is an infrastructure as code tool which uses providers to interact with different clouds - and Locally supports the hashicorp/azurerm provider.

This guide was tested using the following versions of HashiCorp Terraform and the hashicorp/azurerm provider, but newer versions should work too:

  • terraform - v1.16.3
  • hashicorp/azurerm provider - v5.6.0

Provisioning a Resource Group

In this example we're going to provision a Resource Group within the First Subscription. We first need to define a provider block for the hashicorp/azurerm provider in a file named main.tf:

provider "azurerm" {
  features {}
}

Note that we haven't specified any credentials for the hashicorp/azurerm provider, as Locally will automatically configure the provider for you to run against Locally rather than Azure when you run locally run terraform [command].

Next we need to add the Terraform resource to provision a Resource Group - in this case with the name rg-from-terraform in the location berlin:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "rg-from-terraform"
  location = "berlin"
}

Now that we've created our Terraform configuration, we need to download the hashicorp/azurerm provider by running:

$ terraform init

If Locally isn't already running, we'll need to start it by running:

$ locally build

At which point we can deploy this Terraform configuration against Locally by running:

$ locally run terraform apply

Once that's applied, if we open the First Subscription within the Locally Dashboard, and view the Resource Groups then we should see our newly created Resource Group.

Next steps

If you have an existing Terraform configuration that already targets Azure and you'd like to point it at Locally, see the Existing AzureRM Configuration guide. To run terraform apply against Locally in your pipeline, see Using Locally in CI.

Should you encounter any issues, please take a look at the troubleshooting section.

You can find more examples of how to use HashiCorp Terraform with Locally in the Examples in the Documentation.

Preview

Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in

A local cloud for you and your agents.

Your Azure infrastructure, running on your machine. Deploy in seconds, break things freely, and ship to Azure when you're ready.