GithubHelp home page GithubHelp logo

Comments (11)

bmoore-msft avatar bmoore-msft commented on June 11, 2024

I think subnets[] may be something we need to except, but in this case I think using json('null') is correct?

from arm-ttk.

marrobi avatar marrobi commented on June 11, 2024

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.

bmoore-msft avatar bmoore-msft commented on June 11, 2024

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.

marrobi avatar marrobi commented on June 11, 2024

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.

amergey avatar amergey commented on June 11, 2024

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.

bmoore-msft avatar bmoore-msft commented on June 11, 2024

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:

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

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

bmoore-msft avatar bmoore-msft commented on June 11, 2024

or both?

from arm-ttk.

amergey avatar amergey commented on June 11, 2024

I am not the initial reporter of the issue, but I also like #2 :)

from arm-ttk.

marrobi avatar marrobi commented on June 11, 2024

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.

bmoore-msft avatar bmoore-msft commented on June 11, 2024

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.

bmoore-msft avatar bmoore-msft commented on June 11, 2024

added an approach in #62

from arm-ttk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.