hashicorp / terraform-plugin-framework-validators

Common Use Case Validators for terraform-plugin-framework
Mozilla Public License 2.0
25 stars 11 forks source link

`Equals` validator for boolean types #231

Closed jar-b closed 4 days ago

jar-b commented 6 days ago

Terraform CLI and Framework Versions

% terraform version
Terraform v1.9.5
on darwin_arm64
% cat go.mod | rg terraform-plugin-framework
        github.com/hashicorp/terraform-plugin-framework v1.11.0
        github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0
        github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
        github.com/hashicorp/terraform-plugin-framework-timetypes v0.5.0
        github.com/hashicorp/terraform-plugin-framework-validators v0.13.0

Use Cases or Problem Statement

The AWS provider recently implemented a resource which included a boolean argument that should only ever be null or true. To enforce this condition, we added a custom BoolEquals validator that confirms a non-null boolean value exactly matches that which the validator is configured with (in our case true).

I'm not sure if this use case is a common enough to warrant moving up into this repository, but thought I'd offer up our implementation just in case.

Proposal

Add a new Equals validator to the boolvalidator package.

Additional Information

The AWS provider implemented a custom version of this in a recent pull request: https://github.com/hashicorp/terraform-provider-aws/pull/39180

Code of Conduct