This project uses a Packer template and a Terraform template to deploy a customizable and scalable web server in Azure
-
Clone this repository
-
Information about files
- tagging-policy-rule.json -> contains azure policy rule - server.json -> contains packer template to create linux image - main.tf and vars.tf -> contains terraform templates to create webserver - init.sh -> script that sets environment variables
- Create an Azure Account
- Install Git Bash
- Install the Azure command line interface
- Install Packer
- Install Terraform
-
Use init.sh to set environment variables for azure authentication
source init.sh
-
Login to Azure
az login --service-principal -u $TF_VAR_ARM_client_id -p $TF_VAR_ARM_client_secret --tenant $TF_VAR_ARM_tenant_id
-
Set the subscription
az account set --subscription $TF_VAR_ARM_subscription_id
-
Create resource group for server image and infrustructure resources
az group create --name $TF_VAR_ARM_resource_group --location eastus
-
Create policy definition
az policy definition create --name "tagging-policy-definition" --rules "tagging-policy-rule.json" --display-name "Deny creation of resources without tags" --description "This policy denies creation of a resources if that do not have tags" --subscription $TF_VAR_ARM_subscription_id --mode Indexed
-
Assign policy
az policy assignment create --name "tagging-policy" --policy "tagging-policy-definition"
-
Verify policy
az policy assignment list
-
Initialize terraform
terraform init
-
Change default value of vars.tf file according to your requirement
-
Plan infrastructure deployment
terraform plan -out solution.plan
Check this image for full output of solution.plan
-
Deploy infrastructure
terraform apply solution.plan
-
Get the public address and port to access the webserver
az network public-ip list -g $TF_VAR_ARM_resource_group -o table az network lb inbound-nat-rule list -g $TF_VAR_ARM_resource_group --lb-name "udacity-web-server-lb" -o table
-
Access web server using <Address>:<FrontendPort>
Use "terraform destroy" command to destroy the infrastructure