Terraform Functions - Part 2 - Count
In part two of this blog series we will take a look at the count function in Terraform and see how we can use this with a basic Azure Web App deployment. In a future blog we will explore how to use the count function in a more complex resource deployment.
In part one we cover an overview of the blog series and some pre-requisites you will need to get started when working through the deployment steps in this blog series, if you haven't seen this information please review this here before you get started with the steps below.
The count function is very useful for easily deploying multiple resources of the same type and configuration. For example, we may need a web farm and all the Virtual Machines need the same configuration, using the count function we can deploy the same resource multiple times and include the count number in the name so we deploy web1, web2, web3. We can also use the count function when deploying the related resources NICs, IP addresses, disks etc. We can easily change this count number to scale up or down the number of resources deployed.
In our example we use Web Apps as they are quick to deploy. We will deploy one Application Service plan and as many Web Applications as determined by the count variable.
- Review the code in \app-service-count-demo\variables.tf
- This is where we set the webappcount variable which is currently set to 1
- Review the code in \app-service-count-demo\main.tf
- Under resource azurerm_app_service is where we set the count function referencing the webappcount variable
- We include count.index in the name, this will iterate through the count and add a number to the resource name so each one is unique
name = join("", [var.environment,"-WebApp-"count.index])
- In the Visual studio code terminal shell, make sure you are in folder \app-service-count-demo\
- Run terraform init
- Run terraform plan check there are no errors and confirm that it is going to deploy the resources you expect.
- Run terraform apply and type yes to approve the change
- Check the Azure Portal to review what has been deployed, you should have;
- One App service Plan, one App service
- Edit variables.tf and change webappcount to 3
- Save the changes
- Run terraform plan check there are no errors and confirm that it is going to deploy the resources you expect.
- Run terraform apply and type yes to approve the change
- Check the Azure Portal to review what has been deployed, you should have;
- One App service Plan, three App services
- From the terminal run terraform destroy
- Confirm that it is going to destroy only the resources you expect type yes to approve and cleanup the resources
- Check the resources have been deleted in the Azure Portal
It differs from one on-line on line casino in South Korea to the next, and it depends on by} your gaming preferences. Check out our in-depth evaluations 메리트카지노 of the most effective on-line casinos in South Korea search out|to search out} the right platform for you and your price range. 18+ | T&C's Apply | Gamble Responsibly and only guess money you could afford to lose.
ReplyDelete