🚀 Deploy Azure Virtual Machines with Terraform
This Terraform project automates the deployment of Azure resources including a Virtual Network, Subnet, Network Security Group, and Linux Virtual Machines.
Before you begin, ensure you have the following installed and set up:
-
Terraform: Install Terraform by following the official installation guide.
-
Azure CLI: Configure Azure CLI and authenticate by running
az login
. Make sure your account has the necessary permissions to create Azure resources. -
SSH Key Pair: Generate an SSH key pair if you haven't already. You will need the public key (
id_rsa.pub
) for SSH access to the virtual machines.
-
Clone the Repository:
git clone <repository-url> cd <repository-name>
-
Initialize Terraform:
terraform init
-
Set Terraform Variables:
Copy the
terraform.tfvars.example
file toterraform.tfvars
and adjust the variables as per your environment:cp terraform.tfvars.example terraform.tfvars
Modify
terraform.tfvars
to set yourprefix
,location
,nodecount
,username
,password
, and any other required variables. -
Review Terraform Plan:
terraform plan
This command shows you what Terraform will do when you apply your configuration.
-
Apply Terraform Configuration:
terraform apply
Review the plan and type
yes
to apply the configuration and provision Azure resources. -
Accessing Virtual Machines:
Once deployed, Terraform will output information about the deployed resources, including public IP addresses of the virtual machines. Use SSH to connect:
ssh <username>@<public-ip-address>
Replace
<username>
with your specified admin username and<public-ip-address>
with the actual IP.
To avoid unnecessary charges, destroy the Terraform-managed infrastructure when no longer needed:
terraform destroy
Type yes
to confirm destruction.
-
Ansible: This configuration installs Ansible on the deployed virtual machines using remote-exec provisioner. Ensure your local machine has Ansible installed if you plan to manage these VMs using Ansible scripts.
-
Customization: Feel free to modify variables or add more resources in
main.tf
as per your project requirements.
Feel free to use this code and add more to it. Happy deploying! 🌟