From c60b35d091dc7420121f7a22f1c711e40ffc200b Mon Sep 17 00:00:00 2001 From: Rodrigo Liberoff Date: Mon, 10 Jun 2024 14:54:41 +0200 Subject: [PATCH] Fix updating the Azure API Management (#59) * Fix updating the Azure API Management. Previously on any update, Terraform was indicating a `forced replacement` due to a calculation of the resource group ID. Passing it as a variable from the main module helps Terraform no to force a replacement, and updating APIs and policies without issue. --- infra/main.tf | 1 + infra/modules/apim/main.tf | 7 +------ infra/modules/apim/variables.tf | 1 + 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/infra/main.tf b/infra/main.tf index 15edbef..8329b35 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -62,6 +62,7 @@ module "apim" { count = var.enable_apim ? 1 : 0 source = "./modules/apim" location = azurerm_resource_group.rg.location + resource_group_id = azurerm_resource_group.rg.id resource_group_name = azurerm_resource_group.rg.name apim_name = local.apim_name apim_subnet_id = module.vnet.apim_subnet_id diff --git a/infra/modules/apim/main.tf b/infra/modules/apim/main.tf index 1f0fb8a..610267e 100644 --- a/infra/modules/apim/main.tf +++ b/infra/modules/apim/main.tf @@ -3,14 +3,10 @@ locals { backend_url = "${var.openai_service_endpoint}openai" } -data "azurerm_resource_group" "rg" { - name = var.resource_group_name -} - resource "azapi_resource" "apim" { type = "Microsoft.ApiManagement/service@2023-05-01-preview" name = var.apim_name - parent_id = data.azurerm_resource_group.rg.id + parent_id = var.resource_group_id location = var.location identity { type = "SystemAssigned" @@ -172,7 +168,6 @@ resource "azurerm_api_management_api_policy" "policy" { XML - depends_on = [azurerm_api_management_backend.openai, azapi_resource.apim_backend_pool] } # https://github.com/aavetis/azure-openai-logger/blob/main/README.md diff --git a/infra/modules/apim/variables.tf b/infra/modules/apim/variables.tf index 9f3426f..6e9c6f5 100644 --- a/infra/modules/apim/variables.tf +++ b/infra/modules/apim/variables.tf @@ -1,4 +1,5 @@ variable "resource_group_name" {} +variable "resource_group_id" {} variable "location" {} variable "apim_name" {} variable "publisher_name" {}