Replicate Environment from one environment to others

Sourav 165 Reputation points
2024-03-07T11:27:16.3133333+00:00

I'm trying to replicate my local infrastructure to dev.
The template I'm getting for a resource is not my desired type.
My local resources had -local appended to the resources name.
i.e. sb-planability-local
when I'm exporting the template, it gives:

"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "namespaces_sb_planability_local_name": {
            "defaultValue": "sb-planability-local",
            "type": "String"
        }
    },
    "variables": {},
.....

The parameter has -local in it with the default value of my local service bus name.
What would be the recommended way to generate/create a template so that I can use for every environment with preferred appended environment name i.e. sb-planability-dev, sb-planability-demo and the parameter name to be environment specific i.e. namespaces_sb_planability_dev_name, namespaces_sb_planability_demo_name.

Any suggestion would have been very helpful.

Thanks

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
568 questions
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 22,466 Reputation points
    2024-03-15T16:17:34.92+00:00

    @Sourav Thanks for reaching out. You can achieve this by using parameters in your ARM templates. Instead of hardcoding the resource names in the template, you can define parameters for the parts of the name that change per environment. Here’s an example of how you can modify your template:

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "environment": {
          "type": "string",
          "metadata": {
            "description": "The name of the environment. e.g. dev, demo"
          }
        }
      },
      "variables": {
        "serviceBusName": "[concat('sb-planability-', parameters('environment'))]"
      },
      ...
    }
    

    In this template, environment is a parameter that you provide when deploying the template. The serviceBusName variable concatenates ‘sb-planability-’ with the value of the environment parameter. This way, you can use the same template for different environments by just changing the environment parameter during deployment.

    For example, if you want to deploy to the dev environment, you would provide ‘dev’ as the environment parameter.

    do let me know incase of further queries, I would be happy to assist you.

    0 comments No comments

0 additional answers

Sort by: Most helpful