-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathvalue.go
78 lines (65 loc) · 2.84 KB
/
value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package attr
import (
"context"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
const (
// UnknownValueString should be returned by Value.String() implementations,
// when Value.IsUnknown() returns true.
UnknownValueString = "<unknown>"
// NullValueString should be returned by Value.String() implementations
// when Value.IsNull() returns true.
NullValueString = "<null>"
// UnsetValueString should be returned by Value.String() implementations
// when Value does not contain sufficient information to display to users.
//
// This is primarily used for invalid Dynamic Value implementations.
UnsetValueString = "<unset>"
)
// Value defines an interface for describing data associated with an attribute.
// Values allow provider developers to specify data in a convenient format, and
// have it transparently be converted to formats Terraform understands.
type Value interface {
// Type returns the Type that created the Value.
Type(context.Context) Type
// ToTerraformValue returns the data contained in the Value as
// a tftypes.Value.
ToTerraformValue(context.Context) (tftypes.Value, error)
// Equal should return true if the Value is considered type and data
// value equivalent to the Value passed as an argument.
//
// Most types should verify the associated Type is exactly equal to prevent
// potential data consistency issues. For example:
//
// - basetypes.Number is inequal to basetypes.Int64 or basetypes.Float64
// - basetypes.String is inequal to a custom Go type that embeds it
//
// Additionally, most types should verify that known values are compared
// to comply with Terraform's data consistency rules. For example:
//
// - In a list, element order is significant
// - In a string, runes are compared byte-wise (e.g. whitespace is
// significant in JSON-encoded strings)
//
Equal(Value) bool
// IsNull returns true if the Value is not set, or is explicitly set to null.
IsNull() bool
// IsUnKnown returns true if the value is not yet known.
// If the value is an aggregate type, only the top level of the aggregate type
// is checked; elements and attributes are not checked.
IsUnknown() bool
// IsFullyNullableKnown returns true if the value is nullable known. If the value
// is an aggregate type, IsFullyNullableKnown only returns true if all elements
// and attributes are nullable known, as well.
IsFullyNullableKnown() bool
// String returns a summary representation of either the underlying Value,
// or UnknownValueString (`<unknown>`) when IsUnknown() returns true,
// or NullValueString (`<null>`) when IsNull() return true.
//
// This is an intentionally lossy representation, that are best suited for
// logging and error reporting, as they are not protected by
// compatibility guarantees within the framework.
String() string
}