Search code examples
azure-blob-storageazure-api-managementazure-rm-template

Accessing Blob content from within ARM Template for API Management API GraphQL Schema


The GraphQL schema content is large so would like to store in blob container and access it from API Management ARM Template to obtain its contents. I already store linked templates in same area and have enough detail to compose the URI with SAS Token . The issue I have is getting the contents from the blob and loading them into a string variable. Whatever I try I cannot access the contents.

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "ApimServiceName": {
        "type": "string"
    },
    "appInsightsName": {
        "type": "string"
    },
    "_artifactsLocation" : {
        "type": "string"
    },
    "_artifactsLocationSasToken" :{
        "type": "string"
    },
    "_buildNumber" :{
        "type": "string"
    },
    "KeyvaultName": {
         "type": "string"
    }
},
"variables": {
    "linkedSchemas": {
        "schemauri": "[concat(parameters('_artifactsLocation'), parameters('_buildNumber'), '/sample-graphql-schema.graphql',parameters('_artifactsLocationSasToken'))]"
    }
},
"resources": [
    {
        "apiVersion": "2021-08-01",
        "type": "Microsoft.ApiManagement/service/apis",
        "name": "[concat(parameters('ApimServiceName'), '/graphql-sample')]",
        "dependsOn": [],
        "properties": {
            "description": "",
            "authenticationSettings": {
                "subscriptionKeyRequired": false
            },
            "subscriptionKeyParameterNames": {
                "header": "Ocp-Apim-Subscription-Key",
                "query": "subscription-key"
            },
            "type": "graphql",
            "apiRevision": "1",
            "subscriptionRequired": true,
            "displayName": "GraphQL API",
            "serviceUrl": "https://emea.sample.com/api/graphql",
            "path": "graphql-sample",
            "protocols": [
                "http",
                "https"
            ]
        }
    },
    {
        "apiVersion": "2021-08-01",
        "type": "Microsoft.ApiManagement/service/apis/schemas",
        "name": "[concat(parameters('ApimServiceName'), '/graphql-sample/graphql')]",
        "dependsOn": [
            "[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'graphql-sample')]"
        ],
        "properties": {
            "contentType": "application/vnd.ms-azure-apim.graphql.schema",
            "document": {
                "value": "[concat('data:text/plain;charset=utf-8;base64,', base64(variables('linkedSchemas').schemauri))]"
            }
        }
    }, etc...

Can anyone share how to obtain the contents of the blob? Perhaps I need to find a different way to access the blob. All the code does as it stands is turn the URI itself into base64.


Solution

  • ARM Templates on their own do does not support fetching values from a URL as far as I know. But APIM Templates do support passing in values, which the service can fetch contents for.

    For this, you don't need the Microsoft.ApiManagement/service/apis/schemas sub-resource, instead the Microsoft.ApiManagement/service/apis resource itself has properties that you need to set.

    • format should be set to graphql-link
    • value should be set to the URL of your GraphQL Schema File including the SAS Token

    Refer the reference doc for more information.