Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.23k stars 748 forks source link

Allow including content from an external file #558

Closed smokedlinq closed 4 years ago

smokedlinq commented 4 years ago

For resources like Logic Apps and API Management, there are some properties that include large amounts of json/xml for definitions/policies that are often easier to maintain in a separate file. Today I have to use a script to collect all of them and include them as parameters. I'd rather the generated ARM template just include the content from the file so I could then just deploy with fewer parameters being needed.

Example using parameters to pass the XML file content today without the feature (minus the scripts required to discover the parameters, and dynamically generate the parameters file or args:

param policyXml string

resource policy 'Microsoft.ApiManagement/service/products/policies@2019-12-01' = {
    name: concat(serviceName, '/my-product')
    properties: {
        value: policyXml
        format: 'rawxml'
    }
}

Example using content loaded by bicep inline, the @ (I used this because it's what I use in azcli) being whatever identifier/keyword to read the content of the file (relative paths are relative to the bicep file being processed, module includes will still be relative to the module bicep file) into the output, in this case assigned to a variable:

var policyXml string = @my-product.policy.xml

resource policy 'Microsoft.ApiManagement/service/products/policies@2019-12-01' = {
    name: concat(serviceName, '/my-product')
    properties: {
        value: policyXml
        format: 'rawxml'
    }
}

Another alternative use would be something like this that directly inline it to the value of the value property:

resource policy 'Microsoft.ApiManagement/service/products/policies@2019-12-01' = {
    name: concat(serviceName, '/my-product')
    properties: {
        value: @my-product.policy.xml
        format: 'rawxml'
    }
}

For values that require JSON objects, I would hope something like json(@my-logic-app.json) would work.

smokedlinq commented 4 years ago

Closing as a duplicate of #471