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

use-resource-id-functions linter rule not spotting if conditional that is wrapped in parens ( ) #8410

Closed
jtracey93 opened this issue Sep 15, 2022 · 9 comments · Fixed by #8445
Assignees
Labels
devdiv Related to Bicep tooling efforts in DevDiv story: linter
Milestone

Comments

@jtracey93
Copy link

jtracey93 commented Sep 15, 2022

Bicep version

0.10.61

Describe the bug
use-resource-id-functions linter rule not spotting if conditional that is wrapped in brackets ( )

Error message: If property "id" represents a resource ID, it must use a symbolic resource reference, be a parameter or start with one of these functions: extensionResourceId, guid, if, reference, resourceId, subscription, subscriptionResourceId, tenantResourceId.

To Reproduce

See snippet below

resource resTopLevelMg 'Microsoft.Management/managementGroups@2021-04-01' = {
  name: parTopLevelManagementGroupPrefix
  properties: {
    displayName: parTopLevelManagementGroupDisplayName
    details: {
      parent: {
        // Causes linter to flag even though this is an `if` condition - Not Working (triggers linter rule)
        id: (empty(parTopLevelManagementGroupParentId) ? '/providers/Microsoft.Management/managementGroups/${tenant().tenantId}' : parTopLevelManagementGroupParentId)
        
        // Passes linter validation - WORKS
        id: empty(parTopLevelManagementGroupParentId) ? '/providers/Microsoft.Management/managementGroups/${tenant().tenantId}' : parTopLevelManagementGroupParentId
      }
    }
  }
}

Additional context

Should we be wrapping the if conditional in brackets ( ), struggling to find do/dont's? Around this anywhere in docs?

Related to ALZ-Bicep PR: Azure/ALZ-Bicep#318 (updating linter rules to latest)

@alex-frankel
Copy link
Collaborator

Possibly another false positive. Thanks for reporting.

@jtracey93
Copy link
Author

@alex-frankel no problem, anytime.

Any thoughts on the uses of parentheses () here thats causing it? Have we just got them where we don't need them (aware thats not the linter rules concern here, but it is causing it)?

Maybe another linter rule idea "unrequired parentheses" etc.?

@jtracey93
Copy link
Author

tagging @DaFitRobsta for PR awareness in ALZ-Bicep

@alex-frankel
Copy link
Collaborator

Oh sorry I missed that piece. These parens are a no-op, so I would recommend removing them. I agree this would be a helpful linter rule.

@alex-frankel alex-frankel removed this from the v0.11 milestone Sep 15, 2022
@alex-frankel alex-frankel changed the title use-resource-id-functions linter rule not spotting if conditional that is wrapped in brackets ( ) use-resource-id-functions linter rule not spotting if conditional that is wrapped in parens ( ) Sep 15, 2022
@jtracey93
Copy link
Author

No worries, thanks for the rapid response. We'll update our code our end in ALZ-Bicep.

But this is still a bug that we probably want to handle on this linter rule.

Do you want me to open a new issue for the new suggestion of the linter rule?

@alex-frankel
Copy link
Collaborator

I'm going to add triage back and we can discuss it next week. I'm not sure if we should do one or the other or both.

@StephenWeatherford
Copy link
Contributor

Parens shouldn't matter, think it should be noticing the use of tenant().tenantId anywhere in the expression.

@StephenWeatherford StephenWeatherford added the devdiv Related to Bicep tooling efforts in DevDiv label Sep 15, 2022
@StephenWeatherford
Copy link
Contributor

Dup of #8104 (but thanks for reporting)

@StephenWeatherford
Copy link
Contributor

Reopening since there is something weird going on with the parens...

Repository owner moved this from Todo to Done in Bicep Sep 22, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
devdiv Related to Bicep tooling efforts in DevDiv story: linter
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants