New sample (converted from Bicep via OpenAI)

This commit is contained in:
Tom Archer 2023-03-17 12:00:33 -07:00
parent 35b3afaf63
commit 771442acd4
5 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,24 @@
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "rg" {
name = random_pet.rg_name.id
location = var.resource_group_location
}
resource "random_string" "azurerm_search_service_name" {
length = 25
upper = false
numeric = false
special = false
}
resource "azurerm_search_service" "search" {
name = random_string.azurerm_search_service_name.result
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
sku = var.sku
replica_count = var.replica_count
partition_count = var.partition_count
}

View File

@ -0,0 +1,7 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}
output "azurerm_search_service_name" {
value = azurerm_search_service.search.name
}

View File

@ -0,0 +1,16 @@
terraform {
required_version = ">=1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}

View File

@ -0,0 +1,24 @@
# Azure Cognitive Search
This template deploys an Azure Cognitive Search service.
## Terraform resource types
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [azurerm_search_service](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/search_service)
## Variables
| Name | Description | Default |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
| `sku` | The pricing tier of the search service you want to create (for example, basic or standard). | standard |
| `replica_count` | The number of replicas that should be created. | 1 |
| `partition_count` | The number of partitions that should be created. | 1 |
## Example
To see how to run this example, see [Deploy an Azure Cognitive Search service using Terraform](https://learn.microsoft.com/azure/search/search-get-started-bicep).

View File

@ -0,0 +1,41 @@
variable "resource_group_location" {
type = string
description = "Location for all resources."
default = "eastus"
}
variable "resource_group_name_prefix" {
type = string
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
default = "rg"
}
variable "sku" {
description = "The pricing tier of the search service you want to create (for example, basic or standard)."
default = "standard"
type = string
validation {
condition = contains(["free", "basic", "standard", "standard2", "standard3", "storage_optimized_l1", "storage_optimized_l2"], var.sku)
error_message = "The sku must be one of the following values: free, basic, standard, standard2, standard3, storage_optimized_l1, storage_optimized_l2."
}
}
variable "replica_count" {
type = number
description = "Replicas distribute search workloads across the service. You need at least two replicas to support high availability of query workloads (not applicable to the free tier)."
default = 1
validation {
condition = var.replica_count >= 1 && var.replica_count <= 12
error_message = "The replica_count must be between 1 and 12."
}
}
variable "partition_count" {
type = number
description = "Partitions allow for scaling of document count as well as faster indexing by sharding your index over multiple search units."
default = 1
validation {
condition = contains([1, 2, 3, 4, 6, 12], var.partition_count)
error_message = "The partition_count must be one of the following values: 1, 2, 3, 4, 6, 12."
}
}