Skip to content

Commit ba78617

Browse files
Merge pull request #233069 from TomArcherMsft/UserStory60501-batch-account-with-storage
User Story 60501: Azure Batch
2 parents 27c4ee7 + b10ee00 commit ba78617

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

articles/batch/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
- name: Create a Batch account - ARM template
2727
href: quick-create-template.md
2828
displayName: Resource Manager
29+
- name: Create a Batch account - Terraform
30+
href: quick-create-terraform.md
2931
- name: Tutorials
3032
items:
3133
- name: Parallel file processing - .NET
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: 'Quickstart: Create an Azure Batch account using Terraform'
3+
description: 'In this article, you create an Azure Batch account using Terraform'
4+
ms.topic: quickstart
5+
ms.service: batch
6+
ms.date: 4/1/2023
7+
ms.custom: devx-track-terraform
8+
author: TomArcherMsft
9+
ms.author: tarcher
10+
---
11+
12+
# Quickstart: Create an Azure Batch account using Terraform
13+
14+
Get started with [Azure Batch](/azure/batch/batch-technical-overview) 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.
15+
16+
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.
17+
18+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
19+
20+
In this article, you learn how to:
21+
22+
> [!div class="checklist"]
23+
> * Create a random value for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
24+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
25+
> * Create a random value using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
26+
> * Create an Azure Storage account using [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account)
27+
> * Create an Azure Batch account using [azurerm_batch_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/batch_account)
28+
29+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
30+
31+
## Prerequisites
32+
33+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
34+
35+
## Implement the Terraform code
36+
37+
> [!NOTE]
38+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-batch-account-with-storage). 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-account-with-storage/TestRecord.md).
39+
>
40+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
41+
42+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
43+
44+
1. Create a file named `providers.tf` and insert the following code:
45+
46+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch-account-with-storage/providers.tf)]
47+
48+
1. Create a file named `main.tf` and insert the following code:
49+
50+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch-account-with-storage/main.tf)]
51+
52+
1. Create a file named `variables.tf` and insert the following code:
53+
54+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch-account-with-storage/variables.tf)]
55+
56+
1. Create a file named `outputs.tf` and insert the following code:
57+
58+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch-account-with-storage/outputs.tf)]
59+
60+
## Initialize Terraform
61+
62+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
63+
64+
## Create a Terraform execution plan
65+
66+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
67+
68+
## Apply a Terraform execution plan
69+
70+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
71+
72+
## Verify the results
73+
74+
#### [Azure CLI](#tab/azure-cli)
75+
76+
1. Get the Azure resource group name.
77+
78+
```console
79+
resource_group_name=$(terraform output -raw resource_group_name)
80+
```
81+
82+
1. Get the Batch account name.
83+
84+
```console
85+
batch_name=$(terraform output -raw batch_name)
86+
```
87+
88+
1. Run [az batch account show](/cli/azure/batch/account#az-batch-account-show) to display information about the new Batch account.
89+
90+
```azurecli
91+
az batch account show \
92+
--resource-group $resource_group_name \
93+
--name $batch_name
94+
```
95+
96+
#### [Azure PowerShell](#tab/azure-powershell)
97+
98+
1. Get the Azure resource group name.
99+
100+
```console
101+
$resource_group_name=$(terraform output -raw resource_group_name)
102+
```
103+
104+
1. Get the Batch account name.
105+
106+
```console
107+
$batch_name=$(terraform output -raw batch_name)
108+
```
109+
110+
1. Run [Get-AzBatchAccount](/powershell/module/az.batch/get-azbatchaccount) to display information about the new service.
111+
112+
```azurepowershell
113+
Get-AzBatchAccount -ResourceGroupName $resource_group_name `
114+
-Name $batch_name
115+
```
116+
117+
---
118+
119+
## Clean up resources
120+
121+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
122+
123+
## Troubleshoot Terraform on Azure
124+
125+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
126+
127+
## Next steps
128+
129+
> [!div class="nextstepaction"]
130+
> [Run your first Batch job with the Azure CLI](/azure/batch/quick-create-cli)

0 commit comments

Comments
 (0)