| title | Quickstart: Create an Azure Batch account using Terraform | |
|---|---|---|
| description | In this article, you create an Azure Batch account using Terraform | |
| ms.topic | quickstart | |
| ms.service | azure-batch | |
| ms.date | 04/02/2025 | |
| ms.custom | devx-track-terraform | |
| author | TomArcherMsft | |
| ms.author | tarcher | |
| content_well_notification |
|
|
| ai-usage | ai-assisted |
Get started with Azure Batch by using Terraform to create a Batch account, including storage. You need a Batch account to create compute resources (pools of compute nodes) and Batch jobs. You can link an Azure Storage account with your Batch account. This pairing is useful to deploy applications and store input and output data for most real-world workloads.
After completing this quickstart, you'll understand the key concepts of the Batch service and be ready to try Batch with more realistic workloads at larger scale.
[!INCLUDE Terraform abstract]
In this article, you learn how to:
[!div class="checklist"]
- Create a random value for the Azure resource group name using random_pet
- Create an Azure resource group using azurerm_resource_group
- Create a random value using random_string
- Create an Azure Storage account using azurerm_storage_account
- Create an Azure Batch account using azurerm_batch_account
Note
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources
-
Create a directory in which to test and run the sample Terraform code and make it the current directory.
-
Create a file named
providers.tfand insert the following code:[!code-terraformmaster]
-
Create a file named
main.tfand insert the following code:[!code-terraformmaster]
-
Create a file named
variables.tfand insert the following code:[!code-terraformmaster]
-
Create a file named
outputs.tfand insert the following code:[!code-terraformmaster]
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
-
Get the Azure resource group name.
resource_group_name=$(terraform output -raw resource_group_name) -
Get the Batch account name.
batch_name=$(terraform output -raw batch_name) -
Run az batch account show to display information about the new Batch account.
az batch account show \ --resource-group $resource_group_name \ --name $batch_name
-
Get the Azure resource group name.
$resource_group_name=$(terraform output -raw resource_group_name) -
Get the Batch account name.
$batch_name=$(terraform output -raw batch_name) -
Run Get-AzBatchAccount to display information about the new service.
Get-AzBatchAccount -ResourceGroupName $resource_group_name ` -Name $batch_name
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure
[!div class="nextstepaction"] Run your first Batch job with the Azure CLI