0
votes

using Terraform with the Azure Search Service, it exports query_keys as a "block" with key and name...

Under the "Attributes Reference" section... https://www.terraform.io/docs/providers/azurerm/r/search_service.html

I already have the ID and Primary Key being exported out to Azure KeyVault from the Terraform code, but how do you do it for a "block" of attributes?

# Key vault secrets
resource "azurerm_key_vault_secret" "go-1a" {
  name          = "secret-Search01-ID"
  value         = azurerm_search_service.go-1.id
  key_vault_id  = data.azurerm_key_vault.env-keyvault.id
}
resource "azurerm_key_vault_secret" "go-1b" {
  name          = "secret-Search01-PrimaryKey"
  value         = azurerm_search_service.go-1.primary_key
  key_vault_id  = data.azurerm_key_vault.env-keyvault.id
}

Thanks in advance

1

1 Answers

1
votes

The query_keys is a list of objects.

Example code

provider "azurerm" {
  version = "~>2.19.0"
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "East US"
}

resource "azurerm_search_service" "example" {
  name                = "example-search-service"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku                 = "standard"
}

output "query_keys_key" {
    value = azurerm_search_service.example.query_keys[0].key
}

output "query_keys_name" {
    value = azurerm_search_service.example.query_keys[0].name
}

Example output

> terraform apply
azurerm_resource_group.example: Refreshing state... [id=/subscriptions/redacted/resourceGroups/example-resources]
azurerm_search_service.example: Refreshing state... [id=/subscriptions/redacted/resourceGroups/example-resources/providers/Microsoft.Search/searchServices/example-search-service]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

query_keys_key = 662EEE1DD452E082922C1AF00B0BBFA9
query_keys_name =

Run a terraform show to see

> terraform show
# azurerm_resource_group.example:
resource "azurerm_resource_group" "example" {
    id       = "/subscriptions/redacted/resourceGroups/example-resources"
    location = "eastus"
    name     = "example-resources"
}

# azurerm_search_service.example:
resource "azurerm_search_service" "example" {
    id                  = "/subscriptions/redacted/resourceGroups/example-resources/providers/Microsoft.Search/searchServices/example-search-service"
    location            = "eastus"
    name                = "example-search-service"
    partition_count     = 1
    primary_key         = "3EE7E9F80715E0451EEBC25196808563"
    query_keys          = [
        {
            key  = "662EEE1DD452E08292BC1AF01B0BBFA9"
            name = ""
        },
    ]
    replica_count       = 1
    resource_group_name = "example-resources"
    secondary_key       = "11CCA067EEC7E04FC1F39582FD01C316"
    sku                 = "standard"
}