-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validation that required won't be false
- Loading branch information
1 parent
14f639f
commit 255c770
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package action | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type isTrueValidator struct{} | ||
|
||
var _ validator.Bool = isTrueValidator{} | ||
|
||
// Description describes the validation in plain text formatting. | ||
func (v isTrueValidator) Description(ctx context.Context) string { | ||
return "Value must be true" | ||
} | ||
|
||
// MarkdownDescription describes the validation in Markdown formatting. | ||
func (v isTrueValidator) MarkdownDescription(ctx context.Context) string { | ||
return v.Description(ctx) | ||
} | ||
|
||
// ValidateBool performs the validation. | ||
func (v isTrueValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) { | ||
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
value := req.ConfigValue | ||
if value.Equal(types.BoolValue(true)) { | ||
return | ||
} | ||
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( | ||
req.Path, | ||
v.Description(ctx), | ||
value.String(), | ||
)) | ||
|
||
} |
This file contains 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
This file contains 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