Provision a Virtual Machine and its related resources on the Azure platform using Terraform as your Infrastructure-as-Code (IaC) tool.
- terraform.yml: Automates CI/CD pipeline—runs
terraform init,validate,plan, andapplyto provision resources based onmain.tf.
- terraform.tfvars enables deploying across multiple environments (e.g., dev, test, prod).
- backend.tf: Configures remote state storage by creating a new Resource Group, ensuring:
- Secure state storage off local runners
- Safe collaboration with state locking
- Versioning of infrastructure changes
Important
Note: Run backend.ps1 before initializing Terraform to provision backend storage resources.
Retrieve your VM’s (Ubuntu) public IP:
az vm list-ip-addresses --resource-group <RESOURCE_GROUP_NAME> --name <VM_NAME> --query "[].virtualMachine.network.publicIpAddresses[0].ipAddress" --output tsvConnect via SSH:
ssh <username>@<IP_ADDRESS>Install Graphviz locally via Homebrew:
brew install graphviz
dot -V # verify it by running- In your terminal, navigate to the directory containing your Terraform configuration files.
- Run
terraform initto initialize the configuration. - Run
terraform plan -out=plan.outto create a plan. - Run
terraform graph -plan=plan.out | dot -Tsvg > graph.svgto generate an SVG file of your Terraform plan.
Open the graph.svg file in Visual Studio Code to view the visual representation of your Terraform resources and their dependencies.
These are insights and resolutions gathered during the development of this Terraform-based Azure VM automation project:
-
network_interface_name
Referencing a map ({}) directly caused issues; resolved by extracting the value into a separate variable. -
network_interface_ids
Required alist(string)format. Ensured correct passing by inserting as an array[]. -
azurerm_virtual_networkDependency
The virtual network was prematurely initialized before the resource group. Added adepends_onclause to enforce creation order and avoid failures. -
Automatic Creation of
NetworkWatcherRG
Azure auto-generates a resource group namedNetworkWatcherRGafter deploying networking components like VNET, SUBNET, and NI. This group is part of Azure's free network monitoring and can be manually deleted or disabled per region if desired.
- Terraform Documentation
- Azure Documentation
- PowerShell: PowerShell file used to centralize terraform commands related to this project.
- GitHub: Platform for version control and collaboration.
backend.ps1- Reference: Microsoft Reactor Series
Contributions are welcome! Feel free to fork this repository and submit a pull request (PR).
- For major changes, please open an issue first to discuss your ideas and ensure alignment.
- There’s an open discussion thread where everyone can share improvements, feedback, and use cases. Jump in!
💡 Whether it's refactoring code, improving documentation, or sharing deployment tips—every contribution helps!
