Here are several low‑cost or free patterns for “gluing” Terraform‑provisioned Azure VMs (or other compute) to a real configuration‑management (CM) workflow. Pick the one that best fits your OS, team skills and scale:
-
Pure‑Terraform + Azure VM Extensions
• Linux: use cloud‑init or Custom Script Extension
• Windows: use PowerShell DSC (push or pull via Azure Automation DSC) or Custom Script Extension
Pros
– No external CM server
– All in Azure, free to start (you pay only for the VM runtime)
Cons
– Limited idempotency and reporting
– Harder to share complex playbooks
Example (Linux Custom Script Extension):
resource "azurerm_virtual_machine_extension" "custom_script" {
name = "install-nginx"
virtual_machine_id = azurerm_linux_virtual_machine.web.id
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.1"
settings = <<SETTINGS
{
"fileUris": ["https://raw.githubusercontent.com/…/install-nginx.sh"],
"commandToExecute": "bash install-nginx.sh"
}
SETTINGS
}
-
Terraform + Ansible (or any SSH‑based CM)
• Spin up VMs with Terraform
• Use null_resource + provisioner "remote-exec" to invoke Ansible‑playbooks
• Or push inventory into AWX/Tower (AWX is open‑source/free)
Pros
– Battle‑tested idempotency, rolling updates, reporting
– Huge ecosystem of modules/roles
Cons
– You need an Ansible control‑host (can be your laptop + CI runner)
Quick sketch:
resource "null_resource" "config" {
count = length(azurerm_linux_virtual_machine.web.*.public_ip_address)
triggers = { host = azurerm_linux_virtual_machine.web[count.index].public_ip_address }
provisioner "remote-exec" {
inline = [
"ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i '${self.triggers.host},' site.yml --user azureuser"
]
}
}
-
Terraform + Chef/Puppet/SaltStack (open‑source editions)
• Stand up a small “master” on a low‑tier VM (B1s) or even local/dev machine
• Bootstrap agents via Terraform’s remote-exec or Custom Script Extensions
Pros
– Mature ecosystems for large fleets
Cons
– Higher operational overhead vs. Ansible
-
GitHub Actions / Azure DevOps Pipelines
• Use your IaC pipeline to run inline Bash/PowerShell or Ansible scripts against freshly created servers
• Free tiers:
– GitHub Actions: 2,000 CI minutes/month for private repos, unlimited for public
– Azure DevOps: first 5 users + 1 Microsoft‑hosted parallel job free
Pros
– No self‑hosted CM control‑plane
– Very easy integration with Terraform Cloud, Azure Key Vault, etc.
-
Packer + Golden Images
• Bake your VM image (Linux/Windows) with all config baked in
• Terraform just spins up “ready‑to‑go” images
Pros
– Super‑fast boot times, predictable state
Cons
– Extra build pipeline, image maintenance
-
Secrets & Remote State (bonus!)
• Use Terraform Cloud’s free tier for remote state & variable storage
• Or store remote state in an Azure Storage Account (you pay pennies/month)
• Keep secrets out of TF code—leverage:
– Azure Key Vault (free tier)
– HashiCorp Vault OSS (free)
– GitHub Actions secrets / Azure DevOps Secure Files