Search code examples
azure-bicep

Include an object from another file into main bicep template


I have a file "test.bicep" that has an object:

{
  name: 'testRafaelRule'
  priority: 1001
  ruleCollectionType: 'FirewallPolicyFilterRuleCollection'
  action: {
    type: 'Allow'
  }
  rules: [
    {
      name: 'deleteme-1'
      ipProtocols: [
        'Any'
      ]
      destinationPorts: [
        '*'
      ]
      sourceAddresses: [
        '192.168.0.0/16'
      ]
      sourceIpGroups: []
      destinationIpGroups: []
      destinationAddresses: [
        'AzureCloud.EastUS'
      ]            
      ruleType: 'NetworkRule'
      destinationFqdns: []
    }
  ]
}

and I have another file, in which I am trying to somehow input the object in test.bicep into a specific property called "ruleCollections":

resource fwll 'Microsoft.Network/firewallPolicies/ruleCollectionGroups@2020-11-01' = {  
  name: 'netrules'  
  properties: {
    priority: 200
    ruleCollections: [
      **ADD_OBJECT_FROM_TEST.BICEP_HERE_HOW?**
    ]
  }
}

I have looked at outputs and parameters, but I am trying to add just an object into an existing property, I am not adding an entire resource on its own, otherwise, I would output the resouce and consume it with the "module" keyword.


Solution

  • It's not possible straightforward, but you can leverage variables or module's output.

    var RULE = {
      name: 'testRafaelRule'
      priority: 1001
    (...)
    }
    
    resource fwll 'Microsoft.Network/firewallPolicies/ruleCollectionGroups@2020-11-01' = {  
     name 'netrules'
     properties: {
      ruleCollections: [ 
       RULE
      ]
     }
    }
    

    or

    rule.bicep

    output rule object = {
      name: 'testRafaelRule'
      priority: 1001
    (...)
    }
    

    main.bicep

    module fwrule 'rule.bicep' = {
     name: 'fwrule'
    }
    resource fwll 'Microsoft.Network/firewallPolicies/ruleCollectionGroups@2020-11-01' = {  
     name 'netrules'
     properties: {
      ruleCollections: [ 
       fwrule.outputs.rule
      ]
     }
    }