-
Notifications
You must be signed in to change notification settings - Fork 756
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
Resource is getting deployed even though the if condition makes it false thereby giving error resource defined multiple times #7561
Comments
I believe the template validation engine will run prior to any conditions being evaluated, so this behavior is expected. For example, I get the same error when trying to deploy a template with boolean constant conditions: For the specific scenario you describe, it looks like the difference between resource initiativeDefinitionPolicyAssignment 'Microsoft.Authorization/policyAssignments@2019-09-01' = [for policy in initiativeDefinition: {
name: policy.name
identity: {
type: 'SystemAssigned'
}
location: location
properties: union(
{
scope: resourceGroup().id
enforcementMode: 'Default'
policyDefinitionId: policy.id
},
policy.isParameterized ? {parameters: policy.para} : {}
)
}] |
@jeskew Oh okay makes sense, Thank you so much that helps :) |
@jeskew can we close this or we have something to do here? |
@miqm There's some overlap between this issue and #2371 (if we were to solve the issue in the ARM runtime), but we may be able to improve the user experience here by not emitting resources whose condition is known to be false at compile time. The latter would probably require #444 to be completed first, but it's worth discussing at triage. |
I'm going to close this as a dup of #2371 |
Bicep version
v0.8.9
Describe the bug
Resource is getting deployed even though the if condition makes it false.
Trying to do policy assignments with parameters & one without parameters, have the name & ids in an array but inspite of having bool false value the resource is getting deployed which is throwing an error .
{"error":{"code":"InvalidTemplate","message":"Deployment template validation failed: 'The resource 'Microsoft.Authorization/policyAssignments/Azure Security Benchmark' at line '1' and column '785' is defined multiple times in a template. Please see https://aka.ms/arm-template/#resources for usage details.'.","additionalInfo":[{"type":"TemplateViolation","info":{"lineNumber":1,"linePosition":785,"path":"properties.template.resources[0]"}}]}}
To Reproduce
Steps to reproduce the behavior:
Additional context
Not sure if this is a bug or my code issue i am just staring out with Bicep, any help would be appreciated. Thank you :)
The text was updated successfully, but these errors were encountered: