Skip to content

Commit ebab3c0

Browse files
committed
Quickstart using Terraform
1 parent 321a331 commit ebab3c0

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-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: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 example code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-batch_account). See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
39+
40+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
41+
42+
1. Create a file named `providers.tf` and insert the following code:
43+
44+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch_account/providers.tf)]
45+
46+
1. Create a file named `main.tf` and insert the following code:
47+
48+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch_account/main.tf)]
49+
50+
1. Create a file named `variables.tf` and insert the following code:
51+
52+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch_account/variables.tf)]
53+
54+
1. Create a file named `outputs.tf` and insert the following code:
55+
56+
[!code-terraform[master](~/terraform_samples/quickstart/101-batch_account/outputs.tf)]
57+
58+
## Initialize Terraform
59+
60+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
61+
62+
## Create a Terraform execution plan
63+
64+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
65+
66+
## Apply a Terraform execution plan
67+
68+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
69+
70+
## Verify the results
71+
72+
#### [Azure CLI](#tab/azure-cli)
73+
74+
1. Get the Azure resource group name.
75+
76+
```console
77+
resource_group_name=$(terraform output -raw resource_group_name)
78+
```
79+
80+
1. Get the Batch account name.
81+
82+
```console
83+
batch_name=$(terraform output -raw batch_name)
84+
```
85+
86+
1. Run [az batch account show](/cli/azure/batch/account#az-batch-account-show) to display information about the new Batch account.
87+
88+
```azurecli
89+
az batch account show \
90+
--resource-group $resource_group_name \
91+
--name $batch_name
92+
```
93+
94+
#### [Azure PowerShell](#tab/azure-powershell)
95+
96+
1. Get the Azure resource group name.
97+
98+
```console
99+
$resource_group_name=$(terraform output -raw resource_group_name)
100+
```
101+
102+
1. Get the Batch account name.
103+
104+
```console
105+
$batch_name=$(terraform output -raw batch_name)
106+
```
107+
108+
1. Run [Get-AzBatchAccount](/powershell/module/az.batch/get-azbatchaccount) to display information about the new service.
109+
110+
```azurepowershell
111+
Get-AzBatchAccount -ResourceGroupName $resource_group_name `
112+
-Name $batch_name
113+
```
114+
115+
---
116+
117+
## Clean up resources
118+
119+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
120+
121+
## Troubleshoot Terraform on Azure
122+
123+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
124+
125+
## Next steps
126+
127+
> [!div class="nextstepaction"]
128+
> [Run your first Batch job with the Azure CLI](/azure/batch/quick-create-cli)

0 commit comments

Comments
 (0)