For this project, you will write a Packer template and a Terraform template to deploy a customizable, scalable web server in Azure.
-
Clone this repository
-
Create your infrastructure as code
-
Update this README to reflect how someone would use your code.
- Create an Azure Account
- Install the Azure command line interface
- Install Packer
- Install Terraform
2.2. ✔️ Authenticate to Azure the open Azure portal Bash Cloud Shell to upload project1-tagging-policy.json
Create the Policy Definition:
az policy definition create --name 'tagging-policy' --display-name 'deny-creation-untagged-resources' --description 'This policy ensures all indexed resources in your subscription have tags and deny deployment if they do not' --rules ./project1-tagging-policy.json --mode All
az policy assignment create --name 'tagging-policy' --display-name 'deny-creation-untagged-resources' --policy tagging-policy
az policy assignment list
✔️ Open Azure portal Bash Cloud Shell then upload server.json
✔️ Create a Server Image using below packer command
packer build server.json
✔️ View Images
az image list
Go to folder cd project1-IaC/
Our Terraform template will allow us to reliably create, update, and destroy our infrastructure
Customize vars.tf
Variables from vars.tf are called from mains.tf, for example the variable prefix is called as:
${var.prefix}
In vars.tf, the description and value is assigned in the following manner:
variable "prefix" {
description = "The prefix which should be used for all resources in this example"
default = "quyetnn-project1"
}
See all variable in vars.tf
- Initializing Working Directories
terraform init
- Create infrastructure plan
terraform plan -out solution.plan
- Deploy the infrastructure plan
terraform apply "solution.plan"
- View infrastructure
terraform show
Azure Portal Azuredevops resource created by terraform ✔️ View in Azure Portal
- Destroy infrastructure (when completed) using
clean_resources.sh
to delete all resources except Azuredevops resource group
terraform state list | while read line
do
if [[ $line == azurerm_resource_group* ]]; then
echo $line " is a resource group and will not be deleted!"
else
echo "deleting: " $line
terraform destroy -target $line -auto-approve
fi
done
Using terraform state list
command to skip destroying azurerm_resource_group which lab user can not delete it.
- Delete images(when completed)
az image delete -g Azuredevops -n MyPackerImage
az policy assignment list
az image list
terraform plan -out solution.plan
terraform apply "solution.plan"
terraform show