skip to Main Content

I have a module that have named value resources and another module that have api and operation resources. I have then a bicep file (main.bicep) that will call the both files. A shorten version (just to make it easier to exaplain):

namedValue module:

param apimServiceName string
param namedvalues_prefix string
param aud string

resource apimService 'Microsoft.ApiManagement/service@2022-09-01-preview' existing = {
  name:apimServiceName
}


//named values:
resource la_triggerurl 'Microsoft.ApiManagement/service/namedValues@2022-08-01' = {
  parent: apimService
  name: '${namedvalues_prefix}-url'
  properties: {
    displayName: '${namedvalues_prefix}-url'
    secret: true
    value: workflow_triggerUrl
  }
}

//...

api module:

param apimServiceName string
param apiName string


resource apimService 'Microsoft.ApiManagement/service@2022-09-01-preview' existing = {
  name:apimServiceName
}


resource apiOperationSend 'Microsoft.ApiManagement/service/apis/operations@2022-09-01-preview' = {
  parent: api
  name: 'send'
  properties: {
    displayName: 'Send'
    method: 'POST'
    urlTemplate: '/send'
    templateParameters: []
    responses: []
  }
}

resource apiPolicySend 'Microsoft.ApiManagement/service/apis/operations/policies@2022-09-01-preview' = {
  parent: apiOperationSend
  name: 'policy'
  properties: {
    value: loadTextContent('../Policies/policy.xml')
  }
}

// main.bicep:

param aud string

var apimServiceName = 'apim'
var apimRg = 'apim-rg'


module namedValues 'Modules/namedvalues.bicep' = {
  name: 'namedValue'
  scope:resourceGroup(apimRg)
  params: {
    apimServiceName: apimServiceName
    namedvalues_prefix: 'somePrefix'
    aud:aud
  }
}

// The api and its resources need to be deployed after the deployment of the named values
module apiModule 'Modules/apiAndOperations.bicep' = {
  name:'apiDeployment'
  scope:resourceGroup(apimRg)
  params:{
    apiName:'personnelfromoracleint'
    apimServiceName:apimServiceName
  }
}

The issue is I need the named value module to be deployed before the api module because these namedvalues are used in the policies inside the policy.xml file.

I have thus tried to have a parent: namedValues field in main.bicep when calling the apiModule but VS code gave me this error:

The property "parent" is not allowed on objects of type "module". Permissible properties include "dependsOn"

When I tried to use dependsOn: namedValues instead it gave me this error:

The property "dependsOn" expected a value of type "(module[] | (resource | module) | resource[])[]" but the provided value is of type "module"

Any suggestion for how to solve this issue?

2

Answers


  1. Chosen as BEST ANSWER

    Ok I think I have found the answer. I have only needed to put the dependencies between []. So, simple just write:

      dependsOn: [namedValues]
    

    I thought the error message means that we are not allowed to make modules dependednt on each other


  2. You can use the dependsOn block in the resource to add explicit dependencies, however bicep also works by building the dependency graph for you if you refer to dependant resources in the right way. This implicit method is nicer and requires less lines of code.

    eg.

    Add output apimName string = apimService.name to your api module. Then refer to it in your namedValues declaration with apiModule.outputs.apimName.

    module namedValues 'Modules/namedvalues.bicep' = {
      name: 'namedValue'
      scope:resourceGroup(apimRg)
      params: {
        apimServiceName: apiModule.outputs.apimName
        namedvalues_prefix: 'somePrefix'
        aud:aud
      }
    }
    
    named values
    module apiModule 'Modules/apiAndOperations.bicep' = {
      name:'apiDeployment'
      scope:resourceGroup(apimRg)
      params:{
        apiName:'personnelfromoracleint'
        apimServiceName:apimServiceName
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search