-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathbool_attribute.go
205 lines (176 loc) · 7.51 KB
/
bool_attribute.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package schema
import (
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)
// Ensure the implementation satisifies the desired interfaces.
var (
_ Attribute = BoolAttribute{}
_ fwxschema.AttributeWithBoolValidators = BoolAttribute{}
)
// BoolAttribute represents a schema attribute that is a boolean. When
// retrieving the value for this attribute, use types.Bool as the value type
// unless the CustomType field is set.
//
// Terraform configurations configure this attribute using expressions that
// return a boolean or directly via the true/false keywords.
//
// example_attribute = true
//
// Terraform configurations reference this attribute using the attribute name.
//
// .example_attribute
type BoolAttribute struct {
// CustomType enables the use of a custom attribute type in place of the
// default basetypes.BoolType. When retrieving data, the basetypes.BoolValuable
// associated with this custom type must be used in place of types.Bool.
CustomType basetypes.BoolTypable
// Required indicates whether the practitioner must enter a value for
// this attribute or not. Required and Optional cannot both be true,
// and Required and Computed cannot both be true.
Required bool
// Optional indicates whether the practitioner can choose to enter a value
// for this attribute or not. Optional and Required cannot both be true.
Optional bool
// Computed indicates whether the provider may return its own value for
// this Attribute or not. Required and Computed cannot both be true. If
// Required and Optional are both false, Computed must be true, and the
// attribute will be considered "read only" for the practitioner, with
// only the provider able to set its value.
Computed bool
// Sensitive indicates whether the value of this attribute should be
// considered sensitive data. Setting it to true will obscure the value
// in CLI output. Sensitive does not impact how values are stored, and
// practitioners are encouraged to store their state as if the entire
// file is sensitive.
Sensitive bool
// Description is used in various tooling, like the language server, to
// give practitioners more information about what this attribute is,
// what it's for, and how it should be used. It should be written as
// plain text, with no special formatting.
Description string
// MarkdownDescription is used in various tooling, like the
// documentation generator, to give practitioners more information
// about what this attribute is, what it's for, and how it should be
// used. It should be formatted using Markdown.
MarkdownDescription string
// DeprecationMessage defines warning diagnostic details to display when
// practitioner configurations use this Attribute. The warning diagnostic
// summary is automatically set to "Attribute Deprecated" along with
// configuration source file and line information.
//
// Set this field to a practitioner actionable message such as:
//
// - "Configure other_attribute instead. This attribute will be removed
// in the next major version of the provider."
// - "Remove this attribute's configuration as it no longer is used and
// the attribute will be removed in the next major version of the
// provider."
//
// In Terraform 1.2.7 and later, this warning diagnostic is displayed any
// time a practitioner attempts to configure a value for this attribute and
// certain scenarios where this attribute is referenced.
//
// In Terraform 1.2.6 and earlier, this warning diagnostic is only
// displayed when the Attribute is Required or Optional, and if the
// practitioner configuration sets the value to a known or unknown value
// (which may eventually be null). It has no effect when the Attribute is
// Computed-only (read-only; not Required or Optional).
//
// Across any Terraform version, there are no warnings raised for
// practitioner configuration values set directly to null, as there is no
// way for the framework to differentiate between an unset and null
// configuration due to how Terraform sends configuration information
// across the protocol.
//
// Additional information about deprecation enhancements for read-only
// attributes can be found in:
//
// - https://github.com/hashicorp/terraform/issues/7569
//
DeprecationMessage string
// Validators define value validation functionality for the attribute. All
// elements of the slice of AttributeValidator are run, regardless of any
// previous error diagnostics.
//
// Many common use case validators can be found in the
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
//
// If the Type field points to a custom type that implements the
// xattr.TypeWithValidate interface, the validators defined in this field
// are run in addition to the validation defined by the type.
Validators []validator.Bool
}
// ApplyTerraform5AttributePathStep always returns an error as it is not
// possible to step further into a BoolAttribute.
func (a BoolAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
return a.GetType().ApplyTerraform5AttributePathStep(step)
}
// BoolValidators returns the Validators field value.
func (a BoolAttribute) BoolValidators() []validator.Bool {
return a.Validators
}
// Equal returns true if the given Attribute is a BoolAttribute
// and all fields are equal.
func (a BoolAttribute) Equal(o fwschema.Attribute) bool {
if _, ok := o.(BoolAttribute); !ok {
return false
}
return fwschema.AttributesEqual(a, o)
}
// GetDeprecationMessage returns the DeprecationMessage field value.
func (a BoolAttribute) GetDeprecationMessage() string {
return a.DeprecationMessage
}
// GetDescription returns the Description field value.
func (a BoolAttribute) GetDescription() string {
return a.Description
}
// GetMarkdownDescription returns the MarkdownDescription field value.
func (a BoolAttribute) GetMarkdownDescription() string {
return a.MarkdownDescription
}
// GetType returns types.StringType or the CustomType field value if defined.
func (a BoolAttribute) GetType() attr.Type {
if a.CustomType != nil {
return a.CustomType
}
return types.BoolType
}
// IsComputed returns the Computed field value.
func (a BoolAttribute) IsComputed() bool {
return a.Computed
}
// IsOptional returns the Optional field value.
func (a BoolAttribute) IsOptional() bool {
return a.Optional
}
// IsRequired returns the Required field value.
func (a BoolAttribute) IsRequired() bool {
return a.Required
}
// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a BoolAttribute) IsWriteOnly() bool {
return false
}
// IsSensitive returns the Sensitive field value.
func (a BoolAttribute) IsSensitive() bool {
return a.Sensitive
}
// IsRequiredForImport returns false as this behavior is only relevant
// for managed resource identity schema attributes.
func (a BoolAttribute) IsRequiredForImport() bool {
return false
}
// IsOptionalForImport returns false as this behavior is only relevant
// for managed resource identity schema attributes.
func (a BoolAttribute) IsOptionalForImport() bool {
return false
}