AZS002 + AZS003: schema Default/Type mismatch and empty-block panic risk (ports of long-open tfproviderlint PRs) - #4
Merged
Conversation
…isk (ports of long-open tfproviderlint PRs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
AZS002 + AZS003: two new schema checks
Implements the checks from two tfproviderlint PRs that have sat open upstream — bflad/tfproviderlint#329 (S038, open since Feb 2025) and bflad/tfproviderlint#236 (XS003, open since Apr 2021) — as tfproviderlint appears dormant and both checks were written for (and validated against) the AzureRM provider. Both are reimplemented in azproviderlint's self-contained style rather than copied, since the originals mostly patch tfproviderlint helper internals we don't use.
AZS002 —
Defaultvalue must match the declaredTypeThe plugin SDK's
InternalValidatedoes not type-checkDefaultagainstType, soType: schema.TypeInt, Default: trueonly surfaces as an error at plan time.Improvements over the upstream S038 implementation:
TypeFloat(accepting both int and float constants; upstream silently ignored it)Default: SkuStandard) still resolve through the type checkerAZS003 — optional-only list blocks allow
foo {}Type: TypeListblocks whose nested properties are all optional with noDefault/DefaultFuncand noAtLeastOneOf/ExactlyOneOfaccept an empty block, which yields a nil list element that expand functions commonly crash on (raw[0].(map[string]interface{})— see azurerm#11426), or a permanent diff. XS003's companion cleanup (azurerm#11452, merged 2021) fixed ~100 of these by addingAtLeastOneOf; this check gates the pattern going forward.This is a heuristic: blocks whose expand functions guard against nil are safe in practice but still reported — suppress those with
//azignore:AZS003.Both checks
Schema/Resourcein a package namedschema), so directhelper/schemause, azurerm'spluginsdkaliases, and literals elided insidemap[string]*Schemaall resolve identicallyTypeSet, primitive elems and out-of-scope schema types stay quiet