Search code examples
jsonazureazure-resource-managerazure-resource-group

Predefined Resource Group in ARM Template


I'm working on a custom arm template.

I would like to have specific resource group to be hard coded inside the JSON so when opening the template it will simulate "Resource Group: Use existing: predefined selected Resource group"

I've been scratching my head for hours and searched the web deeply, I also tried to export existing resource group template and import it to custom deployment but it still shows

Resource Group *Create New *Use Existing

Is there any way to define existing RG inside the JSON template?


Solution

  • there are several ways to achieve this (not that it makes sense, but you can do this).

    1. Use automation around the template to always deploy it to the same rg. this makes most sense as your template stays flexible
    2. wrap your template with a parent template (so "convert" your template to a nested template). that way the parent template can control to which resource group your nested template gets deployed (look for cross resource group ARM Template deployments).
    3. Make your template a nested inline template (worst case). this is pretty much the same as point 2, but kinda worse, because nested inline templates have this peculiar drawback of not being able to use their own parameters\variables, only the ones defined in the parent.

    Again, none of this makes sense as you should just deploy it to the proper subscription\resource group combination. but there you have it, if you insist.

    But the portal experience will stay the same (there is no way of working around that, you can forcé the template to always deploy to the same resource group (not that it makes any sense), but not alter the portal experience), if thats what you are concerned about.