Skip to content

Introduce Data Source, Provider, and Resource Level Validators #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 30, 2022

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Aug 28, 2022

Closes #48

These configuration validators are intended for usage outside the schema definition, which may be easier to comprehend or introduce with code generation.

For example:

func (r exampleResource) ConfigValidators(ctx context.Context) []resource.ConfigValidator {
  return []resource.ConfigValidator{
    // Schema defined attributes named attr1 and attr2 must have one or more configured
    resourcevalidator.AtLeastOneOf(
      path.MatchRoot("attr1"),
      path.MatchRoot("attr2"),
    ),
    // Schema defined attributes named attr3 and attr4 cannot be configured together
    resourcevalidator.Conflicting(
      path.MatchRoot("attr3"),
      path.MatchRoot("attr4"),
    ),
    // Schema defined attributes named attr5 and attr6 must only have one configured
    resourcevalidator.ExactlyOneOf(
      path.MatchRoot("attr5"),
      path.MatchRoot("attr6"),
    ),
    // Schema defined attributes named attr7 and attr8 must be configured together
    resourcevalidator.RequiredTogether(
      path.MatchRoot("attr7"),
      path.MatchRoot("attr8"),
    ),
  }
}

Reference: #48

These configuration validators are intended for usage outside the schema definition, which may be easier to comprehend or introduce with code generation.

For example:

```go
func (r exampleResource) ConfigValidators(ctx context.Context) []resource.ConfigValidator {
  return []resource.ConfigValidator{
    // Schema defined attributes named attr1 and attr2 must have one or more configured
    resourcevalidator.AtLeastOneOf(
      path.MatchRoot("attr1"),
      path.MatchRoot("attr2"),
    ),
    // Schema defined attributes named attr3 and attr4 cannot be configured together
    resourcevalidator.Conflicting(
      path.MatchRoot("attr3"),
      path.MatchRoot("attr4"),
    ),
    // Schema defined attributes named attr5 and attr6 must only have one configured
    resourcevalidator.ExactlyOneOf(
      path.MatchRoot("attr5"),
      path.MatchRoot("attr6"),
    ),
    // Schema defined attributes named attr7 and attr8 must be configured together
    resourcevalidator.RequiredTogether(
      path.MatchRoot("attr7"),
      path.MatchRoot("attr8"),
    ),
  }
}
```
@bflad bflad added the enhancement New feature or request label Aug 28, 2022
@bflad bflad added this to the v0.5.0 milestone Aug 28, 2022
@bflad bflad requested a review from a team as a code owner August 28, 2022 18:50
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bflad bflad merged commit 7425c06 into main Aug 30, 2022
@bflad bflad deleted the bflad/schema-validators branch August 30, 2022 14:42
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource/Data-Source/Provider level Schema Configuration Validators
2 participants