Azure / arm-template-whatif

A repository to track issues related to what-if noise suppression
MIT License
90 stars 14 forks source link

Noisy response when deploying API Management APIs under the Product #330

Open vkorvach opened 1 year ago

vkorvach commented 1 year ago

Describe the noise

When redeploying the resources below, what-if shows a 'Create' change for the existing API under the specific Product, as well as some changes in API itself.

Resource type Microsoft.ApiManagement/service/products/apis

apiVersion 2021-12-01-preview

Client Azure CLI

Relevant ARM Template code (we only need the resource object for the above resourceType and apiVersion, but if it's easier you can include the entire template

apim-resources.bicep

param apiManagementServiceName string
param productName string
param apiServices array
param apiManagementPolicyBase64 string

resource apimInstance 'Microsoft.ApiManagement/service@2021-12-01-preview' existing = {
  name: apiManagementServiceName
}

module apisModule 'apim-api.bicep' = [for apiService in apiServices: {
  name: 'apim-api-${apiService.name}'
  params: {
    apimName: apiManagementServiceName
    name: apiService.name
    displayName: apiService.displayName
    serviceUrl: apiService.serviceUrl
    swaggerJsonRelativePath: apiService.swaggerJsonRelativePath
    path: apiService.path
    apiPolicyXml: apiService.apiPolicyXml
  }
}]

resource apimProduct 'Microsoft.ApiManagement/service/products@2021-12-01-preview' = {
  name: '${productName}-product'
  parent: apimInstance
  dependsOn: [ apisModule ]
  properties: {
    subscriptionRequired: false
    displayName: productName
    state: 'published'
  }

  resource apimApi 'apis' = [for apiService in apiServices: {
    name: '${apiService.name}'
  }]
}

apim-api.bicep

param apimName string
param name string
param path string
param displayName string
param serviceUrl string
param swaggerJsonRelativePath string

param apiPolicyXml string

resource apimInstance 'Microsoft.ApiManagement/service@2021-12-01-preview' existing = {
  name: apimName
}

resource apimAPI 'Microsoft.ApiManagement/service/apis@2021-12-01-preview' = {
  name: name
  parent: apimInstance
  properties: {
    path: path
    displayName: displayName
    serviceUrl: 'https://${serviceUrl}'
    format: 'openapi-link'
    apiType: 'http'
    type: 'http'
    isCurrent: true
    protocols: [
      'https'
    ]
    subscriptionRequired: true
    value: 'https://${serviceUrl}${swaggerJsonRelativePath}'    
  }
}

resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2022-04-01-preview' = {
  name: 'policy'
  parent: apimAPI
  properties: {
    format:'xml'
    value: base64ToString(apiPolicyXml)
  }
}

Expected response (i.e. "I expected no noise since the template has not been modified since the resources were deployed)

No changes are reported since no changes were made in-between deployments.

Current (noisy) response (either include a screenshot of the what-if output, or copy/paste the text)

  + Microsoft.ApiManagement/service/xxxxxxxx/products/product-1/apis/api-1 [2021-12-01-preview]

      apiVersion: "2021-12-01-preview"
      id:         "/subscriptions/xxxxxxxx/resourceGroups/rg-1/providers/Microsoft.ApiManagement/service/xxxxxxxx/products/product-1/apis/api-1"
      name:       "api1"
      type:       "Microsoft.ApiManagement/service/products/apis"

~ Microsoft.ApiManagement/service/xxxxxxxx/apis/api-1 [2021-12-01-preview]
    - properties.contact:

        name: "company-1"
        url:  "https://www.company1.com/"

    - properties.description:                          "api-1 description"
    - properties.subscriptionKeyParameterNames.header: "Ocp-Apim-Subscription-Key"
    + properties.type:                                 "http"
    x properties.isCurrent:                            true

Additional context Add any other context about the problem here.