Skip to content
Get Started for Free

Terraform

Terraform is an Infrastructure-as-Code (IaC) tool that can deploy your full infrastructure with a few simple commands, in a reproducible manner. This guide will show you how to use it with LocalStack.

This guide is designed for users who are new to LocalStack for Azure emulator and assumes basic knowledge of how Terraform works. We will demonstrate how to create an Azure resource group using Terraform.

Create the following two files:

A Terraform template with the provider information called provider.tf:

Terminal window
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=4.14.0"
}
}
}
provider "azurerm" {
features {}
subscription_id = "00000000-0000-0000-0000-000000000000"
metadata_host="localhost.localstack.cloud:4566"
}

Please note the metadata_host attribute! This is essential to ensure that the infrastructure is deployed to the LocalStack Emulator, instead of to the real cloud.

A Terraform file that contains the resource group information called main.tf:

Terminal window
resource "random_uuid" "uuid" {}
resource "azurerm_resource_group" "rg" {
name = "rg-hello-tf-${random_uuid.uuid.result}"
location = "westeurope"
}

You can now use Terraform like you would normally.

First initialize the repository, and download the specified provider:

terraform init

Second, apply (create) the specified resources:

terraform apply

The terraform tool will now create the resource group.

If you’ve followed our guide on how to configure the az CLI tool to point to LocalStack, you can verify that the resource exist by using the az tool:

Terminal window
az group list
Was this page helpful?