Skip to content

Commit 76b7831

Browse files
committed
add primitive types as well as list and map collection types
1 parent 52edf5b commit 76b7831

15 files changed

+4899
-0
lines changed

list/schema/attribute.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99

1010
// Attribute define a value field inside the Schema. Implementations in this
1111
// package include:
12+
// - BoolAttribute
13+
// - Float32Attribute
14+
// - Float64Attribute
15+
// - Int32Attribute
16+
// - Int64Attribute
17+
// - ListAttribute
18+
// - MapAttribute
1219
// - StringAttribute
1320
//
1421
// In practitioner configurations, an equals sign (=) is required to set

list/schema/bool_attribute.go

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package schema
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tftypes"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
10+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
11+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
12+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
13+
"github.com/hashicorp/terraform-plugin-framework/types"
14+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
15+
)
16+
17+
// Ensure the implementation satisifies the desired interfaces.
18+
var (
19+
_ Attribute = BoolAttribute{}
20+
_ fwxschema.AttributeWithBoolValidators = BoolAttribute{}
21+
)
22+
23+
// BoolAttribute represents a schema attribute that is a boolean. When
24+
// retrieving the value for this attribute, use types.Bool as the value type
25+
// unless the CustomType field is set.
26+
//
27+
// Terraform configurations configure this attribute using expressions that
28+
// return a boolean or directly via the true/false keywords.
29+
//
30+
// example_attribute = true
31+
//
32+
// Terraform configurations reference this attribute using the attribute name.
33+
//
34+
// .example_attribute
35+
type BoolAttribute struct {
36+
// CustomType enables the use of a custom attribute type in place of the
37+
// default basetypes.BoolType. When retrieving data, the basetypes.BoolValuable
38+
// associated with this custom type must be used in place of types.Bool.
39+
CustomType basetypes.BoolTypable
40+
41+
// Required indicates whether the practitioner must enter a value for
42+
// this attribute or not. Required and Optional cannot both be true,
43+
// and Required and Computed cannot both be true.
44+
Required bool
45+
46+
// Optional indicates whether the practitioner can choose to enter a value
47+
// for this attribute or not. Optional and Required cannot both be true.
48+
Optional bool
49+
50+
// Description is used in various tooling, like the language server, to
51+
// give practitioners more information about what this attribute is,
52+
// what it's for, and how it should be used. It should be written as
53+
// plain text, with no special formatting.
54+
Description string
55+
56+
// MarkdownDescription is used in various tooling, like the
57+
// documentation generator, to give practitioners more information
58+
// about what this attribute is, what it's for, and how it should be
59+
// used. It should be formatted using Markdown.
60+
MarkdownDescription string
61+
62+
// DeprecationMessage defines warning diagnostic details to display when
63+
// practitioner configurations use this Attribute. The warning diagnostic
64+
// summary is automatically set to "Attribute Deprecated" along with
65+
// configuration source file and line information.
66+
//
67+
// Set this field to a practitioner actionable message such as:
68+
//
69+
// - "Configure other_attribute instead. This attribute will be removed
70+
// in the next major version of the provider."
71+
// - "Remove this attribute's configuration as it no longer is used and
72+
// the attribute will be removed in the next major version of the
73+
// provider."
74+
//
75+
// In Terraform 1.2.7 and later, this warning diagnostic is displayed any
76+
// time a practitioner attempts to configure a value for this attribute and
77+
// certain scenarios where this attribute is referenced.
78+
//
79+
// In Terraform 1.2.6 and earlier, this warning diagnostic is only
80+
// displayed when the Attribute is Required or Optional, and if the
81+
// practitioner configuration sets the value to a known or unknown value
82+
// (which may eventually be null). It has no effect when the Attribute is
83+
// Computed-only (read-only; not Required or Optional).
84+
//
85+
// Across any Terraform version, there are no warnings raised for
86+
// practitioner configuration values set directly to null, as there is no
87+
// way for the framework to differentiate between an unset and null
88+
// configuration due to how Terraform sends configuration information
89+
// across the protocol.
90+
//
91+
// Additional information about deprecation enhancements for read-only
92+
// attributes can be found in:
93+
//
94+
// - https://github.com/hashicorp/terraform/issues/7569
95+
//
96+
DeprecationMessage string
97+
98+
// Validators define value validation functionality for the attribute. All
99+
// elements of the slice of AttributeValidator are run, regardless of any
100+
// previous error diagnostics.
101+
//
102+
// Many common use case validators can be found in the
103+
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
104+
//
105+
// If the Type field points to a custom type that implements the
106+
// xattr.TypeWithValidate interface, the validators defined in this field
107+
// are run in addition to the validation defined by the type.
108+
Validators []validator.Bool
109+
}
110+
111+
// ApplyTerraform5AttributePathStep always returns an error as it is not
112+
// possible to step further into a BoolAttribute.
113+
func (a BoolAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
114+
return a.GetType().ApplyTerraform5AttributePathStep(step)
115+
}
116+
117+
// BoolValidators returns the Validators field value.
118+
func (a BoolAttribute) BoolValidators() []validator.Bool {
119+
return a.Validators
120+
}
121+
122+
// Equal returns true if the given Attribute is a BoolAttribute
123+
// and all fields are equal.
124+
func (a BoolAttribute) Equal(o fwschema.Attribute) bool {
125+
if _, ok := o.(BoolAttribute); !ok {
126+
return false
127+
}
128+
129+
return fwschema.AttributesEqual(a, o)
130+
}
131+
132+
// GetDeprecationMessage returns the DeprecationMessage field value.
133+
func (a BoolAttribute) GetDeprecationMessage() string {
134+
return a.DeprecationMessage
135+
}
136+
137+
// GetDescription returns the Description field value.
138+
func (a BoolAttribute) GetDescription() string {
139+
return a.Description
140+
}
141+
142+
// GetMarkdownDescription returns the MarkdownDescription field value.
143+
func (a BoolAttribute) GetMarkdownDescription() string {
144+
return a.MarkdownDescription
145+
}
146+
147+
// GetType returns types.StringType or the CustomType field value if defined.
148+
func (a BoolAttribute) GetType() attr.Type {
149+
if a.CustomType != nil {
150+
return a.CustomType
151+
}
152+
153+
return types.BoolType
154+
}
155+
156+
// IsComputed returns false because it does not apply to ListResource schemas.
157+
func (a BoolAttribute) IsComputed() bool {
158+
return false
159+
}
160+
161+
// IsOptional returns the Optional field value.
162+
func (a BoolAttribute) IsOptional() bool {
163+
return a.Optional
164+
}
165+
166+
// IsRequired returns the Required field value.
167+
func (a BoolAttribute) IsRequired() bool {
168+
return a.Required
169+
}
170+
171+
// IsSensitive returns false because it does not apply to ListResource schemas.
172+
func (a BoolAttribute) IsSensitive() bool {
173+
return false
174+
}
175+
176+
// IsWriteOnly returns false because it does not apply to ListResource schemas.
177+
func (a BoolAttribute) IsWriteOnly() bool {
178+
return false
179+
}
180+
181+
// IsRequiredForImport returns false as this behavior is only relevant
182+
// for managed resource identity schema attributes.
183+
func (a BoolAttribute) IsRequiredForImport() bool {
184+
return false
185+
}
186+
187+
// IsOptionalForImport returns false as this behavior is only relevant
188+
// for managed resource identity schema attributes.
189+
func (a BoolAttribute) IsOptionalForImport() bool {
190+
return false
191+
}

0 commit comments

Comments
 (0)