The Terraform Azure VM Automation project demonstrates how to automate the deployment of a virtual machine (VM) in Azure using Terraform. I aim to showcase Infrastructure as Code (IaC) principles and how to manage cloud resources efficiently. This configuration includes automated deployment scripts for now, Terraform configuration files, and examples of outputs for easy management and scalability of Azure resources.
Before using the Terraform configuration, ensure the following is installed:
- Terraform: Install Terraform
- Azure CLI: Install Azure CLI
- Git: Install Git
- PowerShell: Available by default on Windows; for other operating systems, download from Microsoft.
If you're new to Git, check out my Git guide. Visual Studio Code makes it easy to get started.
terraform-azure-vm-automation/
│
├── main.tf
├── variables.tf
├── outputs.tf
├── terraform.tfvars
├── git-init-push.ps1
├── tf-init-apply.ps1
├── tf-destroy.ps1
├── LICENSE
├── .gitignore
├── photos
│ ├── social_preview.jpg
│ ├── graph.png
│ ├── NetworkWatcherRG.png
└── README.md
This file contains the core configuration for provisioning resources in Azure. It includes the setup for the resource group, virtual network, subnet, network interface, and virtual machine.
This file defines the variables used in the Terraform configuration and uses terraform.tfvars
to specify values, making it easy to customize the deployment environment by changing variable values.
This file defines the outputs of the Terraform configuration, providing useful information about the deployed resources.
This script initializes a Git repository, adds a remote origin, commits changes, and pushes to the remote repository. The script works uninterrupted if the GitHub repository is already created and the script is updated accordingly.
Please refer my custom crafted how to git guide if you are a beginner.
This script initializes Terraform, validates the configuration, plans the deployment, and applies the changes. In addition, it takes a backup of the .tfstate and tfplan with an opportunity to creat the Graph.
This script destroys the Terraform-managed infrastructure. Except NetworkWatcherRG, please refer my Key Learnings here
Please visit the WIKI page.
- Disable Password Authentication: Update the
os_profile_linux_config
todisable_password_authentication = true
for better security and configure SSH keys for VM access. - Secret Management: Move sensitive information such as admin passwords to a secure secret management system like Azure Key Vault.
- Scalability: Enhance the configuration to support deployment of multiple VMs and additional Azure resources such as databases and load balancers.
- Load Balancer and CI/CD Integration
Feel free to fork this repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change. I have started a discussion, and everyone can bring ideas there.
Thanks to the Terraform and Azure documentation teams for their extensive resources and examples. This project was inspired from my previous role as IT Administrator and the need to automate and efficiently manage cloud infrastructure.