Skip to content
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

Open
MarcusFelling opened this issue Feb 1, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@MarcusFelling
Copy link
Collaborator

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.

@MarcusFelling MarcusFelling added the enhancement New feature or request label Feb 1, 2021
@ghost ghost added the Needs: Triage 🔍 label Feb 1, 2021
@MarcusFelling MarcusFelling added this to the v0.4 milestone Feb 1, 2021
@stan-sz
Copy link
Contributor

stan-sz commented Feb 2, 2021

This should be feasible with the latest contribution #1420 (pending release). With that you should be able to represent a subscription level deployment that:

  • creates a RG within the same subscription
  • creates resources (as modules) in the above RG scope
    See example usages

@MarcusFelling
Copy link
Collaborator Author

@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).

@JFolberth
Copy link
Contributor

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:

resource rg 'Microsoft.Resources/resourceGroups"@2020-06-01' = {
    name: 'rg-test-dev-eus' 
    location: 'eastus'
}

Can include whatever tags and then deploy the .json at the subscription level as noted above.

@anthony-c-martin
Copy link
Member

anthony-c-martin commented Feb 3, 2021

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
    ...
  }
}

@cwe1ss
Copy link

cwe1ss commented Sep 11, 2022

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 targetScope = 'subscription' and just scope the resources to the correct resource group.

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
        }
      ]
    }
  }
}

@stan-sz
Copy link
Contributor

stan-sz commented Sep 26, 2022

While not a single-file solution, #4158 would also help make the resource group creation easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants