float64validator

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2022 License: MPL-2.0 Imports: 7 Imported by: 13

Documentation

Overview

Package float64validator provides validators for types.Float64 attributes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtLeast

func AtLeast(min float64) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit floating point.
  • Is greater than or equal to the given minimum.

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

Example
package main

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

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

func AtMost

func AtMost(max float64) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit floating point.
  • Is less than or equal to the given maximum.

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

Example
package main

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

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

func Between

func Between(min, max float64) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit floating point.
  • Is greater than or equal to the given minimum and less than or equal to the given maximum.

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

Example
package main

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

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

func NoneOf added in v0.3.0

func NoneOf(unacceptableFloats ...float64) tfsdk.AttributeValidator

NoneOf checks that the float64 held in the attribute is none of the given `unacceptableFloats`.

Example
package main

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

func main() {
	// Used within a GetSchema method of a DataSource, Provider, or Resource
	_ = tfsdk.Schema{
		Attributes: map[string]tfsdk.Attribute{
			"example_attr": {
				Required: true,
				Type:     types.Float64Type,
				Validators: []tfsdk.AttributeValidator{
					// 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 added in v0.3.0

func OneOf(acceptableFloats ...float64) tfsdk.AttributeValidator

OneOf checks that the float64 held in the attribute is one of the given `acceptableFloats`.

Example
package main

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

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

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL