Skip to content

Commit bcafdc4

Browse files
authored
Merge pull request #232247 from TomArcherMsft/UserStory60501-azure-cognitive-search
User Story 60501: Azure Cognitive Search
2 parents e3fcd82 + eacfeee commit bcafdc4

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

articles/search/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
- name: ARM template
4444
displayName: Resource Manager
4545
href: search-get-started-arm.md
46+
- name: Terraform
47+
href: search-get-started-terraform.md
4648
- name: Tutorials
4749
items:
4850
- name: Add search to static web apps
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: 'Quickstart: Create an Azure Cognitive Search service using Terraform'
3+
description: 'In this article, you create an Azure Cognitive Search service using Terraform'
4+
ms.topic: quickstart
5+
ms.date: 3/28/2023
6+
ms.custom: devx-track-terraform
7+
author: TomArcherMsft
8+
ms.author: tarcher
9+
ms.service: cognitive-search
10+
---
11+
12+
# Quickstart: Create an Azure Cognitive Search service using Terraform
13+
14+
This article shows how to use Terraform to create an [Azure Cognitive Search service](./search-what-is-azure-search.md) using [Terraform](/azure/developer/terraform/quickstart-configure).
15+
16+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
17+
18+
In this article, you learn how to:
19+
20+
> [!div class="checklist"]
21+
> * 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)
22+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
23+
> * Create a random string using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
24+
> * Create an Azure Cognitive Search service using [azurerm_search_service](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/search_service)
25+
26+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
27+
28+
## Prerequisites
29+
30+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
31+
32+
## Implement the Terraform code
33+
34+
> [!NOTE]
35+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-azure-cognitive-search). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/blob/master/quickstart/101-azure-cognitive-search/TestRecord.md).
36+
>
37+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
38+
39+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
40+
41+
1. Create a file named `main.tf` and insert the following code:
42+
43+
[!code-terraform[master](~/terraform_samples/quickstart/101-azure-cognitive-search/main.tf)]
44+
45+
1. Create a file named `outputs.tf` and insert the following code:
46+
47+
[!code-terraform[master](~/terraform_samples/quickstart/101-azure-cognitive-search/outputs.tf)]
48+
49+
1. Create a file named `providers.tf` and insert the following code:
50+
51+
[!code-terraform[master](~/terraform_samples/quickstart/101-azure-cognitive-search/providers.tf)]
52+
53+
1. Create a file named `variables.tf` and insert the following code:
54+
55+
[!code-terraform[master](~/terraform_samples/quickstart/101-azure-cognitive-search/variables.tf)]
56+
57+
## Initialize Terraform
58+
59+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
60+
61+
## Create a Terraform execution plan
62+
63+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
64+
65+
## Apply a Terraform execution plan
66+
67+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
68+
69+
## Verify the results
70+
71+
1. Get the Azure resource name in which the Azure Cognitive Search service was created.
72+
73+
```console
74+
resource_group_name=$(terraform output -raw resource_group_name)
75+
```
76+
77+
1. Get the Azure Cognitive Search service name.
78+
79+
```console
80+
azurerm_search_service_name=$(terraform output -raw azurerm_search_service_name)
81+
```
82+
83+
1. Run [az search service show](/cli/azure/search/service#az-search-service-show) to show the Azure Cognitive Search service you created in this article.
84+
85+
```azurecli
86+
az search service show --name $azurerm_search_service_name \
87+
--resource-group $resource_group_name
88+
```
89+
90+
## Clean up resources
91+
92+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
93+
94+
## Troubleshoot Terraform on Azure
95+
96+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
97+
98+
## Next steps
99+
100+
> [!div class="nextstepaction"]
101+
> [Create an Azure Cognitive Search index using the Azure portal](./search-get-started-portal.md)

0 commit comments

Comments
 (0)