Skip to content

Commit 1452aa1

Browse files
committed
Merge branch 'main' into av/refinements
2 parents c121e24 + 9e8cd18 commit 1452aa1

39 files changed

+1386
-22
lines changed

.changes/0.16.0.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 0.16.0 (December 12, 2024)
2+
3+
FEATURES:
4+
5+
* listvalidator: Added `NoNullValues` validator ([#245](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/245))
6+
* mapvalidator: Added `NoNullValues` validator ([#245](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/245))
7+
* setvalidator: Added `NoNullValues` validator ([#245](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/245))
8+
* dynamicvalidator: New package which contains `types.Dynamic` specific validators ([#249](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/249))
9+
10+
BUG FIXES:
11+
12+
* Fixed bug with `ConflictsWith` and `AlsoRequires` validators where unknown values would raise invalid diagnostics during `terraform validate`. ([#251](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/251))
13+

.github/workflows/ci-github-actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17-
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
17+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
1818
with:
1919
go-version-file: 'go.mod'
2020
- run: go install github.com/rhysd/actionlint/cmd/actionlint@latest

.github/workflows/ci-go.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20-
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
20+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
2121
with:
2222
go-version-file: 'go.mod'
2323
- run: go mod download
@@ -31,13 +31,13 @@ jobs:
3131
go-version: [ '1.23', '1.22' ]
3232
steps:
3333
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34-
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
34+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
3535
with:
3636
go-version: ${{ matrix.go-version }}
3737
- run: go mod download
3838
- run: go test -coverprofile=coverage.out ./...
3939
- run: go tool cover -html=coverage.out -o coverage.html
40-
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
40+
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
4141
with:
4242
name: go-${{ matrix.go-version }}-coverage
4343
path: coverage.html

.github/workflows/ci-goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18-
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
18+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
1919
with:
2020
go-version-file: 'go.mod'
2121
- uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
ref: ${{ inputs.versionNumber }}
8585
fetch-depth: 0
8686

87-
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
87+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
8888
with:
8989
go-version-file: 'go.mod'
9090

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 0.16.0 (December 12, 2024)
2+
3+
FEATURES:
4+
5+
* listvalidator: Added `NoNullValues` validator ([#245](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/245))
6+
* mapvalidator: Added `NoNullValues` validator ([#245](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/245))
7+
* setvalidator: Added `NoNullValues` validator ([#245](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/245))
8+
* dynamicvalidator: New package which contains `types.Dynamic` specific validators ([#249](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/249))
9+
10+
BUG FIXES:
11+
12+
* Fixed bug with `ConflictsWith` and `AlsoRequires` validators where unknown values would raise invalid diagnostics during `terraform validate`. ([#251](https://github.com/hashicorp/terraform-plugin-framework-validators/issues/251))
13+
114
## 0.15.0 (October 31, 2024)
215

316
FEATURES:

dynamicvalidator/all.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package dynamicvalidator
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"strings"
10+
11+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
12+
)
13+
14+
// All returns a validator which ensures that any configured attribute value
15+
// attribute value validates against all the given validators.
16+
//
17+
// Use of All is only necessary when used in conjunction with Any or AnyWithAllWarnings
18+
// as the Validators field automatically applies a logical AND.
19+
func All(validators ...validator.Dynamic) validator.Dynamic {
20+
return allValidator{
21+
validators: validators,
22+
}
23+
}
24+
25+
var _ validator.Dynamic = allValidator{}
26+
27+
// allValidator implements the validator.
28+
type allValidator struct {
29+
validators []validator.Dynamic
30+
}
31+
32+
// Description describes the validation in plain text formatting.
33+
func (v allValidator) Description(ctx context.Context) string {
34+
var descriptions []string
35+
36+
for _, subValidator := range v.validators {
37+
descriptions = append(descriptions, subValidator.Description(ctx))
38+
}
39+
40+
return fmt.Sprintf("Value must satisfy all of the validations: %s", strings.Join(descriptions, " + "))
41+
}
42+
43+
// MarkdownDescription describes the validation in Markdown formatting.
44+
func (v allValidator) MarkdownDescription(ctx context.Context) string {
45+
return v.Description(ctx)
46+
}
47+
48+
// ValidateDynamic performs the validation.
49+
func (v allValidator) ValidateDynamic(ctx context.Context, req validator.DynamicRequest, resp *validator.DynamicResponse) {
50+
for _, subValidator := range v.validators {
51+
validateResp := &validator.DynamicResponse{}
52+
53+
subValidator.ValidateDynamic(ctx, req, validateResp)
54+
55+
resp.Diagnostics.Append(validateResp.Diagnostics...)
56+
}
57+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package dynamicvalidator_test
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework-validators/dynamicvalidator"
8+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
9+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
10+
)
11+
12+
func ExampleAll() {
13+
// Used within a Schema method of a DataSource, Provider, or Resource
14+
_ = schema.Schema{
15+
Attributes: map[string]schema.Attribute{
16+
"example_attr": schema.DynamicAttribute{
17+
Required: true,
18+
Validators: []validator.Dynamic{
19+
dynamicvalidator.Any(
20+
dynamicvalidator.Any( /* ... */ ),
21+
dynamicvalidator.All( /* ... */ ),
22+
),
23+
},
24+
},
25+
},
26+
}
27+
}

dynamicvalidator/also_requires.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package dynamicvalidator
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator"
8+
"github.com/hashicorp/terraform-plugin-framework/path"
9+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
10+
)
11+
12+
// AlsoRequires checks that a set of path.Expression has a non-null value,
13+
// if the current attribute or block also has a non-null value.
14+
//
15+
// This implements the validation logic declaratively within the schema.
16+
// Refer to [datasourcevalidator.RequiredTogether],
17+
// [providervalidator.RequiredTogether], or [resourcevalidator.RequiredTogether]
18+
// for declaring this type of validation outside the schema definition.
19+
//
20+
// Relative path.Expression will be resolved using the attribute or block
21+
// being validated.
22+
func AlsoRequires(expressions ...path.Expression) validator.Dynamic {
23+
return schemavalidator.AlsoRequiresValidator{
24+
PathExpressions: expressions,
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package dynamicvalidator_test
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework-validators/dynamicvalidator"
8+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
9+
"github.com/hashicorp/terraform-plugin-framework/path"
10+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
11+
)
12+
13+
func ExampleAlsoRequires() {
14+
// Used within a Schema method of a DataSource, Provider, or Resource
15+
_ = schema.Schema{
16+
Attributes: map[string]schema.Attribute{
17+
"example_attr": schema.DynamicAttribute{
18+
Optional: true,
19+
Validators: []validator.Dynamic{
20+
// Validate this attribute must be configured with other_attr.
21+
dynamicvalidator.AlsoRequires(path.Expressions{
22+
path.MatchRoot("other_attr"),
23+
}...),
24+
},
25+
},
26+
"other_attr": schema.DynamicAttribute{
27+
Optional: true,
28+
},
29+
},
30+
}
31+
}

0 commit comments

Comments
 (0)