Comments (11)
I think subnets[] may be something we need to except, but in this case I think using json('null') is correct?
from arm-ttk.
Not sure subnets[] would work. As it can be different resources that take an array. Firewall rules for example.
Are you saying json('null') should work? Sure I tried it, but can try again might have been the union function that didn't like it.
Can give it another go tomorrow.
from arm-ttk.
oic - it's flagging the empty variable...
Instead of an empty variable use: json('[]') in your "else" side of the if() statement
from arm-ttk.
So json('[]')
:
"subnets": "[union(variables('defaultSubnets'),if(parameters('deployVnetGateway'), variables('vnetGatewaySubnet'),json('[]') ),if(parameters('deployBastion'), variables('bastionSubnet'),json('[]') ))]",
Fails ARM-TTK due to empty value.
and json('null')
:
"subnets": "[union(variables('defaultSubnets'),if(parameters('deployVnetGateway'), variables('vnetGatewaySubnet'),json('null') ),if(parameters('deployBastion'), variables('bastionSubnet'),json('null') ))]",
Gives:
Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template variable 'subnets' is not valid: Template language function 'union' expects parameters of
| the same type, but found multiple types..
from arm-ttk.
Very similar needs for us
We need to "transform" a variable list of parameters into an array so we use this kind of thing (which is simplified to illustrate here) :
[union(array('val'),if(empty(parameters('param')),json('[]'),array(parameters('anotherVal'))))]
this is failing because json('[]') is considered as an empty property for "Template Should Not Contain Blanks"
There is probably alternative way to do achieve that without json('[]'), at a price of a much more complex logic to follow
from arm-ttk.
Ack... json('[]') was working for me (i.e. tests didn't flag it) due to user error (I used it in an output which is already excepted). Anyway....
So I could think of a few options here:
-
allow certain variable names to be empty
Generally I think if you use an empty Var you know why you're doing it and it's intentional... the flip side is that you would miss come cases where you don't want it directly assigned to a property. So I could say any variable that is named something like "empty*" would be ignored by the test. That requires you to know about the "magic" naming convention to bypass the test -
except the json() function specifically
Indirectly we do this for json('null') today, we could do it (easily) for any time the empty json is not preceded by colon. This would required the template author to use the json() function anytime you want to use empty... it would also mean the test would not flag incorrect use of empty, but that's extremely rare in practice.
I think I like #2 - thoughts?
from arm-ttk.
or both?
from arm-ttk.
I am not the initial reporter of the issue, but I also like #2 :)
from arm-ttk.
2 works for me. Unless there are instances other than empty arrays that can be dealt with using the same logic, such as '{}'.
from arm-ttk.
yes, I think the logic would work the same for empty objects, strings, nulls... So the cases we would catch are where you literally specify an empty property (regardless of type)... which TBH is the common case and the common mistake. If you've authored it as an expression, you're intentionally doing so.
from arm-ttk.
added an approach in #62
from arm-ttk.
Related Issues (20)
- Outputs Must Be Present In Template Parameters HOT 1
- Failing to validate Azure Front Door ARM property HOT 2
- Bug with "Parameter Types Should Be Consistent" test HOT 1
- Bug with "PasswordBoxes-Must-Have-Min-Length" test HOT 1
- Conditional bicep module parameters causing "Parameter Types Should Be Consistent" to fail HOT 5
- The issue "The resource 'xxx' is not defined in the template" is not detected HOT 1
- arm-ttk reporting error for using latest version of backupVaults and it's sub resources HOT 1
- Does not work with Microsoft.KubernetesConfiguration/extensions apiVersion 2023-05-01 HOT 3
- Parameter Types Should Be Consistent test fails when nested deployment array parameter element values includes 1 template parameter value HOT 2
- Empty property false positives with nested forms HOT 2
- Group-Object InnerTemplateName is failing with error Index (zero based) must be greater than or equal to zero and less than the size of the argument list HOT 5
- System.Collections.Generic.KeyNotFoundException: The given key 'file:///D:/a/1/s/source/bicep/.avm/res/sql/server/database/backup-short-term-retention-policy/main.bicep' was not present in the dictionary. HOT 4
- extensionResourceId from Bicep flagged in ARM-TTK
- $IsMainTemplate not properly passed down to scripts, resulting in false positives
- arm-ttk does not seem to recognize an outputs reference to a DropDown living inside an EditableGrid's column HOT 2
- arm-ttk does not recognize steps('basics').elementName as synonymous with basics('elementName')
- arm-ttk does not flag default passwords
- arm-ttk does not recognize parameters/variables references when the parameter/variable name is non-constant
- arm-ttk applies "CreateUIDefinition Must Not Have Blanks" test to user data
- Arm TTK : URIs Should Be Properly Constructed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arm-ttk.