converge icon indicating copy to clipboard operation
converge copied to clipboard

parameter validation

Open stevendborrelli opened this issue 8 years ago • 4 comments

I don't know if this should be a macro, but I was bitten today in Ansible because interpolations resulted in an empty variable. Is it possible that we have some checks to make sure computed variables or outputs of a module meet certain conditions?

Ignore the crappy syntax, but something like:

required {
       len(computed_var) > 0
       len(consul_servers_group) = len (control_servers_group)
       len(counsul_servers_group) >= 3
               "A minimum of 3 consul servers is required)
} 

warn {
        (consul_servers_group % 2) != 0 :
               "The number of consul servers should be an odd number"
}

stevendborrelli avatar Aug 02 '16 09:08 stevendborrelli

Maybe this is part of the param definition, so that it can be used outside for API's & UI rendering.

stevendborrelli avatar Aug 02 '16 09:08 stevendborrelli

I like the idea of maybe having a ‘constraint’ type option for params:

param “foo” { default = 5 constraints { type = number value > 0 } }

but then it maybe goes too far toward being a language and makes things more complicated for the user?

On Aug 2, 2016, at 4:25 AM, Steven Borrelli [email protected] wrote:

Maybe this is part of the param definition, so that it can be used outside for API's & UI rendering.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/asteris-llc/converge/issues/134#issuecomment-236851670, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMbqwdStRgSMSZqMqbkCOEe780uR7jGks5qbw0OgaJpZM4JaZc7.

rebeccaskinner avatar Aug 02 '16 13:08 rebeccaskinner

Could we have a valid/constraints field that takes a function? So, param "foo" { default = 5, constraint = NonZeroNum }, then have a function called NonZeroNum that checks the param during validate? That way, the config file is simpler, validation can be as detailed and simple as you like, and users can define their own constraints?

sehqlr avatar Aug 18 '16 17:08 sehqlr

I'm going to remove this from the 0.3.0 project, in favor of tracking only the PR on that board

sehqlr avatar Oct 04 '16 21:10 sehqlr