This repository contains Terraform code to deploy Azure Virtual Machines (VMs) in a private subnet behind a load balancer, with SSH access through a bastion host.
Before you begin, ensure you have the following:
- Azure subscription
- Terraform installed (version >= x.x.x)
- Azure CLI installed (for managing Azure resources)
-
Clone this repository:
git clone https://github.com/your-repo-name.git
-
Navigate to the cloned directory:
cd your-repo-name -
Initialize Terraform:
terraform init
-
Create a
terraform.tfvarsfile with the required variables. Here's an example:web_linuxvm_instance_count = 2
Adjust the value of
web_linuxvm_instance_countas needed. -
Review and adjust the
variables.tffile to configure other settings as per your requirements. -
Review and adjust the
main.tffile to customize resource names, sizes, etc., according to your preferences. -
Apply the Terraform configuration:
terraform apply
This will create the Azure resources based on the specified configuration.
To access the VMs via SSH, you'll need to connect through the bastion host. Here's how:
-
Get the public IP address of the bastion host from the Azure Portal or using the Azure CLI.
-
SSH into the bastion host:
ssh username@bastion-public-ip
-
Once connected to the bastion host, SSH into the desired VM(s) within the private subnet:
ssh username@private-vm-ip
Replace
usernamewith your username andprivate-vm-ipwith the private IP address of the VM you want to connect to.
To avoid incurring costs, ensure to destroy the created Azure resources when they are no longer needed:
terraform destroyThis project is licensed under the MIT License - see the LICENSE file for details.