Skip to content

Commit f452d2c

Browse files
Merge pull request #232608 from TomArcherMsft/UserStory60501-cognitive-services-account
User Story 60501: Azure Cognitive Services
2 parents 81a212e + 20b5966 commit f452d2c

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

articles/cognitive-services/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
- name: Create a new resource using an ARM template
2424
displayName: Resource Manager
2525
href: create-account-resource-manager-template.md
26+
- name: Create a new resource using Terraform
27+
href: create-account-terraform.md
2628
- name: How-To
2729
items:
2830
- name: Plan and manage costs
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 Cognitive Services resource using Terraform'
3+
description: 'In this article, you create an Azure Cognitive Services resource using Terraform'
4+
keywords: cognitive services, cognitive solutions, cognitive intelligence, cognitive artificial intelligence
5+
services: cognitive-services
6+
ms.service: cognitive-services
7+
ms.topic: quickstart
8+
ms.date: 3/29/2023
9+
ms.custom: devx-track-terraform
10+
author: TomArcherMsft
11+
ms.author: tarcher
12+
---
13+
14+
# Quickstart: Create an Azure Cognitive Services resource using Terraform
15+
16+
This article shows how to use Terraform to create a [Cognitive Services account](/azure/cognitive-services/cognitive-services-apis-create-account) using [Terraform](/azure/developer/terraform/quickstart-configure).
17+
18+
Azure Cognitive Services are cloud-based artificial intelligence (AI) services that help developers build cognitive intelligence into applications without having direct AI or data science skills or knowledge. They are available through REST APIs and client library SDKs in popular development languages. Azure Cognitive Services enables developers to easily add cognitive features into their applications with cognitive solutions that can see, hear, speak, and analyze.
19+
20+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
21+
22+
In this article, you learn how to:
23+
24+
> [!div class="checklist"]
25+
> * Create a random pet name for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
26+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
27+
> * Create a random string using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
28+
> * Create a Cognitive Services account using [azurerm_cognitive_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cognitive_account)
29+
30+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
31+
32+
## Prerequisites
33+
34+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
35+
36+
## Implement the Terraform code
37+
38+
> [!NOTE]
39+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-cognitive-services-account). 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-cognitive-services-account/TestRecord.md).
40+
>
41+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
42+
43+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
44+
45+
1. Create a file named `main.tf` and insert the following code:
46+
47+
[!code-terraform[master](~/terraform_samples/quickstart/101-cognitive-services-account/main.tf)]
48+
49+
1. Create a file named `outputs.tf` and insert the following code:
50+
51+
[!code-terraform[master](~/terraform_samples/quickstart/101-cognitive-services-account/outputs.tf)]
52+
53+
1. Create a file named `providers.tf` and insert the following code:
54+
55+
[!code-terraform[master](~/terraform_samples/quickstart/101-cognitive-services-account/providers.tf)]
56+
57+
1. Create a file named `variables.tf` and insert the following code:
58+
59+
[!code-terraform[master](~/terraform_samples/quickstart/101-cognitive-services-account/variables.tf)]
60+
61+
## Initialize Terraform
62+
63+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
64+
65+
## Create a Terraform execution plan
66+
67+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
68+
69+
## Apply a Terraform execution plan
70+
71+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
72+
73+
## Verify the results
74+
75+
#### [Azure CLI](#tab/azure-cli)
76+
77+
1. Get the Azure resource name in which the Cognitive Services account was created.
78+
79+
```console
80+
resource_group_name=$(terraform output -raw resource_group_name)
81+
```
82+
83+
1. Get the Cognitive Services account name.
84+
85+
```console
86+
azurerm_cognitive_account_name=$(terraform output -raw azurerm_cognitive_account_name)
87+
```
88+
89+
1. Run [az cognitiveservices account show](/cli/azure/cognitiveservices/account#az-cognitiveservices-account-show) to show the Cognitive Services account you created in this article.
90+
91+
```azurecli
92+
az cognitiveservices account show --name $azurerm_cognitive_account_name \
93+
--resource-group $resource_group_name
94+
```
95+
96+
#### [Azure PowerShell](#tab/azure-powershell)
97+
98+
1. Get the Azure resource name in which the Cognitive Services account was created.
99+
100+
```console
101+
$resource_group_name=$(terraform output -raw resource_group_name)
102+
```
103+
104+
1. Get the Cognitive Services account name.
105+
106+
```console
107+
$azurerm_cognitive_account_name=$(terraform output -raw azurerm_cognitive_account_name)
108+
```
109+
110+
1. Run [Get-AzCognitiveServicesAccount](/powershell/module/az.cognitiveservices/get-azcognitiveservicesaccount) to display information about the new service.
111+
112+
```azurepowershell
113+
Get-AzCognitiveServicesAccount -ResourceGroupName $resource_group_name `
114+
-Name $azurerm_cognitive_account_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+
> [Recover deleted Cognitive Services resources](manage-resources.md)

0 commit comments

Comments
 (0)