int64validator

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: 9 Imported by: 150

Documentation

Overview

Package int64validator provides validators for types.Int64 attributes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtLeast

func AtLeast(min int64) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit integer.
  • Is exclusively greater than the given minimum.

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

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate integer value must be at least 42
					int64validator.AtLeast(42),
				},
			},
		},
	}
}

func AtLeastSumOf added in v0.4.0

func AtLeastSumOf(attributesToSumPathExpressions ...path.Expression) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit integer.
  • Is at least the sum of the attributes retrieved via the given path expression(s).

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

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate this integer value must be at least the
					// summed integer values of other_attr1 and other_attr2.
					int64validator.AtLeastSumOf(path.Expressions{
						path.MatchRoot("other_attr1"),
						path.MatchRoot("other_attr2"),
					}...),
				},
			},
			"other_attr1": {
				Required: true,
				Type:     types.Int64Type,
			},
			"other_attr2": {
				Required: true,
				Type:     types.Int64Type,
			},
		},
	}
}

func AtMost

func AtMost(max int64) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit integer.
  • Is exclusively less than the given maximum.

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

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate integer value must be at most 42
					int64validator.AtMost(42),
				},
			},
		},
	}
}

func AtMostSumOf added in v0.4.0

func AtMostSumOf(attributesToSumPathExpressions ...path.Expression) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit integer.
  • Is at most the sum of the given attributes retrieved via the given path expression(s).

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

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate this integer value must be at most the
					// summed integer values of other_attr1 and other_attr2.
					int64validator.AtMostSumOf(path.Expressions{
						path.MatchRoot("other_attr1"),
						path.MatchRoot("other_attr2"),
					}...),
				},
			},
			"other_attr1": {
				Required: true,
				Type:     types.Int64Type,
			},
			"other_attr2": {
				Required: true,
				Type:     types.Int64Type,
			},
		},
	}
}

func Between

func Between(min, max int64) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit integer.
  • Is exclusively greater than the given minimum and less than the given maximum.

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

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate integer value must be at least 10 and at most 100
					int64validator.Between(10, 100),
				},
			},
		},
	}
}

func EqualToSumOf added in v0.4.0

func EqualToSumOf(attributesToSumPathExpressions ...path.Expression) tfsdk.AttributeValidator

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

  • Is a number, which can be represented by a 64-bit integer.
  • Is equal to the sum of the given attributes retrieved via the given path expression(s).

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

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate this integer value must be equal to the
					// summed integer values of other_attr1 and other_attr2.
					int64validator.EqualToSumOf(path.Expressions{
						path.MatchRoot("other_attr1"),
						path.MatchRoot("other_attr2"),
					}...),
				},
			},
			"other_attr1": {
				Required: true,
				Type:     types.Int64Type,
			},
			"other_attr2": {
				Required: true,
				Type:     types.Int64Type,
			},
		},
	}
}

func NoneOf added in v0.3.0

func NoneOf(unacceptableInts ...int64) tfsdk.AttributeValidator

NoneOf checks that the int64 held in the attribute is none of the given `unacceptableInts`.

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate integer value must not be 12, 24, or 48
					int64validator.NoneOf([]int64{12, 24, 48}...),
				},
			},
		},
	}
}

func OneOf added in v0.3.0

func OneOf(acceptableInts ...int64) tfsdk.AttributeValidator

OneOf checks that the int64 held in the attribute is one of the given `acceptableInts`.

Example
package main

import (
	"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
	"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.Int64Type,
				Validators: []tfsdk.AttributeValidator{
					// Validate integer value must be 12, 24, or 48
					int64validator.OneOf([]int64{12, 24, 48}...),
				},
			},
		},
	}
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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