Skip to content

Commit c98400c

Browse files
authored
Merge pull request #291699 from LiSeda/LS-tfauto
LS_New_quickstart-create-automation-account-terraform.md
2 parents 8da3968 + b7e6b45 commit c98400c

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

articles/automation/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
items:
1717
- name: Create Automation account - Azure portal
1818
href: quickstarts/create-azure-automation-account-portal.md
19+
- name: Create Automation account - Terraform
20+
href: quickstarts/create-azure-automation-account-terraform.md
1921
- name: Update runbook from PowerShell 5.1 to PowerShell 7.2
2022
href: quickstart-update-runbook-in-runtime-environment.md
2123
- name: Run Azure CLI commands in PowerShell 7.2 runbooks
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: 'Quickstart: Use Terraform to create an Azure Automation account'
3+
description: In this quickstart, you use Terraform to create an Azure resource group, create an Azure Automation account with a system-assigned identity, and assign a "Reader" role to the Automation account.
4+
ms.topic: quickstart
5+
ms.date: 01/15/2025
6+
ms.custom: devx-track-terraform
7+
ms.service: azure-automation
8+
author: SnehaSudhirG
9+
ms.author: sudhirsneha
10+
#customer intent: As a Terraform user, I want to learn how to create an Azure resource group, create an Azure Automation account with a system-assigned identity, and assign a "Reader" role to the account.
11+
content_well_notification:
12+
- AI-contribution
13+
---
14+
15+
# Quickstart: Use Terraform to create an Azure Automation account
16+
17+
In this quickstart, you create an Azure Automation account and use Terraform to assign a "Reader" role to the account. An Automation account is a cloud-based service that provides a secure environment for running runbooks, which are scripts that automate processes. The account can automate frequent, time-consuming, and error-prone tasks that are managed in the cloud. This Automation account is created within an Azure resource group, which is a container that holds related resources for an Azure solution. Additionally, a "Reader" role is assigned to the Automation account, granting the subscription permission to view all resources in an Automation account but not make any changes.
18+
19+
[!INCLUDE [About Terraform](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
20+
21+
In this article, you learn how to:
22+
23+
> [!div class="checklist"]
24+
> * Create an Azure resource group with a unique name.
25+
> * Generate a random string for unique naming of the Azure resources.
26+
> * Create an Automation account, and enable public network access.
27+
> * Retrieve the current Azure subscription.
28+
> * Retrieve the role definition for "Reader".
29+
> * Assign the "Reader" role to the Automation account.
30+
> * Output the names of the created resource group and Automation account.
31+
32+
## Prerequisites
33+
34+
- Create an Azure account with an active subscription. You can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). Options for your new Automation account are organized into tabs in the **Create an Automation Account** page of the Azure portal.
35+
36+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure).
37+
38+
## Implement the Terraform code
39+
40+
> [!NOTE]
41+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-azure-automation). 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-automation/TestRecord.md).
42+
>
43+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform).
44+
45+
1. Create a directory in which to test and run the sample Terraform code, and make it the current directory.
46+
47+
1. Create a file named `main.tf`, and insert the following code:
48+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-automation/main.tf":::
49+
50+
1. Create a file named `outputs.tf`, and insert the following code:
51+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-automation/outputs.tf":::
52+
53+
1. Create a file named `providers.tf`, and insert the following code:
54+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-automation/providers.tf":::
55+
56+
1. Create a file named `variables.tf`, and insert the following code:
57+
:::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-automation/variables.tf":::
58+
59+
## Initialize Terraform
60+
61+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
62+
63+
## Create a Terraform execution plan
64+
65+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
66+
67+
## Apply a Terraform execution plan
68+
69+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
70+
71+
## Verify the results
72+
73+
### [Azure CLI](#tab/azure-cli)
74+
75+
1. Get the Azure resource group name.
76+
77+
```console
78+
resource_group_name=$(terraform output -raw resource_group_name)
79+
```
80+
81+
1. Get the Automation account name.
82+
83+
```console
84+
automation_account_name=$(terraform output -raw automation_account_name)
85+
```
86+
87+
1. Run [`az automation account show`](/cli/azure/automation/account#az-automation-account-show) to view the Automation account.
88+
89+
```azurecli
90+
az automation account show --name $automation_account_name --resource-group $resource_group_name
91+
```
92+
93+
### [Azure PowerShell](#tab/azure-powershell)
94+
95+
1. Get the Azure resource group name.
96+
97+
```console
98+
$resource_group_name=$(terraform output -raw resource_group_name)
99+
```
100+
101+
1. Get the Automation account name.
102+
103+
```console
104+
$automation_account_name=$(terraform output -raw automation_account_name)
105+
```
106+
107+
1. Run [`Get-AzAutomationAccount`](/powershell/module/az.automation/get-azautomationaccount#example-2-get-an-account) to view the Automation account.
108+
109+
```azurepowershell
110+
Get-AzAutomationAccount -ResourceGroupName $resource_group_name -Name $automation_account_name
111+
```
112+
113+
---
114+
115+
## Clean up resources
116+
117+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
118+
119+
## Troubleshoot Terraform on Azure
120+
121+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot).
122+
123+
## Next steps
124+
125+
In this Quickstart, you created an Automation account. [Explore articles about Automation accounts](/search/?terms=Azure%20automation%20account%20and%20terraform) to learn more.
126+
127+
To use managed identities with your Automation account, continue to:
128+
129+
> [!div class="nextstepaction"]
130+
> [Tutorial: Create Automation PowerShell runbook using managed identity](../learn/powershell-runbook-managed-identity.md)

0 commit comments

Comments
 (0)