numbervalidator

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MPL-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package numbervalidator provides validators for types.Number attributes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoneOf

func NoneOf(unacceptableFloats ...*big.Float) tfsdk.AttributeValidator

NoneOf checks that the *big.Float held in the attribute is none of the given `unacceptableFloats`.

Example
package main

import (
	"math/big"

	"github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator"
	"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.NumberType,
				Validators: []tfsdk.AttributeValidator{
					// Validate number value must not be 1.2, 2.4, or 4.8
					numbervalidator.NoneOf(
						[]*big.Float{
							big.NewFloat(1.2),
							big.NewFloat(2.4),
							big.NewFloat(4.8),
						}...,
					),
				},
			},
		},
	}
}
Output:

func OneOf

func OneOf(acceptableFloats ...*big.Float) tfsdk.AttributeValidator

OneOf checks that the *big.Float held in the attribute is one of the given `acceptableFloats`.

Example
package main

import (
	"math/big"

	"github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator"
	"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.NumberType,
				Validators: []tfsdk.AttributeValidator{
					// Validate number value must be 1.2, 2.4, or 4.8
					numbervalidator.OneOf(
						[]*big.Float{
							big.NewFloat(1.2),
							big.NewFloat(2.4),
							big.NewFloat(4.8),
						}...,
					),
				},
			},
		},
	}
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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