|
| 1 | +--- |
| 2 | +title: 'Deploy an Azure Batch account and two pools - Terraform' |
| 3 | +description: In this article, you deploy an Azure Batch account and two pools using Terraform. |
| 4 | +ms.topic: quickstart |
| 5 | +ms.date: 10/24/2024 |
| 6 | +ms.custom: devx-track-terraform |
| 7 | +ms.service: azure-batch |
| 8 | +author: Padmalathas |
| 9 | +ms.author: padmalathas |
| 10 | +#customer intent: As a Terraform user, I want to see how to create an Azure resource group, Storage account, Batch account, and two Batch pools with different scaling configurations. |
| 11 | +content_well_notification: |
| 12 | + - AI-contribution |
| 13 | +ai-usage: ai-assisted |
| 14 | +--- |
| 15 | + |
| 16 | +# Deploy an Azure Batch account and two pools - Terraform |
| 17 | + |
| 18 | +In this quickstart, you create an Azure Batch account, an Azure Storage account, and two Batch pools using Terraform. Batch is a cloud-based job scheduling service that parallelizes and distributes the processing of large volumes of data across many computers. It's typically used for parametric sweeps, Monte Carlo simulations, financial risk modeling, and other high-performance computing applications. A Batch account is the top-level resource in the Batch service that provides access to pools, jobs, and tasks. The Storage account is used to store and manage all the files that are used and generated by the Batch service, while the two Batch pools are collections of compute nodes that execute the tasks. |
| 19 | + |
| 20 | +[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)] |
| 21 | + |
| 22 | +> [!div class="checklist"] |
| 23 | +> * Specify the required version of Terraform and the required providers. |
| 24 | +> * Define the Azure provider with no additional features. |
| 25 | +> * Define variables for the location of the resource group and the prefix of the resource group name. |
| 26 | +> * Generate a random name for the resource group using the provided prefix. |
| 27 | +> * Create an Azure resource group with the generated name at the specified location. |
| 28 | +> * Generate a random string to be used as the name for the Storage account. |
| 29 | +> * Create a Storage account with the generated name in the created resource group, at the same location, and with a standard account tier and locally redundant Storage replication type. |
| 30 | +> * Generate another random string to be used as the name for the Batch account. |
| 31 | +> * Create a Batch account with the generated name in the created resource group, at the same location, and link it to the created Storage account with Storage keys authentication mode. |
| 32 | +> * Generate a random name for the Batch pool with a "pool" prefix. |
| 33 | +> * Create a Batch pool with a fixed scale using the generated name in the created resource group, linked to the created Batch account, with a standard A1 virtual machine (VM) size, Ubuntu 22.04 node agent SKU, and a start task that echoes 'Hello World from $env' with a maximum of one retry and waits for success. |
| 34 | +> * Create another Batch pool with auto scale, using the same generated name, in the created resource group, linked to the created Batch account, with a standard A1 VM size, Ubuntu 22.04 node agent SKU, and an autoscale formula. |
| 35 | +> * Output the names of the created resource group, Storage account, Batch account, and both Batch pools. |
| 36 | +
|
| 37 | +## Prerequisites |
| 38 | + |
| 39 | +- Create an Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 40 | +- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure). |
| 41 | + |
| 42 | +## Implement the Terraform code |
| 43 | + |
| 44 | +> [!NOTE] |
| 45 | +> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-batch-pools-with-job). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/tree/master/quickstart/101-batch-pools-with-job/TestRecord.md). |
| 46 | +> |
| 47 | +> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform). |
| 48 | +
|
| 49 | +1. Create a directory in which to test and run the sample Terraform code, and make it the current directory. |
| 50 | + |
| 51 | +1. Create a file named `main.tf`, and insert the following code: |
| 52 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-batch-pools-with-job/main.tf"::: |
| 53 | + |
| 54 | +1. Create a file named `outputs.tf`, and insert the following code: |
| 55 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-batch-pools-with-job/outputs.tf"::: |
| 56 | + |
| 57 | +1. Create a file named `providers.tf`, and insert the following code: |
| 58 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-batch-pools-with-job/providers.tf"::: |
| 59 | + |
| 60 | +1. Create a file named `variables.tf`, and insert the following code: |
| 61 | + :::code language="Terraform" source="~/terraform_samples/quickstart/101-batch-pools-with-job/variables.tf"::: |
| 62 | + |
| 63 | +## Initialize Terraform |
| 64 | + |
| 65 | +[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)] |
| 66 | + |
| 67 | +## Create a Terraform execution plan |
| 68 | + |
| 69 | +[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)] |
| 70 | + |
| 71 | +## Apply a Terraform execution plan |
| 72 | + |
| 73 | +[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)] |
| 74 | + |
| 75 | +## Verify the results |
| 76 | + |
| 77 | +### [Azure CLI](#tab/azure-cli) |
| 78 | + |
| 79 | +Run [`az batch account show`](/cli/azure/batch/account#az-batch-account-show) to view the Batch account. |
| 80 | + |
| 81 | +```azurecli |
| 82 | +az batch account show --name <batch_account_name> --resource-group <resource_group_name> |
| 83 | +``` |
| 84 | + |
| 85 | +Replace `<batch_account_name>` with the name of your Batch account and `<resource_group_name>` with the name of your resource group. |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Clean up resources |
| 90 | + |
| 91 | +[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)] |
| 92 | + |
| 93 | +## Troubleshoot Terraform on Azure |
| 94 | + |
| 95 | +[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot). |
| 96 | + |
| 97 | +## Next steps |
| 98 | + |
| 99 | +> [!div class="nextstepaction"] |
| 100 | +> [See more articles about Batch accounts](/search/?terms=Azure%20batch%20account%20and%20terraform). |
0 commit comments