From 8bac84c593d3d365f9aade504f5e06a743eda6d0 Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 5 Mar 2024 17:39:04 +0100 Subject: [PATCH] [VAS-506] updated infra to create dedicate apim product for backoffice external and helpdesk --- infra/04_apim_api.tf | 150 +++++++++++++++++++++++++++++++++---------- infra/99_locals.tf | 1 - 2 files changed, 116 insertions(+), 35 deletions(-) diff --git a/infra/04_apim_api.tf b/infra/04_apim_api.tf index 115f796..7b1b522 100644 --- a/infra/04_apim_api.tf +++ b/infra/04_apim_api.tf @@ -1,64 +1,146 @@ locals { - repo_name = "pagopa-backoffice-external" + apim_backoffice_external_api = { + // Backoffice External + display_name = "Selfcare Backoffice External Product pagoPA" + description = "API for Backoffice External" + path = "backoffice/external" + subscription_required = true + service_url = null + } + apim_backoffice_helpdesk_api = { + // Helpdesk + display_name = "Backoffice Helpdesk" + description = "API for helpdesk on Backoffice" + path = "backoffice/helpdesk" + subscription_required = true + service_url = null + } - display_name = "Selfcare Backoffice External Product pagoPA" - description = "API for Backoffice External" - path = "backoffice/external" host = "api.${var.apim_dns_zone_prefix}.${var.external_domain}" hostname = var.hostname } -resource "azurerm_api_management_group" "api_group" { - name = local.apim.product_id +############## +## Products ## +############## + +// Backoffice External user(s) +module "apim_backoffice_external_product" { + source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//api_management_product?ref=v6.4.1" + + product_id = "backoffice-external" + display_name = local.apim_backoffice_external_api.display_name + description = local.apim_backoffice_external_api.description + + api_management_name = local.apim.name resource_group_name = local.apim.rg + + published = true + subscription_required = local.apim_backoffice_external_api.subscription_required + approval_required = true + subscriptions_limit = 1000 + + policy_xml = file("./api_product/backoffice-external/_base_policy.xml") +} + +// Helpdesk +module "apim_backoffice_helpdesk_product" { + source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//api_management_product?ref=v6.4.1" + + product_id = "backoffice-helpdesk" + display_name = local.apim_backoffice_helpdesk_api.display_name + description = local.apim_backoffice_helpdesk_api.description + api_management_name = local.apim.name - display_name = local.display_name - description = local.description + resource_group_name = local.apim.rg + + published = false + subscription_required = local.apim_backoffice_helpdesk_api.subscription_required + approval_required = true + subscriptions_limit = 1000 + + policy_xml = file("./api_product/backoffice-helpdesk/_base_policy.xml") } -resource "azurerm_api_management_api_version_set" "api_version_set" { - name = format("%s-${local.repo_name}", var.env_short) + +############## +## Api Vers ## +############## + +resource "azurerm_api_management_api_version_set" "api_backoffice_external_api" { + + name = format("%s-backoffice-external-api", var.env_short) resource_group_name = local.apim.rg api_management_name = local.apim.name - display_name = local.display_name + display_name = local.apim_backoffice_external_api.display_name versioning_scheme = "Segment" } -module "api_v1" { - source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//api_management_api?ref=v6.7.0" +resource "azurerm_api_management_api_version_set" "api_backoffice_helpdesk_api" { - name = format("%s-${local.repo_name}", var.env_short) + name = format("%s-backoffice-helpdesk-api", var.env_short) + resource_group_name = local.apim.rg + api_management_name = local.apim.name + display_name = local.apim_backoffice_helpdesk_api.display_name + versioning_scheme = "Segment" +} + + +############## +## OpenApi ## +############## + +module "apim_api_backoffice_external_api_v1" { + source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//api_management_api?ref=v6.4.1" + + name = format("%s-backoffice-external-api", var.env_short) api_management_name = local.apim.name resource_group_name = local.apim.rg - product_ids = [local.apim.product_id] - subscription_required = true + product_ids = [module.apim_backoffice_external_product.product_id] + subscription_required = local.apim_backoffice_external_api.subscription_required + version_set_id = azurerm_api_management_api_version_set.api_backoffice_external_api.id + api_version = "v1" - version_set_id = azurerm_api_management_api_version_set.api_version_set.id - api_version = "v1" - - description = local.description - display_name = local.display_name - path = local.path + description = local.apim_backoffice_external_api.description + display_name = local.apim_backoffice_external_api.display_name + path = local.apim_backoffice_external_api.path protocols = ["https"] - - service_url = null + service_url = local.apim_backoffice_external_api.service_url content_format = "openapi" - content_value = templatefile("../openapi/openapi.json", { + content_value = templatefile("./api/backoffice-external/v1/_openapi.json.tpl", { host = local.host }) - xml_content = templatefile("./policy/_base_policy.xml", { - hostname = var.hostname + xml_content = templatefile("./api/backoffice-external/v1/_base_policy.xml", { + hostname = local.hostname }) +} - api_operation_policies = [ - { - operation_id = "getCreditorInstitutions", - xml_content = templatefile("./api/pagopa-backoffice-external/_get_broker_institutions_policy.xml", {}) - }, - ] +module "apim_api_backoffice_helpdesk_api_v1" { + source = "git::https://github.com/pagopa/terraform-azurerm-v3.git//api_management_api?ref=v6.4.1" -} + name = format("%s-backoffice-helpdesk-api", var.env_short) + api_management_name = local.apim.name + resource_group_name = local.apim.rg + product_ids = [module.apim_backoffice_helpdesk_product.product_id] + subscription_required = local.apim_backoffice_helpdesk_api.subscription_required + version_set_id = azurerm_api_management_api_version_set.api_backoffice_helpdesk_api.id + api_version = "v1" + description = local.apim_backoffice_helpdesk_api.description + display_name = local.apim_backoffice_helpdesk_api.display_name + path = local.apim_backoffice_helpdesk_api.path + protocols = ["https"] + service_url = local.apim_backoffice_helpdesk_api.service_url + + content_format = "openapi" + content_value = templatefile("./api/backoffice-helpdesk/v1/_openapi.json.tpl", { + host = local.host + }) + + xml_content = templatefile("./api/backoffice-helpdesk/v1/_base_policy.xml", { + hostname = local.hostname + }) +} \ No newline at end of file diff --git a/infra/99_locals.tf b/infra/99_locals.tf index 5ed42d0..3763646 100644 --- a/infra/99_locals.tf +++ b/infra/99_locals.tf @@ -4,7 +4,6 @@ locals { apim = { name = "${local.product}-apim" rg = "${local.product}-api-rg" - product_id = "TODO" # TODO product id to import from pagopa-infra } }