Skip to content

Commit

Permalink
Fix updating the Azure API Management (#59)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
rliberoff authored Jun 10, 2024
1 parent 6208a13 commit c60b35d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions infra/modules/apim/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -172,7 +168,6 @@ resource "azurerm_api_management_api_policy" "policy" {
</on-error>
</policies>
XML
depends_on = [azurerm_api_management_backend.openai, azapi_resource.apim_backend_pool]
}

# https://github.com/aavetis/azure-openai-logger/blob/main/README.md
Expand Down
1 change: 1 addition & 0 deletions infra/modules/apim/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
variable "resource_group_name" {}
variable "resource_group_id" {}
variable "location" {}
variable "apim_name" {}
variable "publisher_name" {}
Expand Down

0 comments on commit c60b35d

Please sign in to comment.