How to set azure policies to specific operations when the operations where generated with terraform?

wout swennen 11 Reputation points
2022-11-26T12:53:23.443+00:00

We are trying to implement an apim in Azure. For content validation agains an xml we want to have the policies on operation level. The problem is that the operations are generated with the use of wsdl’s.

resource "azurerm_api_management_api" "service_api" {
name = "Service"
resource_group_name = data.azurerm_resource_group.rg.name
api_management_name = data.azurerm_api_management.apim.name
revision = "1"
display_name = "Service"
path = "service"
protocols = ["https"]
api_type = "soap"

import {
content_format = "wsdl"
content_value = file("${path.module}/Service.wsdl")
wsdl_selector {
service_name = "Service"
endpoint_name = "ServicePort"
}
}
}
This way the operation_id is generated and we have no idea to get this operation_id.

resource "azurerm_api_management_api_operation_policy" "operation_policy" {
api_name = azurerm_api_management_api.service_api.name
api_management_name = data.azurerm_api_management.apim.name
resource_group_name = data.azurerm_resource_group.rg.name
operation_id = "7881e744f10c3f142c5a1cca"
xml_content = <<XML
<policies>
<policy stuff>
</policies>
XML
}
Is there any way we can get this operation_id with (data sources) or to set this operation_id while also generating the operations with an WSDL.

Sorry for the hard question and I hope its explained clearly
Thanks in advance

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,751 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
793 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JananiRamesh-MSFT 21,091 Reputation points
    2022-11-30T18:04:31.41+00:00

    Hi @wout swennen Thanks for reaching out. From the description i understand that you wanted to know how to get the operation id to set the policy to specific operations. Operation ids are automatically generated, you can use the below Rest api call after importing the API's and see what operations are available and get the name property to identify the intended operation for which you want to set the policy.
    https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/api-operation/list-by-api?tabs=HTTP
    I am not sure if terraform has ability to call REST API and parse the response you can also use powershell commands to fetch the operation ids.

    do let me know incase of further queries, I would be happy to assist you.

    0 comments No comments

  2. 2022-12-07T11:22:47.067+00:00

    azurerm_api_management_api" "service_api" {
    name = "Service"
    resources_group_name = data.azurerm_resource_group.rg.name
    api_management_name = data.azurerm_api_management.apim.name
    revision = "1"
    display_name = "Service"
    path = "service"
    protocols = [" https "]
    api_type

    0 comments No comments