bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Autogenerating modules when target scope is not resource group

Open antsok opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. When I develop an end-2-end solution and use a resource group as a lifecycle boundary to keep all my resources in it, I use a single bicep to create one or more resource groups and resources within them. Subscription becomes my target scope.

Now, with subscription as a target scope, it is not possible to use 'resource'. (Scope "subscription" is not valid for this resource type. Permitted scopes: "resourceGroup").

So I am forced to use modules even if the code won't be reused. This leads to the sprawling of unneeded files.

Describe the solution you'd like I would like a way for bicep to not require me to create a module if I don't need it, and do this for me instead. Kind of autogenerating a module.

Ideally, the only additional param needed for a resource is the RG scope. So it could look something like this:

resource projectRG 'Microsoft.Resources/resourceGroups@2021-04-01' = {
...
}

resource storageaccount 'Microsoft.Storage/storageAccounts@2021-02-01' scope:projectRG = {
...
}

antsok avatar May 28 '22 12:05 antsok

Related to #4555

alex-frankel avatar May 31 '22 15:05 alex-frankel

Hi @antsok — thank you for the detailed write-up and the clear example, and apologies for the long wait here.

This fits with a cluster of closely-related requests around declaring and consuming modules inline / in a single file, so I wanted to link them together for context: #1431 (create a resource group and its resources in one file at subscription scope) and #4555 (inline modules), which @alex-frankel had already connected this to, along with the broader #2505. I'll leave this open and keep it grouped with those so the scenarios are tracked together. If you have additional detail on the "autogenerate the module for me" angle specifically, it's very welcome here. Thanks again!

torreymicrosoft avatar Jun 10 '26 22:06 torreymicrosoft