Compile-time validation of parameter declarations and usage¶
Context and Problem Statement¶
Azure accepts definitions whose parameter usage is wrong, for example an Array parameter used with equals, or a String parameter used with in. The mistake only shows up at evaluation time, as an error or a policy that never matches. Bylaw knows each parameter's type and every place it is used, so it can catch many of these mistakes. How strict should it be?
Decision Drivers¶
- Catch definite mistakes at compile time.
- Avoid false positives that push authors towards
Arm.
Considered Options¶
- Errors for definite mismatches, warnings for likely mistakes
- Warnings only
- No validation beyond checking that the parameter exists
Decision Outcome¶
Chosen option: "Errors for definite mismatches, warnings for likely mistakes".
Errors:
Param XwhereXis not declared.- An
Arrayparameter used with an operator that takes a single value:-Be,-BeLike,-Match,-MatchCase,-ContainText,-ContainKey, or the comparison operators. - A non-
Arrayparameter used with-BeIn. - A
BooleanorObjectparameter used with-BeLike,-Match,-MatchCaseor-ContainText. - A comparison operator used with a parameter that isn't
Integer,Float,StringorDateTime. - A
Defaultthat doesn't match the declaredType, or isn't inAllowedValues. AllowedValueswhose items don't match the declaredType.- Effect parameter rules (ADR-0017).
Warnings:
- A parameter that is declared but never used.
- A
Stringparameter with noAllowedValuesthat is used as an effect. This is already an error under ADR-0017, so it is listed here only for completeness. - An empty
AllowedValues, which Azure treats as no restriction (BYL3035, added 2026-12-01). - A
Schemaon a parameter that isn't anObject(BYL3036, added 2026-12-01). Azure documentsschemaonly forObjectparameters, but it doesn't reject one on another type, so this is a warning rather than an error.
Parameter types follow Azure: String, Array, Object, Boolean, Integer, Float, DateTime. When Type isn't given, every Parameter form infers it from Default and AllowedValues. If inference is ambiguous, the build fails and asks for an explicit -Type.
Declaration forms¶
A parameter can be declared in three forms, which all give the same parameter:
Parameter Sku -Type String -AllowedValues a, b -Default a
Parameter Sku @{
Type = 'String'
AllowedValues = 'a', 'b'
Default = 'a'
}
Parameter @{ Name = 'Sku'; Type = 'String'; AllowedValues = 'a', 'b'; Default = 'a' }
- The one-line form suits a short declaration. A long one would need backtick line continuation, which Bylaw files don't use, so it goes in a hashtable after the name, one option per line. That keeps the name first, as in the one-line form and in
Policy 'name' { }. - The hashtable keys are the option names
Type,AllowedValues,Default,DisplayName,Description,JsonName,MetadataandSchema, matched ignoring case. The form withNameinside the hashtable also suits declarations built as data. - These are BYL1015: an unknown key, a hashtable together with named options such as
-Type, aNamekey in a hashtable after a name, two hashtables, a second argument that isn't a hashtable, and a missing or empty name. PolicyDefinitionandDefinitionGrouptake the same forms, since 2026-12-01 (ADR-0033).- Splatting (
Parameter Sku @options) also works, becauseParameteris a PowerShell function. It isn't the documented form, because the options sit away from the declaration, and a misspelled key is a PowerShell binding error, not a Bylaw diagnostic that lists the valid keys.
Parameter schema¶
Added 2026-12-01, for issue #71. A parameter's schema is a JSON Schema that Azure validates the assigned value against, following the Json.NET Schema 2019-09 implementation. Microsoft documents it only for Object parameters. Azure's built-in definitions use it on 197 Object parameters, mostly in Kubernetes and Guest Configuration, and none on other types except as null.
Schematakes a hashtable and is emitted afterdefaultValue. Anything else is BYL1015. An[ordered]@{ }keeps its keys in the order given, and a plain@{ }has them sorted, as for any hashtable (ADR-0009). Converting a plain hashtable to ordered insideParametercan't recover the order: PowerShell has built theHashtablebefore the keyword runs, and its own order follows the keys' hashes, not the source, so it would only fix an order nobody wrote. Reading the order back from the source would work only for a literal written in place, not for one built in a variable or loaded from data, so it isn't done. Key order has no meaning in a JSON Schema, only for reading the output. Bylaw doesn't interpret it: a schema is data for Azure, and Bylaw has no equivalent of its keywords to offer instead.ConvertTo-Bylawwrites it back as an[ordered]hashtable, one key per line where it doesn't fit on one, as Kubernetes schemas often don't.- Bylaw doesn't check that
DefaultandAllowedValuesmatch the schema, as Azure requires. PowerShell'sTest-Json -Schemacould, but it uses a different JSON Schema implementation from Azure's, so it could disagree with Azure. That is left for later.
Consequences¶
- Good, because the most common parameter bugs become build errors.
- Bad, because
Armusage can't be checked. Parameters referenced only insideArmcount as used, and are not validated.
Pros and Cons of the Options¶
Errors and warnings¶
- Good, because it gives the best defect detection.
- Bad, because the rule set has to be maintained.
Warnings only¶
- Good, because it never blocks a build.
- Bad, because warnings get ignored in CI.
Existence only¶
- Good, because it is trivial.
- Bad, because it misses the bugs that matter.