Skip to content

Commit 22346a4

Browse files
authored
Merge pull request #296989 from TomArcherMsft/101-azure-storage-actions-create-storage-task
101-azure-storage-actions-create-storage-task
2 parents 7250218 + 1f53d7e commit 22346a4

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

articles/storage-actions/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ items:
1010
items:
1111
- name: Create, assign, and run a storage task
1212
href: storage-tasks/storage-task-quickstart-portal.md
13+
- name: Create a storage task - Terraform
14+
href: storage-tasks/storage-task-quickstart-terraform.md
1315
expanded: true
1416
- name: Concepts
1517
items:
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: 'Quickstart: Create a storage task using Terraform'
3+
titleSuffix: Azure Storage Actions Preview
4+
description: Learn how to create a storage task using Terraform. A storage task can perform on blobs in one or more Azure Storage accounts.
5+
author: normesta
6+
ms.service: azure-storage-actions
7+
ms.custom: devx-track-terraform;build-2023-metadata-update
8+
ms.topic: quickstart
9+
ms.author: normesta
10+
ms.date: 03/25/2025
11+
#customer intent: As a Terraform user, I want to see how to create a storage task using Terraform.
12+
content_well_notification:
13+
- AI-contribution
14+
---
15+
16+
# Quickstart: Create a storage task using Terraform
17+
18+
A storage task can perform operations on blobs in an Azure Storage account. As you create a task, you can define the conditions that must be met by each object (container or blob), and the operations to perform on the object. You can also identify one or more Azure Storage account targets. See [What are Azure Storage Actions?](../overview.md).
19+
20+
In this how-to article, you'll learn how to create a storage task using Terraform.
21+
22+
> [!IMPORTANT]
23+
> Azure Storage Actions is currently in PREVIEW and is available in these [regions](../overview.md#supported-regions).
24+
> See the [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/) for legal terms that apply to Azure features that are in beta, preview, or otherwise not yet released into general availability.
25+
26+
[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
27+
28+
> [!div class="checklist"]
29+
> * Retrieve the current Azure client configuration.
30+
> * Generate a random name for the resource group.
31+
> * Create a new Azure resource group with the generated name.
32+
> * Generate a random string to be used as the storage task name.
33+
> * Calculate a future date by offsetting the current date by a certain number of days.
34+
> * Create a new Azure API resource of type "Microsoft.StorageActions/storageTasks".
35+
> * Specify the required providers for Terraform, including their sources and versions.
36+
> * Configure the Azure provider with specific features.
37+
> * Define several variables, including the location of the resource group, the prefix for the resource group name, the number of offset days, and the description of the storage task.
38+
39+
## Prerequisites
40+
41+
- Create an Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
42+
43+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
44+
45+
## Implement the Terraform code
46+
47+
The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-azure-storage-actions-create-storage-task). 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-azure-storage-actions-create-storage-task/TestRecord.md). 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 `providers.tf` and insert the following code.
52+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-storage-actions-create-storage-task/providers.tf":::
53+
54+
1. Create a file named `main.tf` and insert the following code.
55+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-storage-actions-create-storage-task/main.tf":::
56+
57+
1. Create a file named `variables.tf` and insert the following code.
58+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-storage-actions-create-storage-task/variables.tf":::
59+
60+
1. Create a file named `outputs.tf` and insert the following code.
61+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-storage-actions-create-storage-task/outputs.tf":::
62+
63+
> [!IMPORTANT]
64+
> If you are using the 4.x azurerm provider, you must [explicitly specify the Azure subscription ID](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/4.0-upgrade-guide#specifying-subscription-id-is-now-mandatory) to authenticate to Azure before running the Terraform commands.
65+
>
66+
> One way to specify the Azure subscription ID without putting it in the `providers` block is to specify the subscription ID in an environment variable named `ARM_SUBSCRIPTION_ID`.
67+
>
68+
> For more information, see the [Azure provider reference documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#argument-reference).
69+
70+
## Initialize Terraform
71+
72+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
73+
74+
## Create a Terraform execution plan
75+
76+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
77+
78+
## Apply a Terraform execution plan
79+
80+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
81+
82+
## Verify the results
83+
84+
#### [Azure PowerShell](#tab/azure-powershell)
85+
86+
1. Get the Azure resource group name.
87+
88+
```console
89+
$resource_group_name=$(terraform output -raw resource_group_name)
90+
```
91+
92+
1. Get the storage task name.
93+
94+
```console
95+
$storage_task_name=$(terraform output -raw storage_task_name)
96+
```
97+
98+
1. Run [Get-AzStorageActionTask](/powershell/module/az.storageaction/get-azstorageactiontask) to get the storage task properties.
99+
100+
```azurepowershell
101+
Get-AzStorageActionTask -Name $storage_task_name -ResourceGroupName $resource_group_name
102+
```
103+
104+
---
105+
106+
## Clean up resources
107+
108+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
109+
110+
## Troubleshoot Terraform on Azure
111+
112+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot).
113+
114+
## Next steps
115+
116+
[Create a storage task](storage-task-create.md)

0 commit comments

Comments
 (0)