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
- Create a resource group (if not existed) in which the image will be deployed by azure cli:
IMAGE_LOCATION="East US"
RESOURCE_GROUP="packer-rg"
az group create --location "$IMAGE_LOCATION" \
--name "$RESOURCE_GROUP" \
--tags 'environment=dev'- Create a service prinpal by running the following commands from azure cli:
let "randomIdentifier=$RANDOM*$RANDOM"
servicePrincipalName="msdocs-sp-$randomIdentifier"
roleName="Contributor"
subscriptionID=$(az account show --query id -o tsv)
# Verify the ID of the active subscription
echo "Using subscription ID $subscriptionID"
RESOURCE_GROUP="packer-rg"
echo "Creating SP for RBAC with name $servicePrincipalName, with role $roleName and in scopes /subscriptions/$subscriptionID/resourceGroups/$RESOURCE_GROUP"
az ad sp create-for-rbac --name $servicePrincipalName --role $roleName --scopes /subscriptions/$subscriptionID/resourceGroups/$RESOURCE_GROUP - Capture the output from the above commands
{
"appId": "***",
"displayName": "msdocs-sp-110966904",
"password": "PasswordOfTheApp",
"tenant": "tenantID"
}-
Change variables in the file server.json
- Change client_id variable with appId value
- Change client_secret variable with password value
- Change subscription_id variable with yout subscritopn id
-
Running the following command to create image:
packer build server.json- Change variables in file vars.tf as needed
- Replace your public key by change the content of file id_rsa.pub
- Running the following commands to deploy infrastructure
terraform plan -out solution.plan
terraform apply solution.plan- The output after running terraform apply
Outputs:
public_ip_address = [
"20.232.162.79",
]
vmss_public_ip_fqdn = "cdtkpp.eastus.cloudapp.azure.com"- Running the following command to see the whole output of the deployment
terraform show