Add AlsoRequiresWhenEquals validator#48888
Conversation
…enEqualsValidator.
Community GuidelinesThis comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀 Voting for Prioritization
Pull Request Authors
|
…IfSingleBlockRemoved'.
533fb10 to
5b4abee
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds new Terraform Plugin Framework string validators to enforce conditional “also requires” and “conflicts with” relationships based on a string/enum attribute value, then adopts these validators in Bedrock Agent Core resources (replacing bespoke ValidateConfig checks). It also refactors the bool AlsoRequiresWhenTrue validator to reuse shared internal logic and renames/moves a list plan modifier into a more specific listplanmodifier package.
Changes:
- Add
tfstringvalidator.AlsoRequiresWhenEquals,ConflictsWithWhenEquals, andConflictsWithWhenNotEquals(with shared internal validator implementations and unit tests). - Replace resource-level
ValidateConfiglogic in Bedrock Agent Core resources with schema validators (and adjust acceptance tests accordingly). - Rename the list default-from-path plan modifier into
internal/framework/planmodifiers/listplanmodifierand update its usages/tests.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/service/route53domains/domain.go | Updates import/usage to the renamed listplanmodifier.DefaultValueFromPath. |
| internal/service/bedrockagentcore/registry.go | Uses AlsoRequiresWhenEquals on authorizer_type and removes custom ValidateConfig. |
| internal/service/bedrockagentcore/memory_strategy.go | Replaces ValidateConfig with conditional string validators for type and nested config. |
| internal/service/bedrockagentcore/memory_strategy_test.go | Updates expected diagnostics text and refreshes test model IDs; removes some scenario steps from the custom test. |
| internal/service/bedrockagentcore/gateway.go | Adds AlsoRequiresWhenEquals for authorizer config presence (but currently uses the wrong enum constant; see comment). |
| internal/service/bedrockagentcore/agent_runtime.go | Adds ExactlyOneOfChildren object validator to authorizer configuration nested object. |
| internal/framework/validators/stringvalidator/also_requires_when_equals.go | New validator: require other attributes when a string equals a target value. |
| internal/framework/validators/stringvalidator/also_requires_when_equals_test.go | Unit coverage for AlsoRequiresWhenEquals. |
| internal/framework/validators/stringvalidator/conflicts_with_when_equals.go | New validator: forbid other attributes when a string equals a target value. |
| internal/framework/validators/stringvalidator/conflicts_with_when_equals_test.go | Unit coverage for ConflictsWithWhenEquals. |
| internal/framework/validators/stringvalidator/conflicts_with_when_not_equals.go | New validator: forbid other attributes when a string does not equal a target value. |
| internal/framework/validators/stringvalidator/conflicts_with_when_not_equals_test.go | Unit coverage for ConflictsWithWhenNotEquals. |
| internal/framework/validators/internal/also_requires_when.go | Shared internal implementation backing string/bool “also requires when …” validators. |
| internal/framework/validators/internal/conflicts_with_when.go | Shared internal implementation backing string “conflicts with when …” validators. |
| internal/framework/validators/internal/exactly_one_of.go | Renames shared request/response structs used by object validators (ValidatorRequest/ValidatorResponse). |
| internal/framework/validators/objectvalidator/*.go | Updates object validators to use the shared internal request/response types. |
| internal/framework/validators/boolvalidator/also_requires_when_true.go | Refactors to reuse the shared internal “also requires when …” implementation. |
| internal/framework/validators/boolvalidator/also_requires_when_true_test.go | Expands test matrix to cover additional multi-target cases and unknown handling. |
| internal/framework/planmodifiers/listplanmodifier/default_value_from_path.go | Renames package and exported symbol to listplanmodifier.DefaultValueFromPath. |
| internal/framework/planmodifiers/listplanmodifier/default_value_from_path_test.go | Updates tests for the new package/name and uses t.Context() instead of context.Background(). |
YakDriver
left a comment
There was a problem hiding this comment.
I really like this. The single direction reads very nicely and replaces a bunch of badness. The multi-direction concerns me a little (easily half specified when iff is meant) but not committed to it. Either way, it's a great improvement.
| Required: true, | ||
| CustomType: fwtypes.StringEnumType[awstypes.MemoryStrategyType](), | ||
| Validators: []validator.String{ | ||
| tfstringvalidator.AlsoRequiresWhenEquals( |
There was a problem hiding this comment.
What about adding another so that we don't need Requires and Conflicts in this situation? I fought a while with names and these are the two best I came up with. Map would be handy if there are multiple arms that need selecting.
tfstringvalidator.Discriminates(map[value, path])- accurate, used in OpenAPI, JSON schema but maybe less well known?tfstringvalidator.RequiredIffValue(map[value, path])- "Iff" is a little jargony and might be misread as "If"
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.
Description
Adds the
AlsoRequiresWhenEqualsstring attribute validator which checks that eachpath.Expressionhas a non-null configuration value when the string(y) attribute being validated has the known, specified value.The generic internals can be re-used by
tfboolvalidator.AlsoRequiresWhenTrue.This fixes some bugs to do with unknowns in that validator.
Plus
ConflictsWithWhenEqualsandConflictsWithWhenNotEqualsstring attribute validators required foraws_bedrockagentcore_memory_strategy.Relations
Closes #48700.
Output from Acceptance Testing