Generate validation rules for map attributes #1020
Draft
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.
Extends the generator to produce validation rules for map-type attributes (tags, labels, environment variables) using key/value constraints from Smithy models. Adds 124 new tag validation rules across 48 services.
Changes
listmap(ListShape, KeyShape, ValueShape)syntax in mapping filesuppercase,replace) operate on shape enum valuesmap_rule.go.tmpltemplate for map validation rulesImplementation
AWS services define tags using two different patterns in their Smithy models.
Smithy
mapTypeSome services use a
maptype with explicitkeyandvaluetargets:The generator traverses this automatically via
traverseToMapConstraints(). No mapping file changes needed—just reference the shape name.List of Structures
Most services use a list containing a structure with named members:
This pattern cannot be inferred automatically because member names vary across services (
key/Key/TagKey,value/Value/TagValue). To avoid hardcoding member name lookups, I introduced thelistmap()function:This explicitly specifies which shapes provide list-level, key, and value constraints. The generator resolves each shape to a rich object containing pattern, length, and enum constraints, then combines them into a single map validation rule.
Shape Objects in Eval Context
The generator now represents each Smithy shape as a cty object:
This allows HCL expressions to directly reference shapes by name. Transform functions like
uppercase()andreplace()operate on the shape's enum values and return a new shape with transformed values:Regex Pattern Compatibility
Tag key patterns often include negative lookahead like
(?!aws:)to prevent reserved prefixes. Since Go's regexp doesn't support lookahead, these patterns are stripped. The character class validation still applies.Testing
listmap()function combines constraints correctlyReferences
tagsattributes #1019