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
After cloning this project
Enter the Policy_folder using cd Udacity_Azure_Devops_Lab1/Policy_folder
You first have to create the policy using the command
az policy definition create --name tagging-policy --display-name 'Allow Tags' --description 'This policy makes sure that the indexed resources are not created without a tag --mode Indexed' --rules tagging-policy.json
Apply the policy to the subscription using
az policy assignment create --name tagging-policy --policy tagging-policy --scope /subscriptions/XXXX-XXXX-XXXX-XXXX
Note: Use your subscription id on the area marked XXXX-XXXX-XXXX-XXXX to apply the policy to your subscription
You should have a similar view as shown below
First, determine your service principle credentials by entering the following command to get your client_id and client_secret
az ad sp create-for-rbac --query "{ client_id: appId, client_secret: password }"
To get your subscription Id use:
az account show --query "{ subscription_id: id }"
Persist the values in the environment variable using:
export ARM_CLIENT_ID=XXXX-XXXX-XXXX-XXXX
export ARM_CLIENT_SECRET=XXXXXXXXXXXXXXXX
export ARM_SUBSCRIPTION_ID=XXXX-XXXX-XXXX-XXXX
To create a linux image using packer run the following command
packer build server.json
If your image creation was successful, you should have a simlar output as shown below.
- To create the resources, enter the terraform folder containing the main.tf and vars.tf.
cd Udacity_Azure_Devops_Lab1/Terraform_folder
- Plan the Terraform resource deployment with
terraform plan init
terraform plan -out solution.plan
From the vars.tf, the variables are defined to implement DRY. But also you have the option of entering the Prefix name for your resources and the number of VMs you want. the number of VMs is set to be at most 5. The prompt output is as shown below.
- create your resources with the command
terraform apply solution.plan
When the resources are created, you should have a similar view as shown below.