Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-120903.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'boolvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:09:03.733715-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121130.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'dynamicvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:11:30.572285-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121159.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'float32validator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:11:59.137017-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121224.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'float64validator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:12:24.396457-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121243.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'int32validator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:12:43.521669-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121308.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'int64validator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:13:08.483387-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121402.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'listvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:14:02.302221-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121418.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'mapvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:14:18.324953-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121440.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'numbervalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:14:40.942642-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121500.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'objectvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:15:00.176757-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121519.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'resourcevalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:15:19.618622-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121533.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'setvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:15:33.908556-05:00
custom:
Issue: "263"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250206-121553.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'stringvalidator: Added `PreferWriteOnlyAttribute` validator'
time: 2025-02-06T12:15:53.337804-05:00
custom:
Issue: "263"
28 changes: 28 additions & 0 deletions boolvalidator/prefer_write_only_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package boolvalidator

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator"
)

// PreferWriteOnlyAttribute returns a warning if the Terraform client supports
// write-only attributes, and the attribute that the validator is applied to has a value.
// It takes in a path.Expression that represents the write-only attribute schema location,
// and the warning message will indicate that the write-only attribute should be preferred.
//
// This validator should only be used for resource attributes as other schema types do not
// support write-only attributes.
//
// This implements the validation logic declaratively within the schema.
// Refer to [resourcevalidator.PreferWriteOnlyAttribute]
// for declaring this type of validation outside the schema definition.
func PreferWriteOnlyAttribute(writeOnlyAttribute path.Expression) validator.Bool {
return schemavalidator.PreferWriteOnlyAttribute{
WriteOnlyAttribute: writeOnlyAttribute,
}
}
34 changes: 34 additions & 0 deletions boolvalidator/prefer_write_only_attribute_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package boolvalidator_test

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator"
)

func ExamplePreferWriteOnlyAttribute() {
// Used within a Schema method of a Resource
_ = schema.Schema{
Attributes: map[string]schema.Attribute{
"example_attr": schema.BoolAttribute{
Optional: true,
Validators: []validator.Bool{
// Throws a warning diagnostic encouraging practitioners to use
// write_only_attr if example_attr has a value.
boolvalidator.PreferWriteOnlyAttribute(
path.MatchRoot("write_only_attr"),
),
},
},
"write_only_attr": schema.BoolAttribute{
WriteOnly: true,
Optional: true,
},
},
}
}
28 changes: 28 additions & 0 deletions dynamicvalidator/prefer_write_only_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package dynamicvalidator

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator"
)

// PreferWriteOnlyAttribute returns a warning if the Terraform client supports
// write-only attributes, and the attribute that the validator is applied to has a value.
// It takes in a path.Expression that represents the write-only attribute schema location,
// and the warning message will indicate that the write-only attribute should be preferred.
//
// This validator should only be used for resource attributes as other schema types do not
// support write-only attributes.
//
// This implements the validation logic declaratively within the schema.
// Refer to [resourcevalidator.PreferWriteOnlyAttribute]
// for declaring this type of validation outside the schema definition.
func PreferWriteOnlyAttribute(writeOnlyAttribute path.Expression) validator.Dynamic {
return schemavalidator.PreferWriteOnlyAttribute{
WriteOnlyAttribute: writeOnlyAttribute,
}
}
34 changes: 34 additions & 0 deletions dynamicvalidator/prefer_write_only_attribute_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package dynamicvalidator_test

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/dynamicvalidator"
)

func ExamplePreferWriteOnlyAttribute() {
// Used within a Schema method of a Resource
_ = schema.Schema{
Attributes: map[string]schema.Attribute{
"example_attr": schema.DynamicAttribute{
Optional: true,
Validators: []validator.Dynamic{
// Throws a warning diagnostic encouraging practitioners to use
// write_only_attr if example_attr has a value.
dynamicvalidator.PreferWriteOnlyAttribute(
path.MatchRoot("write_only_attr"),
),
},
},
"write_only_attr": schema.DynamicAttribute{
WriteOnly: true,
Optional: true,
},
},
}
}
28 changes: 28 additions & 0 deletions float32validator/prefer_write_only_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package float32validator

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator"
)

// PreferWriteOnlyAttribute returns a warning if the Terraform client supports
// write-only attributes, and the attribute that the validator is applied to has a value.
// It takes in a path.Expression that represents the write-only attribute schema location,
// and the warning message will indicate that the write-only attribute should be preferred.
//
// This validator should only be used for resource attributes as other schema types do not
// support write-only attributes.
//
// This implements the validation logic declaratively within the schema.
// Refer to [resourcevalidator.PreferWriteOnlyAttribute]
// for declaring this type of validation outside the schema definition.
func PreferWriteOnlyAttribute(writeOnlyAttribute path.Expression) validator.Float32 {
return schemavalidator.PreferWriteOnlyAttribute{
WriteOnlyAttribute: writeOnlyAttribute,
}
}
34 changes: 34 additions & 0 deletions float32validator/prefer_write_only_attribute_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package float32validator_test

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/float32validator"
)

func ExamplePreferWriteOnlyAttribute() {
// Used within a Schema method of a Resource
_ = schema.Schema{
Attributes: map[string]schema.Attribute{
"example_attr": schema.Float32Attribute{
Optional: true,
Validators: []validator.Float32{
// Throws a warning diagnostic encouraging practitioners to use
// write_only_attr if example_attr has a value.
float32validator.PreferWriteOnlyAttribute(
path.MatchRoot("write_only_attr"),
),
},
},
"write_only_attr": schema.Float32Attribute{
WriteOnly: true,
Optional: true,
},
},
}
}
28 changes: 28 additions & 0 deletions float64validator/prefer_write_only_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package float64validator

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator"
)

// PreferWriteOnlyAttribute returns a warning if the Terraform client supports
// write-only attributes, and the attribute that the validator is applied to has a value.
// It takes in a path.Expression that represents the write-only attribute schema location,
// and the warning message will indicate that the write-only attribute should be preferred.
//
// This validator should only be used for resource attributes as other schema types do not
// support write-only attributes.
//
// This implements the validation logic declaratively within the schema.
// Refer to [resourcevalidator.PreferWriteOnlyAttribute]
// for declaring this type of validation outside the schema definition.
func PreferWriteOnlyAttribute(writeOnlyAttribute path.Expression) validator.Float64 {
return schemavalidator.PreferWriteOnlyAttribute{
WriteOnlyAttribute: writeOnlyAttribute,
}
}
34 changes: 34 additions & 0 deletions float64validator/prefer_write_only_attribute_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package float64validator_test

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
)

func ExamplePreferWriteOnlyAttribute() {
// Used within a Schema method of a Resource
_ = schema.Schema{
Attributes: map[string]schema.Attribute{
"example_attr": schema.Float64Attribute{
Optional: true,
Validators: []validator.Float64{
// Throws a warning diagnostic encouraging practitioners to use
// write_only_attr if example_attr has a value.
float64validator.PreferWriteOnlyAttribute(
path.MatchRoot("write_only_attr"),
),
},
},
"write_only_attr": schema.Float64Attribute{
WriteOnly: true,
Optional: true,
},
},
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.7

require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework v1.13.1-0.20250204221559-2b72dc0a12ab
github.com/hashicorp/terraform-plugin-go v0.26.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw=
github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU=
github.com/hashicorp/terraform-plugin-framework v1.13.1-0.20250204221559-2b72dc0a12ab h1:x1GxE9ztKndo/6CPnkA8yBfmj8z13063U0pY6ayKNFo=
github.com/hashicorp/terraform-plugin-framework v1.13.1-0.20250204221559-2b72dc0a12ab/go.mod h1:qBKUqe1lv1NZcsO5pBjiKd5YuNDUeqvV1w8w5df/8WI=
github.com/hashicorp/terraform-plugin-go v0.26.0 h1:cuIzCv4qwigug3OS7iKhpGAbZTiypAfFQmw8aE65O2M=
github.com/hashicorp/terraform-plugin-go v0.26.0/go.mod h1:+CXjuLDiFgqR+GcrM5a2E2Kal5t5q2jb0E3D57tTdNY=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
Expand Down
28 changes: 28 additions & 0 deletions int32validator/prefer_write_only_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package int32validator

import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"

"github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator"
)

// PreferWriteOnlyAttribute returns a warning if the Terraform client supports
// write-only attributes, and the attribute that the validator is applied to has a value.
// It takes in a path.Expression that represents the write-only attribute schema location,
// and the warning message will indicate that the write-only attribute should be preferred.
//
// This validator should only be used for resource attributes as other schema types do not
// support write-only attributes.
//
// This implements the validation logic declaratively within the schema.
// Refer to [resourcevalidator.PreferWriteOnlyAttribute]
// for declaring this type of validation outside the schema definition.
func PreferWriteOnlyAttribute(writeOnlyAttribute path.Expression) validator.Int32 {
return schemavalidator.PreferWriteOnlyAttribute{
WriteOnlyAttribute: writeOnlyAttribute,
}
}
Loading
Loading