A workshop project for deploying a Linux virtual machine on Microsoft Azure using Terraform. Covers networking, security groups, SSH access, and infrastructure lifecycle management.
- Terraform v4.4.0 or later
- Azure CLI (latest)
- An Azure account with an active subscription
- SSH client
az login
az account set --subscription "Azure for Students"
az account show --output tableIf you don't already have an SSH key pair:
ssh-keygen -t ed25519 -C "your-email@example.com"Copy terraform.tfvars.example to terraform.tfvars and fill in your values:
prefix = "demo"
location = "West Europe"
vm_size = "Standard_B1s"
admin_username = "adminuser"
ssh_key_path = "~/.ssh/id_ed25519.pub"terraform-azure-demo/
├── main.tf # Core infrastructure resources
├── variables.tf # Variable declarations
├── terraform.tfvars # Your variable values (excluded from version control)
├── outputs.tf # Output values displayed after deployment
└── .gitignore
# Initialize the working directory (run once)
terraform init
# Format and validate
terraform fmt
terraform validate
# Preview changes
terraform plan
# Deploy
terraform apply
# Tear down all resources
terraform destroy- Resource Group
- Virtual Network and Subnet
- Network Interface
- Public IP Address (static)
- Network Security Group (SSH on port 22)
- Ubuntu 22.04 LTS Virtual Machine (
Standard_B1s)
After a successful apply, Terraform outputs the SSH command:
ssh adminuser@<PUBLIC_IP>To specify a key path explicitly:
ssh -i ~/.ssh/id_ed25519 adminuser@<PUBLIC_IP>| Size | vCPUs | RAM | Approx. Cost | Notes |
|---|---|---|---|---|
| Standard_B1ls | 1 | 0.5 GB | ~$4/mo | Minimal, testing only |
| Standard_B1s | 1 | 1 GB | ~$8/mo | Recommended for dev/learning |
| Standard_F2 | 2 | 4 GB | ~$70/mo | Compute-optimized, higher cost |
Standard_B1s is the recommended choice for student subscriptions.
Authentication error - Re-run az login and verify the correct subscription is active.
SSH connection timeout - Check that the NSG allows inbound TCP on port 22 from your IP. Verify the VM is in a running state with az vm list --show-details --output table.
Permission denied (SSH) - Ensure key permissions are set correctly:
chmod 600 ~/.ssh/id_ed25519QuotaExceeded - Switch to a smaller VM size or delete unused resources. Check quota with:
az vm list-usage --location "West Europe" --output tableProvider not registered - Register the required namespaces:
az provider register --namespace Microsoft.Compute
az provider register --namespace Microsoft.Network- SSH key authentication is enforced; password authentication is disabled on the VM.
- The NSG currently allows SSH from any source IP (
*). For production use, restrictsource_address_prefixto your IP range. terraform.tfvarsand state files are excluded from version control via.gitignore. Do not commit them.- For team environments, use remote state storage (Azure Storage Account or Terraform Cloud).
- Terraform AzureRM Provider Docs
- Azure CLI Reference
- Terraform Learning Tutorials
- Azure Architecture Center