wafv2: generate web_acl and rule_group from depth-limited schemas - #3227
Draft
arditti wants to merge 3 commits into
Draft
wafv2: generate web_acl and rule_group from depth-limited schemas#3227arditti wants to merge 3 commits into
arditti wants to merge 3 commits into
Conversation
The de-recursed schemas allow 3 levels of Statement nesting, i.e. 2 chained logical statements (And/Or/Not) above a match statement - one logical level fewer than terraform-provider-aws's hand-written WAFv2 schemas. Unrolling to --depth 4 currently produces generated files (~103 MB for the web ACL resource) that exceed a Go per-function compiler limit (internal compiler error: NewBulk too big), so matching that extra level needs generator changes first. Statements nested deeper than the schema are silently omitted from Terraform state on import/read; the remote resource itself is not modified. Document both behaviors in the resource docs (via new website templates) and in the all_schemas.hcl comments.
…k updates that would modify them Depth-limited (de-recursed) schemas cannot represent statements nested beyond their maximum depth. Previously such properties were silently omitted from state on read/import (Info-level log only), plans reported no changes, and an update touching a truncated rule could corrupt the remote resource, since the patch is computed from truncated state. - tools/derecurse-schema.py records the property names it prunes at the depth boundary under an x-derecursed key in the rewritten schema. - The resource generator plumbs them into the resource via a new WithUnrepresentableProperties option. - Read collects properties skipped during Cloud Control-to-Terraform translation and emits a warning diagnostic when any declared- unrepresentable property was dropped, listing the exact locations. Skips of undeclared properties (schema newer than the provider) stay log-only, as before. - Update walks the remote resource model, locates content the schema cannot represent, and fails with an actionable error when the patch would modify it. Updates elsewhere in the resource proceed normally. Verified against a live web ACL nested one logical level beyond the schema: import now warns with the exact dropped path; a structural edit inside the truncated rule is rejected (previously it silently inserted a statement into the remote rule); edits to other properties succeed; within-depth web ACLs see no warning and no behavior change.
Author
|
Pushed a follow-up commit that makes the depth limitation loud instead of silent:
Verified live: importing a 3-logical-level web ACL warns with the exact dropped path; a structural edit inside the truncated rule is rejected with the remote resource untouched; description/tag edits succeed; within-depth web ACLs see no warning and no behavior change. Docs updated to describe both behaviors. |
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.
Community Note
Relates #95
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the library.
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
No.
Description
Unsuppresses
awscc_wafv2_web_aclandawscc_wafv2_rule_group(resource + singular data source) by generating them from depth-limited (de-recursed) local schemas, sidestepping the "Recursive Attribute Definitions" blocker (#95).Approach
Terraform's type system cannot model recursive attribute definitions, but it can model a fixed nesting depth — the same trade-off
terraform-provider-awsmakes in its hand-writtenaws_wafv2_web_acl/aws_wafv2_rule_groupschemas. This PR applies it to the generated provider:tools/derecurse-schema.py, rewrites a CloudFormation schema in place:definitionsare detected generically as strongly-connected components of the$refgraph (no WAFv2 names hardcoded) — for WebACL the cycle is{AndStatement, ManagedRuleGroupStatement, NotStatement, OrStatement, RateBasedStatement, Statement}.Statement,StatementLevel2,StatementLevel3).AndStatement) are pruned entirely. The result: a level-3Statementstill offersRateBasedStatement/ManagedRuleGroupStatement(without theirScopeDownStatement) but notAndStatement/OrStatement/NotStatement— mirroringterraform-provider-aws.AddressField/PhoneNumberField→FieldIdentifier), which otherwise trip the generator's array-item typing (Resource Suppression: list of undefined is not supported #1515).AWS_WAFv2_WebACL.json/AWS_WAFv2_RuleGroup.jsonare committed, pinned viainternal/update/suppressions_checkout.txt, and annotated inall_schemas.hclfollowing theaws_lex_bot/aws_emrserverless_applicationprecedent (pinned local schema + note). After a future schema refresh, re-running the script on the fresh schema re-applies the unroll.Limitation
The unroll depth is 3 levels of
Statement, which supports 2 chained logical statements (And/Or/Not) above a match statement — e.g.AndStatement → NotStatement → ByteMatchStatement. For precision: this is one logical level fewer thanterraform-provider-aws's hand-written schema, whose level constant of 3 yields 3 chained logical statements. Unrolling to--depth 4closes that gap in the schema, but the generated Go currently fails to compile at that depth —web_acl_resource_gen.gogrows to ~103 MB and the Go compiler hits a per-function limit (internal compiler error: NewBulk too big) because the whole schema is emitted as one function literal. Matching the extra level therefore needs generator changes (deduplicating repeated nested-attribute subtrees) rather than a bigger--depth; I intend to propose that separately.Behavior at the boundary (verified against a live web ACL nested beyond the schema depth):
internal/generic/translate.go); the remote resource is not modified, and subsequent plans report no changes.Deeper nesting can be regained at any time by re-running the script with
--depth Nand regenerating, once the generated-code size is addressed.Generated file sizes
The unrolled schema inflates the generated code (expected, called out up front):
web_acl_resource_gen.gois ~19.6 MB,rule_group_resource_gen.go~9.1 MB, singular data sources ~13.3 MB / ~6.1 MB, and the four docs pages total ~11 MB. They compile cleanly (the wafv2 package takes ~2 minutes to build). If that size is unacceptable, the same script/pinning mechanism works at--depth 2, which roughly halves it.Verification
Gates (all pass):
Acceptance tests (us-east-1):
(The generated
*DataSource_NonExistenttests fail identically for the pre-existingawscc_wafv2_ip_set, because WAFv2's Cloud Control identifier is compositeName|Id|Scopeand the API returnsValidationExceptionrather than not-found — a pre-existing pattern, not introduced here.)End-to-end with a locally built provider (real AWS, us-east-1, REGIONAL): created a
awscc_wafv2_web_aclwith a rule usingand_statement→ [geo_match_statement,not_statement→geo_match_statement] and aawscc_wafv2_rule_groupwithor_statement→ [geo_match_statement,not_statement→geo_match_statement]; read the web ACL back through the new singular data source; re-plan showed no drift; destroyed cleanly.