Solve: Testing Azure Blob in LocalStack...And What to Do When Terraform Fails


Solve: Testing Azure Blob in LocalStack...And What to Do When Terraform Fails







Detailed Steps

Step 1: Create a Python virtual environment (Terminal #1) 

bash
python3 -m venv ~/envs/azure-localstack 
source ~/envs/azure-localstack/bin/activate

Creates an isolated environment for Python testing.


Step 2: Install required Python packages (Terminal #1) 

bash
pip install boto3 requests 

We’ll use these to talk to the LocalStack Blob backend.


Step 3: Start LocalStack with Azure + S3 enabled (Terminal #1) 

bash
docker run -it -p 4566:4566 -e SERVICES=azure,s3 localstack/localstack

Keeps running — leave this Terminal #1 open.


Step 4: Open a new terminal and activate Python environment (Terminal #2) 

bash
source ~/envs/azure-localstack/bin/activate

Then check LocalStack status: 

bash
curl http://localhost:4566/_localstack/health

Confirms that s3 and azure services are running.


Step 5: Create a test script to upload and retrieve a blob (Terminal #2) 

bash
nano azure_blob_test.py


Paste this: 

python
import boto3

s3 = boto3.client("s3", endpoint_url="http://localhost:4566",
                  aws_access_key_id="test", aws_secret_access_key="test", region_name="us-east-1")

s3.create_bucket(Bucket="azure-test-container")
s3.put_object(Bucket="azure-test-container", Key="hello.txt", Body="Hello from Azure test")

resp = s3.get_object(Bucket="azure-test-container", Key="hello.txt")
print(resp["Body"].read().decode())


Run it: 

bash
python azure_blob_test.py


🟢 Should print: 

bash
Hello from Azure test

This confirms blob emulation is working via LocalStack’s S3 backend.


Step 6: Install Terraform 1.8.x (Terminal #2) 

bash
sudo apt-get remove terraform
curl -O https://releases.hashicorp.com/terraform/1.8.5/terraform_1.8.5_linux_amd64.zip
unzip terraform_1.8.5_linux_amd64.zip
sudo mv terraform /usr/local/bin/


Upgrades to a Terraform version compatible with current providers.


Step 7: Attempt Azure provisioning with Terraform (Terminal #2) 

bash
mkdir ~/azure-localstack-tf && cd ~/azure-localstack-tf
nano main.tf


Paste this sample Azure Blob config into main.tf:

hcl
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.75"
    }
  }

  required_version = ">= 1.3.0"
}

provider "azurerm" {
  features {}
  skip_provider_registration = true

  client_id       = "test"
  client_secret   = "test"
  tenant_id       = "test"
  subscription_id = "test"
}

resource "azurerm_resource_group" "localstack_rg" {
  name     = "localstack-rg"
  location = "eastus"
}

resource "azurerm_storage_account" "example" {
  name                     = "azurestoragetest"
  resource_group_name      = azurerm_resource_group.localstack_rg.name
  location                 = azurerm_resource_group.localstack_rg.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_container" "example" {
  name                  = "testcontainer"
  storage_account_name  = azurerm_storage_account.example.name
  container_access_type = "private"
}


Then run: 

bash
terraform init
terraform plan


You’ll see this error: 

bash
Error: building account: ... Specified tenant identifier 'test' is neither a valid DNS name...


🟥 Showstopper: The azurerm provider tries to talk to real Azure and cannot be redirected to LocalStack — despite what the docs suggest.


Step 8: Workaround — Use S3 to Simulate Azure Blob (Terminal #2) 

bash
mkdir ~/azure-s3-workaround && cd ~/azure-s3-workaround
nano main.tf


Paste: 

hcl
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
  required_version = ">= 1.3.0"
}

provider "aws" {
  region                      = "us-east-1"
  access_key                  = "test"
  secret_key                  = "test"
  s3_use_path_style           = true
  skip_credentials_validation = true
  skip_requesting_account_id = true

  endpoints {
    s3 = "http://localhost:4566"
  }
}

resource "aws_s3_bucket" "blob_container" {
  bucket = "azure-simulated-container"
}


Then run: 

bash
terraform init
terraform apply -auto-approve


✅ Terraform provisions the bucket locally. You now have a working simulation of Azure Blob.

You'll see:


bash
aws_s3_bucket.blob_container: Creating...
aws_s3_bucket.blob_container: Creation complete after 1s [id=azure-simulated-container]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.


* * *

Aaron Rose is a software engineer and technology writer.

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

Running AI Models on Raspberry Pi 5 (8GB RAM): What Works and What Doesn't