USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll BooksAzure Cloud Book
HomeAzure BookInfrastructure and Delivery
PreviousAzure Bicep and ARM from Zero: Repeatable InfrastructureNextGitHub Actions and Azure DevOps CI/CD for Azure
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

11 sections

Progress0%
1 / 11

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Terraform on Azure: Providers, Modules, Remote State, Plans, Imports, and Drift

Terraform is declarative infrastructure as code that compares configuration, state, and provider APIs to produce a plan. The AzureRM provider offers modeled Azure resources; the AzAPI provider can reach newer ARM resource types. Terraform state maps configuration to real objects and can contain sensitive values, so it is critical production data.

Lab: 45 minutes · Cost: Terraform has no Azure charge; its state storage and managed resources can charge · Never: commit state or plan files to Git.

Method note: This chapter deliberately teaches Terraform's stateful workflow as one tool rather than presenting Portal or Bicep as equivalent steps. Use the preceding Bicep chapter for the Azure-native declarative path and the service chapters for Portal and command-line alternatives.

What is a safe project structure?

text
infra/ modules/ app-platform/ live/ dev/ main.tf providers.tf variables.tf outputs.tf prod/

Keep modules focused and versioned. Separate state by environment and blast radius. A single state for an entire enterprise creates slow plans, excessive privilege, and risky coupling.

What is the basic Azure configuration?

hcl
terraform { required_version = ">= 1.8.0" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "this" { name = "rg-northstar-tf-dev-001" location = "East US" tags = { environment = "dev" workload = "northstar" } }

The example constraint is a starting pattern, not a promise about the current newest version. Commit .terraform.lock.hcl, review provider upgrades, and test them.

How do you run the Terraform workflow?

bash
terraform fmt -check -recursive terraform init terraform validate terraform plan -out=planned-change.tfplan terraform show planned-change.tfplan terraform apply planned-change.tfplan

Saved plans can contain sensitive values and become stale. Protect and delete them under your pipeline's artifact policy. Do not apply a plan built for a different commit or environment.

How do you store state remotely?

Use an Azure Storage backend with private access, encryption, soft delete/versioning as appropriate, restricted RBAC, and monitoring. Bootstrap it through a separate controlled process because Terraform cannot use a backend that does not yet exist.

hcl
terraform { backend "azurerm" { resource_group_name = "rg-terraform-state-prod" storage_account_name = "REPLACE_STATE_ACCOUNT" container_name = "tfstate" key = "northstar/dev.tfstate" use_azuread_auth = true } }

Use workload identity in CI. Do not supply storage access keys. Azure Blob leases provide state locking behavior; investigate and resolve a lock rather than force-unlocking blindly.

What is AzAPI for?

Use AzAPI when Azure exposes an ARM resource/property before AzureRM models it. Pin the resource API version, validate schema, write tests, and plan migration to AzureRM if it later gains support. AzAPI is not permission to deploy unreviewed preview features.

How do imports and refactors stay safe?

Use import blocks or terraform import to associate existing resources after configuration is written. The first plan should show no unexpected mutation. Use moved blocks when renaming resources/modules so Terraform changes addresses without destroying the real object.

Never “fix” drift by deleting state entries until you understand who owns the resource and what the next plan will do.

How do you handle secrets and outputs?

sensitive = true hides normal CLI display; it does not remove the value from state. Prefer managed identity and Key Vault references. Restrict state readers. Avoid data sources that pull secret material into state. Mark outputs sensitive and publish only necessary non-secret deployment outputs.

What belongs in CI/CD?

  • fmt, validate, static security/policy checks.
  • Provider lock verification.
  • Plan using a least-privilege federated identity.
  • Human review of production plan.
  • Apply the exact approved plan.
  • Post-deployment tests and state backup controls.
  • Scheduled drift detection with owned remediation.

Cleanup

Run terraform plan -destroy, review it, then terraform destroy only for the isolated lab. Confirm separately managed state storage remains intact. Do not destroy shared backend or networking from an application stack.

Official references

  • Terraform on Azure
  • AzureRM provider
  • AzAPI provider
  • AzureRM backend