Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform + Azure Infrastructure

A workshop project for deploying a Linux virtual machine on Microsoft Azure using Terraform. Covers networking, security groups, SSH access, and infrastructure lifecycle management.


Prerequisites

  • Terraform v4.4.0 or later
  • Azure CLI (latest)
  • An Azure account with an active subscription
  • SSH client

Getting Started

1. Authenticate with Azure

az login
az account set --subscription "Azure for Students"
az account show --output table

2. Generate SSH Keys

If you don't already have an SSH key pair:

ssh-keygen -t ed25519 -C "your-email@example.com"

3. Clone and configure

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"

Project Structure

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

Usage

# 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

What Gets Deployed

  • 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)

Connecting to the VM

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>

VM Size Reference

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.


Troubleshooting

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_ed25519

QuotaExceeded - Switch to a smaller VM size or delete unused resources. Check quota with:

az vm list-usage --location "West Europe" --output table

Provider not registered - Register the required namespaces:

az provider register --namespace Microsoft.Compute
az provider register --namespace Microsoft.Network

Security Notes

  • SSH key authentication is enforced; password authentication is disabled on the VM.
  • The NSG currently allows SSH from any source IP (*). For production use, restrict source_address_prefix to your IP range.
  • terraform.tfvars and 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).

References


About

Infrastructure as Code project using Terraform to deploy Azure VM with networking resources.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages