Back
Azure Managed Disk Terraform architecture diagram showing direct attachment to backend VMs without iSCSI

Creating Azure Managed Disks with Terraform/OpenTofu — and How It Differs from OCI

In this post, we’ll explore how to create and attach an Azure Managed Disk Terraform/OpenTofu, one of the simplest ways to automate storage provisioning in Azure. When you automate infrastructure across clouds, you quickly realize that “block storage” doesn’t mean the same thing everywhere.
In this post, we’ll explore how to create and attach an Azure Managed Disk with Terraform/OpenTofu, and how Azure’s approach to block storage differs from what you might know from Oracle Cloud Infrastructure (OCI).

If you haven’t seen the OCI version yet, check out my earlier post:
👉 Provisioning OCI Block Volumes with Terraform/OpenTofu

Step 1 – Defining the Azure Managed Disk with Terraform

Terraform makes it simple to define a managed disk and attach it to a virtual machine.
The concept feels similar to OCI’s block volume, but there’s one big difference — Azure skips the iSCSI handshake entirely.

resource "azurerm_managed_disk" "foggykitchen_backend_vm_data_disk" {
  name                 = "foggykitchen-data-disk"
  location             = azurerm_resource_group.foggykitchen.location
  resource_group_name  = azurerm_resource_group.foggykitchen.name
  storage_account_type = "Premium_LRS"
  create_option        = "Empty"
  disk_size_gb         = 50
}

resource "azurerm_virtual_machine_data_disk_attachment" "foggykitchen_backend_vm_attach" {
  managed_disk_id    = azurerm_managed_disk.foggykitchen_backend_vm_data_disk.id
  virtual_machine_id = azurerm_linux_virtual_machine.foggykitchen_backend_vm.id
  lun                = 0
  caching            = "ReadWrite"
}

Once this plan is applied, the disk is instantly visible inside the VM — no discovery, no iSCSI portal, no extra steps.
That’s where Azure’s storage abstraction really shows its strength.

This Azure Managed Disk Terraform configuration attaches storage directly to the backend VM — no iSCSI or discovery required.

Step 2 – No iSCSI, No Problem

In Azure, the story is refreshingly simple. Once the Managed Disk is attached, it’s instantly visible in the VM — no iSCSI target discovery, no additional provisioning scripts.

The hypervisor handles the block mapping automatically, so what took a few extra steps in OCI now happens silently under the hood. For most workloads, this means faster deployments and cleaner automation.

But it also hides the low-level storage layer — which, in multicloud scenarios, is exactly where you start seeing how different clouds think about the same problem.

For reference, you can always explore Microsoft’s official documentation here:
📘 Terraform AzureRM Managed Disk Resource

Figure 1. Azure Managed Disk attached directly to backend VMs — no iSCSI layer required.

Step 3 – Automating the Mount with Remote-Exec

Because the disk appears automatically, the only thing left is to prepare the filesystem and mount it.
For quick labs, I often use a simple remote-exec provisioner that partitions the disk, formats it, and ensures the mount persists after reboot.

provisioner "remote-exec" {
  inline = [
    "echo '== Creating /u01 and mounting /dev/sdc1'",
    "sudo parted /dev/sdc --script -- mklabel gpt",
    "sudo parted /dev/sdc --script -- mkpart primary ext4 0% 100%",
    "sudo mkfs.ext4 -F /dev/sdc1",
    "sudo mkdir -p /u01",
    "sudo mount /dev/sdc1 /u01",
    "echo '/dev/sdc1 /u01 ext4 defaults,noatime,_netdev 0 0' | sudo tee -a /etc/fstab"
  ]
}

This snippet works well for demonstrations, but in production you’d move this logic to cloud-init or systemd for idempotency and cleaner state management.
In the course, I show a full variant that uses UUID-based mounts, validation, and rollback logic.

Step 4 – From Azure to Multicloud Thinking

Once you understand how Azure Managed Disk Terraform automation works, comparing it with OCI becomes straightforward.
OCI gives you more control but requires more steps; Azure hides the complexity but limits the knobs you can turn.
When you combine both, you start to see what real multicloud engineering looks like. 

That’s exactly what we build inside the Multicloud Foundations course — deploying compute, storage, and networking in both OCI and Azure using the same Terraform/OpenTofu workflow.

👉 Explore Multicloud Foundations: Azure & OCI deployed with Terraform/OpenTofu

Read more about Azure & Terraform

👉 Azure VNet with Terraform

A foundational guide to creating Virtual Networks, subnets, and routing in Azure using Terraform. If you’re deploying Managed Disks as part of a larger compute architecture, this article helps you anchor them inside a clean and scalable network design.

👉 Azure Load Balancer with Terraform

A practical walkthrough of configuring Azure Load Balancer, backend pools, health probes, and traffic rules — essential when building HA architectures on top of VMs backed by Managed Disks. Perfect if you’re preparing a production-ready deployment.

👉 Azure Bastion with Terraform

Learn how to deploy Azure Bastion as a secure alternative to public SSH/RDP. Ideal when your VM workloads using Managed Disks live entirely inside private subnets and you want a managed, zero-public-IP access method.

👉 Azure File Storage NFS with Terraform

A deep dive into provisioning Premium FileStorage (NFS) with Private Endpoint and Network Rules. This is the natural next step if you need shared storage between multiple VMs or want to complement Managed Disks with flexible NFS mounts.

👉 OCI–Azure Interconnect with Terraform 

A multi-cloud tutorial showing how to connect Azure and OCI using ExpressRoute and FastConnect. Particularly useful if your architecture spans both clouds — for example, Azure compute using Managed Disks and OCI databases or persistence layers.

FoggyKitchen Takeaway

Azure abstracts the plumbing; OCI exposes it.
Neither is better — they just teach different lessons about how clouds work beneath the surface.
At FoggyKitchen, we don’t just automate — we cook our infrastructure, one Terraform recipe at a time.

Stay curious, keep experimenting, and remember:
☁️ the cloud may be abstract, but storage is always real.

Multicloud Azure OCI Terraform architecture diagram

Master Multicloud Automation with Terraform/OpenTofu

Learn how to deploy, connect, and automate complete environments across Azure and OCI — step by step, with reusable Terraform recipes and real cloud architectures.

🔒 Lifetime • ⏱️ Self-paced • 🧪 Real labs

Check also other courses:

Leave A Reply

🌍 Master the Multicloud Foundations with Terraform

Build your first production-ready multicloud architectures step by step. Learn how to connect Azure and OCI with Terraform/OpenTofu, and gain the practical skills that cloud engineers need for hybrid environments.

Multicloud Azure OCI Terraform architecture diagram