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

linter should catch non-optimal scope references #2278

Open
alex-frankel opened this issue Apr 15, 2021 · 2 comments
Open

linter should catch non-optimal scope references #2278

alex-frankel opened this issue Apr 15, 2021 · 2 comments
Labels
devdiv Related to Bicep tooling efforts in DevDiv enhancement New feature or request story: linter rules

Comments

@alex-frankel
Copy link
Collaborator

If you don't have a proper reference to a resource group (or other scope), you can provide a scope using the relevant scope function:

module foo '...' = {
  scope: resourceGroup('my-rg')
  ...
}

However, if you do have a reference, it is better to use that reference directly. This is a newer capability so there are old examples out there that use the previous way we exposed.

This is ideal if you have a reference:

resource rg 'microsoft.resources/resourceGroups@2020-06-01' = { ... }

module foo '...' = {
  scope: rg
  ...
}

But in practice we often see this less ideal pattern:

resource rg 'microsoft.resources/resourceGroups@2020-06-01' = { ... }

module foo '...' = {
  scope: resourceGroup(rg.name)
  ...
}
@alex-frankel alex-frankel added the enhancement New feature or request label Apr 15, 2021
@ghost ghost added the Needs: Triage 🔍 label Apr 15, 2021
@majastrz
Copy link
Member

It should work for MGs this way as well once we fix #1833.

@alex-frankel
Copy link
Collaborator Author

If possible, it would be great to catch this scenario as well, where the rgName param is used for the RG declaration and the scope for the module:

targetScope = 'subscription'

param rgName string

resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  name: rgName
  location: deployment().location
}

module foo 'appPlan.bicep' = {
  scope: resourceGroup(rgName)
}

@StephenWeatherford StephenWeatherford added the devdiv Related to Bicep tooling efforts in DevDiv label Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devdiv Related to Bicep tooling efforts in DevDiv enhancement New feature or request story: linter rules
Projects
None yet
Development

No branches or pull requests

4 participants