0
votes

My repo has different arm templates (azure deploy json files) for two different environments. Each environment has its own service bus namespace. I want to generate the same list of topics for each environment in the arm template.

I want to keep the service bus namespace name in their perspective arm template, but I'm not sure if I'm doing this the right way.

The list of topics will be in a parameters.json file. I want to use the same parameters file for both environment/templates. I'm also not sure if this is possible. From this article, using the same parameter file may not be do-able.

I used this site as a reference to create the loop of topics.

Here is en example of an armtemplate.json file:

...
 "parameters": {
        "serviceBusNamespaceName": {
            "type": "string",
            "defaultValue": "serviceBusName1",
            "metadata": {
                "description": "Name of the Service Bus namespace"
            }
        },
        "serviceBusTopics": {
            "type": "array",
            "metadata": {
                "description": "List of topics"
            }
        },
...
"resources": [
        {
            "apiVersion": "2017-04-01",
            "name": "[parameters('serviceBusNamespaceName')]",
            "type": "Microsoft.ServiceBus/namespaces",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "Standard"
            },
            "properties": {}
        },
        {
            "apiVersion": "2017-04-01",
            "name": "[concat(parameters('serviceBusNamespaceName'), '/', parameters('serviceBusTopics')[copyIndex()])]",
            "type": "Microsoft.ServiceBus/namespaces/topics",
            "location": "[resourceGroup().location]",
            "copy": {
                "name": "topicLoop",
                "count": "[length(parameters('serviceBusTopics'))]"
            },
            "properties": {},
            "dependsOn": [
                "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceName'))]"
            ]
        },
....

Here is the parameters.json file:

"parameters": {
        "serviceBusTopics": {
            "value": [
                "topic1",
                "topic2"
            ]
        }
    }

I have Azure Pipelines configured to build and deploy the azure resources. When I navigate out to Azure Portal and check each service bus, I expect to see the topics created. However, this is not working for me.

Can I use the same parameter file for different template/environment? Syntactically, do I have any errors?

2

2 Answers

0
votes

one way is to use to parameter files, one for each environment then in your pipeline you specify the correct parameter file

another way is to not use parameter files at all and just use variables from inside Azure DevOps

I realize this is a short answer, hope that is ok for now

0
votes

Because each environment has its own template file, you simply need to update all files with the service bus and topic parameters and list the topics as a resource like I did above. The defaultvalue is sufficient for targeting different service bus. (might not be the most elegant solution but it works)

I found out that the reason why my template was not working initially is because the pipeline that uses the template was not in the same resource group as the service bus I was targeting.

What I did above works when deploying to the same resource group.