Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: Migrate implementations to support terraform-plugin-framework ve…
…rsion 0.17.0 (#80) The next terraform-plugin-framework version will have separate `datasource/schema`, `provider/schema`, and `resource/schema` packages which use the type-specific `schema/validator` interfaces. This change updates all schema-based validators to the new interfaces. In the cases where the validators did not match a single type (e.g. `metavalidator`, `schemavalidator` package validators), those validators are now present in all the type-specific validator packages.
- Loading branch information
Showing
382 changed files
with
15,920 additions
and
5,758 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,31 @@ | ||
```release-note:breaking-change | ||
all: Migrated implementations to support terraform-plugin-framework version 0.17.0 `datasource/schema`, `provider/schema`, and `resource/schema` packages with type-specific validation | ||
``` | ||
|
||
```release-note:breaking-change | ||
listvalidator: The `ValuesAre` validator has been removed and split into element type-specific validators in the same package, such as `StringValuesAre` | ||
``` | ||
|
||
```release-note:breaking-change | ||
mapvalidator: The `ValuesAre` validator has been removed and split into element type-specific validators in the same package, such as `StringValuesAre` | ||
``` | ||
|
||
```release-note:breaking-change | ||
metavalidator: The `All` and `Any` validators have been removed and split into type-specific packages, such as `stringvalidator.Any` | ||
``` | ||
|
||
```release-note:breaking-change | ||
schemavalidator: The `AlsoRequires`, `AtLeastOneOf`, `ConflictsWith`, and `ExactlyOneOf` validators have been removed and split into type-specific packages, such as `stringvalidator.ConflictsWith` | ||
``` | ||
|
||
```release-note:breaking-change | ||
setvalidator: The `ValuesAre` validator has been removed and split into element type-specific validators in the same package, such as `StringValuesAre` | ||
``` | ||
|
||
```release-note:feature | ||
boolvalidator: New package which contains boolean type specific validators | ||
``` | ||
|
||
```release-note:feature | ||
objectvalidator: New package which contains object type specific validators | ||
``` |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
go.work | ||
go.work.sum | ||
# JetBrains IDEs project files | ||
.idea/ | ||
*.iws |
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,23 @@ | ||
package boolvalidator | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
// AlsoRequires checks that a set of path.Expression has a non-null value, | ||
// if the current attribute or block also has a non-null value. | ||
// | ||
// This implements the validation logic declaratively within the schema. | ||
// Refer to [datasourcevalidator.RequiredTogether], | ||
// [providervalidator.RequiredTogether], or [resourcevalidator.RequiredTogether] | ||
// for declaring this type of validation outside the schema definition. | ||
// | ||
// Relative path.Expression will be resolved using the attribute or block | ||
// being validated. | ||
func AlsoRequires(expressions ...path.Expression) validator.Bool { | ||
return schemavalidator.AlsoRequiresValidator{ | ||
PathExpressions: expressions, | ||
} | ||
} |
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,28 @@ | ||
package boolvalidator_test | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
func ExampleAlsoRequires() { | ||
// Used within a Schema method of a DataSource, Provider, or Resource | ||
_ = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"example_attr": schema.BoolAttribute{ | ||
Optional: true, | ||
Validators: []validator.Bool{ | ||
// Validate this attribute must be configured with other_attr. | ||
boolvalidator.AlsoRequires(path.Expressions{ | ||
path.MatchRoot("other_attr"), | ||
}...), | ||
}, | ||
}, | ||
"other_attr": schema.StringAttribute{ | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} |
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,24 @@ | ||
package boolvalidator | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
// AtLeastOneOf checks that of a set of path.Expression, | ||
// including the attribute this validator is applied to, | ||
// at least one has a non-null value. | ||
// | ||
// This implements the validation logic declaratively within the tfsdk.Schema. | ||
// Refer to [datasourcevalidator.AtLeastOneOf], | ||
// [providervalidator.AtLeastOneOf], or [resourcevalidator.AtLeastOneOf] | ||
// for declaring this type of validation outside the schema definition. | ||
// | ||
// Any relative path.Expression will be resolved using the attribute being | ||
// validated. | ||
func AtLeastOneOf(expressions ...path.Expression) validator.Bool { | ||
return schemavalidator.AtLeastOneOfValidator{ | ||
PathExpressions: expressions, | ||
} | ||
} |
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,28 @@ | ||
package boolvalidator_test | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
func ExampleAtLeastOneOf() { | ||
// Used within a Schema method of a DataSource, Provider, or Resource | ||
_ = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"example_attr": schema.BoolAttribute{ | ||
Optional: true, | ||
Validators: []validator.Bool{ | ||
// Validate at least this attribute or other_attr should be configured. | ||
boolvalidator.AtLeastOneOf(path.Expressions{ | ||
path.MatchRoot("other_attr"), | ||
}...), | ||
}, | ||
}, | ||
"other_attr": schema.StringAttribute{ | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} |
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,24 @@ | ||
package boolvalidator | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
// ConflictsWith checks that a set of path.Expression, | ||
// including the attribute the validator is applied to, | ||
// do not have a value simultaneously. | ||
// | ||
// This implements the validation logic declaratively within the schema. | ||
// Refer to [datasourcevalidator.Conflicting], | ||
// [providervalidator.Conflicting], or [resourcevalidator.Conflicting] | ||
// for declaring this type of validation outside the schema definition. | ||
// | ||
// Relative path.Expression will be resolved using the attribute being | ||
// validated. | ||
func ConflictsWith(expressions ...path.Expression) validator.Bool { | ||
return schemavalidator.ConflictsWithValidator{ | ||
PathExpressions: expressions, | ||
} | ||
} |
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,28 @@ | ||
package boolvalidator_test | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
func ExampleConflictsWith() { | ||
// Used within a Schema method of a DataSource, Provider, or Resource | ||
_ = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"example_attr": schema.BoolAttribute{ | ||
Optional: true, | ||
Validators: []validator.Bool{ | ||
// Validate this attribute must not be configured with other_attr. | ||
boolvalidator.ConflictsWith(path.Expressions{ | ||
path.MatchRoot("other_attr"), | ||
}...), | ||
}, | ||
}, | ||
"other_attr": schema.StringAttribute{ | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} |
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,2 @@ | ||
// Package boolvalidator provides validators for types.Bool attributes. | ||
package boolvalidator |
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,25 @@ | ||
package boolvalidator | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
// ExactlyOneOf checks that of a set of path.Expression, | ||
// including the attribute the validator is applied to, | ||
// one and only one attribute has a value. | ||
// It will also cause a validation error if none are specified. | ||
// | ||
// This implements the validation logic declaratively within the schema. | ||
// Refer to [datasourcevalidator.ExactlyOneOf], | ||
// [providervalidator.ExactlyOneOf], or [resourcevalidator.ExactlyOneOf] | ||
// for declaring this type of validation outside the schema definition. | ||
// | ||
// Relative path.Expression will be resolved using the attribute being | ||
// validated. | ||
func ExactlyOneOf(expressions ...path.Expression) validator.Bool { | ||
return schemavalidator.ExactlyOneOfValidator{ | ||
PathExpressions: expressions, | ||
} | ||
} |
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,28 @@ | ||
package boolvalidator_test | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
func ExampleExactlyOneOf() { | ||
// Used within a Schema method of a DataSource, Provider, or Resource | ||
_ = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"example_attr": schema.BoolAttribute{ | ||
Optional: true, | ||
Validators: []validator.Bool{ | ||
// Validate only this attribute or other_attr is configured. | ||
boolvalidator.ExactlyOneOf(path.Expressions{ | ||
path.MatchRoot("other_attr"), | ||
}...), | ||
}, | ||
}, | ||
"other_attr": schema.StringAttribute{ | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} |
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
Oops, something went wrong.