A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/float64validator below:

float64validator package - github.com/hashicorp/terraform-plugin-framework-validators/float64validator - Go Packages

Package float64validator provides validators for types.Float64 attributes or function parameters.

This section is empty.

This section is empty.

All returns a validator which ensures that any configured attribute value attribute value validates against all the given validators.

Use of All is only necessary when used in conjunction with Any or AnyWithAllWarnings as the Validators field automatically applies a logical AND.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate this Float64 value must either be:
					//  - 1.0
					//  - At least 2.0, but not 3.0
					float64validator.Any(
						float64validator.OneOf(1.0),
						float64validator.All(
							float64validator.AtLeast(2.0),
							float64validator.NoneOf(3.0),
						),
					),
				},
			},
		},
	}
}

AlsoRequires checks that a set of path.Expression has a non-null value, if the current attribute 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 being validated.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Optional: true,
				Validators: []validator.Float64{
					// Validate this attribute must be configured with other_attr.
					float64validator.AlsoRequires(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}

Any returns a validator which ensures that any configured attribute value passes at least one of the given validators.

To prevent practitioner confusion should non-passing validators have conflicting logic, only warnings from the passing validator are returned. Use AnyWithAllWarnings() to return warnings from non-passing validators as well.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate this Float64 value must either be:
					//  - 1.0
					//  - At least 2.0
					float64validator.Any(
						float64validator.OneOf(1.0),
						float64validator.AtLeast(2.0),
					),
				},
			},
		},
	}
}

AnyWithAllWarnings returns a validator which ensures that any configured attribute value passes at least one of the given validators. This validator returns all warnings, including failed validators.

Use Any() to return warnings only from the passing validator.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate this Float64 value must either be:
					//  - 1.0
					//  - At least 2.0
					float64validator.AnyWithAllWarnings(
						float64validator.OneOf(1.0),
						float64validator.AtLeast(2.0),
					),
				},
			},
		},
	}
}
func AtLeast(minVal float64) atLeastValidator

AtLeast returns an AttributeValidator which ensures that any configured attribute or function parameter value:

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate floating point value must be at least 42.42
					float64validator.AtLeast(42.42),
				},
			},
		},
	}
}
package main

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

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.Float64Parameter{
				Name: "example_param",
				Validators: []function.Float64ParameterValidator{
					// Validate floating point value must be at least 42.42
					float64validator.AtLeast(42.42),
				},
			},
		},
	}
}

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.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Optional: true,
				Validators: []validator.Float64{
					// Validate at least this attribute or other_attr should be configured.
					float64validator.AtLeastOneOf(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}
func AtMost(maxVal float64) atMostValidator

AtMost returns an AttributeValidator which ensures that any configured attribute or function parameter value:

Null (unconfigured) and unknown (known after apply) values are skipped.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate floating point value must be at most 42.42
					float64validator.AtMost(42.42),
				},
			},
		},
	}
}
package main

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

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.Float64Parameter{
				Name: "example_param",
				Validators: []function.Float64ParameterValidator{
					// Validate floating point value must be at most 42.42
					float64validator.AtMost(42.42),
				},
			},
		},
	}
}
func Between(minVal, maxVal float64) betweenValidator

Between returns an AttributeValidator which ensures that any configured attribute or function parameter value:

Null (unconfigured) and unknown (known after apply) values are skipped.

minVal cannot be greater than maxVal. Invalid combinations of minVal and maxVal will result in an implementation error message during validation.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate floating point value must be at least 0.0 and at most 1.0
					float64validator.Between(0.0, 1.0),
				},
			},
		},
	}
}
package main

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

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.Float64Parameter{
				Name: "example_param",
				Validators: []function.Float64ParameterValidator{
					// Validate floating point value must be at least 0.0 and at most 1.0
					float64validator.Between(0.0, 1.0),
				},
			},
		},
	}
}

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.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Optional: true,
				Validators: []validator.Float64{
					// Validate this attribute must not be configured with other_attr.
					float64validator.ConflictsWith(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}

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.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Optional: true,
				Validators: []validator.Float64{
					// Validate only this attribute or other_attr is configured.
					float64validator.ExactlyOneOf(path.Expressions{
						path.MatchRoot("other_attr"),
					}...),
				},
			},
			"other_attr": schema.StringAttribute{
				Optional: true,
			},
		},
	}
}
func NoneOf(values ...float64) noneOfValidator

NoneOf checks that the float64 held in the attribute or function parameter is none of the given `values`.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate floating point value must not be 1.2, 2.4, or 4.8
					float64validator.NoneOf([]float64{1.2, 2.4, 4.8}...),
				},
			},
		},
	}
}
package main

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

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.Float64Parameter{
				Name: "example_param",
				Validators: []function.Float64ParameterValidator{
					// Validate floating point value must not be 1.2, 2.4, or 4.8
					float64validator.NoneOf([]float64{1.2, 2.4, 4.8}...),
				},
			},
		},
	}
}
func OneOf(values ...float64) oneOfValidator

OneOf checks that the float64 held in the attribute or function parameter is one of the given `values`.

package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func main() {
	// Used within a Schema method of a DataSource, Provider, or Resource
	_ = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"example_attr": schema.Float64Attribute{
				Required: true,
				Validators: []validator.Float64{
					// Validate floating point value must be 1.2, 2.4, or 4.8
					float64validator.OneOf([]float64{1.2, 2.4, 4.8}...),
				},
			},
		},
	}
}
package main

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

func main() {
	_ = function.Definition{
		Parameters: []function.Parameter{
			function.Float64Parameter{
				Name: "example_param",
				Validators: []function.Float64ParameterValidator{
					// Validate floating point value must be 1.2, 2.4, or 4.8
					float64validator.OneOf([]float64{1.2, 2.4, 4.8}...),
				},
			},
		},
	}
}

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.

NOTE: This validator will produce persistent warnings for practitioners on every Terraform run as long as the specified non-write-only attribute has a value in the configuration. The validator will also produce warnings for users of shared modules who cannot immediately take action on the warning.

package main

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 main() {
	// 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,
			},
		},
	}
}

This section is empty.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4