I am following this guide in order to create Azure AI Search indexes, indexers, and datasources: https://medium.com/expert-thinking/mastering-azure-search-with-terraform-a-how-to-guide-7edc3a6b1ee3
I want to be able to create an Azure AI Search service with Terraform and then use its created API key to use in my restapi provider.
Using:
terraform v.1.7.1
hashicorp/azurerm v3.95.0
mastercard/restapi v1.19.0
main.tf:
module "az-search" {
source = "./modules/az-search"
environment = var.environment
az_resource_group_name = var.az_resource_group_name
az_resource_group_location = var.az_resource_group_location
providers = {
azurerm = azurerm.sub
}
}
providers.tf:
provider "azurerm" {
alias = "sub"
subscription_id = var.az_subscription_id
features {}
}
provider "restapi" {
uri = "https://some-search.search.windows.net"
write_returns_object = true
debug = true
headers = {
"api-key" = [how do I get this from the created resource?]
"Content-Type" = "application/json"
}
create_method = "POST"
update_method = "PUT"
destroy_method = "DELETE"
}
az-search/main.tf
resource "azurerm_search_service" "search" {
name = "some-search"
resource_group_name = var.az_resource_group_name
location = var.az_resource_group_location
sku = var.sku
}
resource "restapi_object" "create_datasource" {
path = "/datasources"
query_string = "api-version=2023-10-01-Preview"
data = file(var.product_datasource_path)
id_attribute = "name"
}
Am I able to get the API key from the created resource and then insert it into the restapi provider?