-
Notifications
You must be signed in to change notification settings - Fork 774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to create resource group and it's resources in single Bicep file without use of module #1431
Comments
This should be feasible with the latest contribution #1420 (pending release). With that you should be able to represent a subscription level deployment that:
|
@stan-sz - Am I missing something, or does that still require the use of modules? This issue is aimed at having the ability to create the RG and all of its resources within a single file (no modules). |
No modules are optional way to structure and organize. If looking to do this all in one file, I'm assuming after release, the code will look like:
Can include whatever tags and then deploy the .json at the subscription level as noted above. |
I think this issue is specifically tracking the ability to both declare and consume a module in one file - to avoid necessitating a multi-file solution for some simple scenarios. E.g. something like the following (pseudocode, but all in one file): targetScope = 'subscription'
// deploy an rg
resource rg 'Microsoft.Resources/resourceGroups@2020-06-01' = {
name: 'rg-test-dev-eus'
location: 'eastus'
}
// consume the below module declaration in this file, and deploy it to the newly-created rg
module myMod 'rgcontents' = {
name: 'myMod'
scope: resourceGroup(rg.name)
params: {
myTags: {
a: 'b'
}
}
}
// declare the module in the same file
moduledecl 'rgcontents' = {
targetScope = 'resourceGroup'
param myTags object = {}
resource xyz 'My.Rp/a@2020-01-01' = {
name: 'xyz'
tags: myTags
...
}
} |
I think it would be much simpler to allow this without the use of any (sub-)modules. I'd like to create the resource group and its resources in one file that uses If we had to use sub-modules like in the example above, we'd still have to pass parameters around which seems like a lot of overhead for simple resource groups. It's already possible to do this when referencing existing resources so it would be great to also allow this for new resources. targetScope = 'subscription'
param location string = 'westeurope'
// I can already reference existing groups
resource existingGroup 'Microsoft.Resources/resourceGroups@2021-04-01' existing = {
name: 'existing-group'
}
// I can already reference existing resources in those groups
resource existingSubnet 'Microsoft.Network/virtualNetworks/subnets@2022-01-01' existing = {
name: 'existing-vnet/existing-subnet'
scope: existingGroup
}
// I can already create new resource groups
resource newGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: 'new-group'
location: location
}
// But I can NOT create new resources in this group.
resource vault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: 'mystorage'
location: location
// Here I would just like to specifiy the resource group for the new resource
scope: newGroup // or maybe "parent: newGroup"?!
properties: {
sku: {
name: 'standard'
family: 'A'
}
tenantId: subscription().tenantId
networkAcls: {
virtualNetworkRules: [
{
id: existingSubnet.id
}
]
}
}
}
|
While not a single-file solution, #4158 would also help make the resource group creation easier. |
This would simplify the very common scenario of creating a resource group, then create resources within it. The resource group is either left out and created via CLI first OR the workaround is to set targetScope to subscription, create resource group resource, then use a module to create the resources within the resource group. For simplicity's sake, I should be able to create all of my infrastructure in a single file.
The text was updated successfully, but these errors were encountered: