Skip to content

Commit

Permalink
Remove unused variables and update API Management outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Mar 5, 2024
1 parent d1eb892 commit 54b6338
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ module "nsg" {
}

module "apim" {
count = var.enable_apim ? 1 : 0
source = "./modules/apim"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
apim_name = local.apim_name
apim_subnet_id = module.vnet.apim_subnet_id
publisher_name = var.publisher_name
publisher_email = var.publisher_email
enable_apim = var.enable_apim
appi_resource_id = module.appi.appi_id
appi_instrumentation_key = module.appi.appi_key
openai_service_name = module.openai.openai_service_name
Expand Down
28 changes: 10 additions & 18 deletions infra/modules/apim/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ locals {
}

resource "azurerm_public_ip" "apim_public_ip" {
count = var.enable_apim ? 1 : 0
name = "pip-apim"
location = var.location
resource_group_name = var.resource_group_name
Expand All @@ -16,26 +15,24 @@ resource "azurerm_public_ip" "apim_public_ip" {
}

resource "azurerm_api_management" "apim" {
count = var.enable_apim ? 1 : 0
name = var.apim_name
location = var.location
resource_group_name = var.resource_group_name
publisher_name = var.publisher_name
publisher_email = var.publisher_email
sku_name = "Developer_1"
virtual_network_type = "External" # Use "Internal" for a fully private APIM
public_ip_address_id = azurerm_public_ip.apim_public_ip[0].id // Required to deploy APIM in STv2 platform
virtual_network_type = "External" # Use "Internal" for a fully private APIM
public_ip_address_id = azurerm_public_ip.apim_public_ip.id // Required to deploy APIM in STv2 platform

virtual_network_configuration {
subnet_id = var.apim_subnet_id
}
}

resource "azurerm_api_management_backend" "openai" {
count = var.enable_apim ? 1 : 0
name = "openai-api"
resource_group_name = var.resource_group_name
api_management_name = azurerm_api_management.apim[0].name
api_management_name = azurerm_api_management.apim.name
protocol = "http"
url = local.backend_url
tls {
Expand All @@ -45,9 +42,8 @@ resource "azurerm_api_management_backend" "openai" {
}

resource "azurerm_api_management_logger" "appi_logger" {
count = var.enable_apim ? 1 : 0
name = local.logger_name
api_management_name = azurerm_api_management.apim[0].name
api_management_name = azurerm_api_management.apim.name
resource_group_name = var.resource_group_name
resource_id = var.appi_resource_id

Expand All @@ -58,10 +54,9 @@ resource "azurerm_api_management_logger" "appi_logger" {

// https://learn.microsoft.com/en-us/semantic-kernel/deploy/use-ai-apis-with-api-management#setup-azure-api-management-instance-with-azure-openai-api
resource "azurerm_api_management_api" "openai" {
count = var.enable_apim ? 1 : 0
name = "openai-api"
resource_group_name = var.resource_group_name
api_management_name = azurerm_api_management.apim[0].name
api_management_name = azurerm_api_management.apim.name
revision = "1"
display_name = "Azure Open AI API"
path = "openai"
Expand All @@ -76,18 +71,16 @@ resource "azurerm_api_management_api" "openai" {
}

resource "azurerm_api_management_named_value" "tenant_id" {
count = var.enable_apim ? 1 : 0
name = "tenant-id"
resource_group_name = var.resource_group_name
api_management_name = azurerm_api_management.apim[0].name
api_management_name = azurerm_api_management.apim.name
display_name = "TENANT_ID"
value = var.tenant_id
}

resource "azurerm_api_management_api_policy" "policy" {
count = var.enable_apim ? 1 : 0
api_name = azurerm_api_management_api.openai[0].name
api_management_name = azurerm_api_management.apim[0].name
api_name = azurerm_api_management_api.openai.name
api_management_name = azurerm_api_management.apim.name
resource_group_name = var.resource_group_name

xml_content = <<XML
Expand Down Expand Up @@ -124,11 +117,10 @@ resource "azurerm_api_management_api_policy" "policy" {

# https://github.com/aavetis/azure-openai-logger/blob/main/README.md
resource "azurerm_api_management_diagnostic" "diagnostics" {
count = var.enable_apim ? 1 : 0
identifier = "applicationinsights"
resource_group_name = var.resource_group_name
api_management_name = azurerm_api_management.apim[0].name
api_management_logger_id = azurerm_api_management_logger.appi_logger[0].id
api_management_name = azurerm_api_management.apim.name
api_management_logger_id = azurerm_api_management_logger.appi_logger.id

sampling_percentage = 100
always_log_errors = true
Expand Down
4 changes: 2 additions & 2 deletions infra/modules/apim/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "apim_name" {
value = var.enable_apim ? azurerm_api_management.apim[0].name : ""
value = azurerm_api_management.apim.name
}

output "gateway_url" {
value = var.enable_apim ? azurerm_api_management.apim[0].gateway_url : ""
value = azurerm_api_management.apim.gateway_url
}
2 changes: 0 additions & 2 deletions infra/modules/apim/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ variable "appi_instrumentation_key" {}
variable "openai_service_name" {}
variable "openai_service_endpoint" {}
variable "tenant_id" {}

variable "enable_apim" {}
48 changes: 29 additions & 19 deletions infra/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
output "resource_group_name" {
value = "${azurerm_resource_group.rg.name}"
description = "The name of the resource group"
value = azurerm_resource_group.rg.name
description = "The name of the resource group"
}

output "subscription_id" {
value = "${data.azurerm_subscription.current.subscription_id}"
description = "The subscription ID used"
value = data.azurerm_subscription.current.subscription_id
description = "The subscription ID used"
}

output "tenant_id" {
value = "${data.azurerm_subscription.current.tenant_id}"
description = "The tenant ID used"
value = data.azurerm_subscription.current.tenant_id
description = "The tenant ID used"
}

output "storage_account_name" {
value = "${module.st.storage_account_name}"
description = "The name of the storage account"
value = module.st.storage_account_name
description = "The name of the storage account"
}

output "storage_container_name" {
value = "${module.st.storage_container_name}"
description = "The name of the storage account"
value = module.st.storage_container_name
description = "The name of the storage account"
}

output "search_service_name" {
value = "${module.search.search_service_name}"
description = "The name of the search service"
value = module.search.search_service_name
description = "The name of the search service"
}

output "search_service_index_name" {
value = "${module.search.search_index_name}"
description = "The name of the search service index"
value = module.search.search_index_name
description = "The name of the search service index"
}

output "openai_service_name" {
value = "${module.openai.openai_service_name}"
description = "The name of the openai service"
value = module.openai.openai_service_name
description = "The name of the openai service"
}

output "embedding_deployment_name" {
value = "${module.openai.embedding_deployment_name}"
description = "The name of the embedding deployment"
}
value = module.openai.embedding_deployment_name
description = "The name of the embedding deployment"
}

output "aihub_fqdn" {
value = module.ca_aihub.fqdn
description = "The FQDN of the AI Hub service"
}

output "chat_fqdn" {
value = module.ca_chat.fqdn
description = "The FQDN of the Chat service"
}

0 comments on commit 54b6338

Please sign in to comment.