Skip to content

Commit 79b0229

Browse files
SBGoodsaustinvalle
andauthored
all: Add int32 type, attribute, and function support (#1010)
* Add support for `int32` type * Add website documentation * Add navigation routes to website * Add changelog entries * Fix documentation typos Co-authored-by: Austin Valle <[email protected]> * Fix casing Co-authored-by: Austin Valle <[email protected]> * Add `toproto5` package test * Remove `metaschema` package implementation * Add int32 types to tables and fix typos * Add edge case testing --------- Co-authored-by: Austin Valle <[email protected]>
1 parent c9804e9 commit 79b0229

File tree

100 files changed

+9065
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+9065
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'types/basetypes: Added `Int32Type` and `Int32Value` implementations for Int32
3+
value handling.'
4+
time: 2024-06-21T13:21:25.992757-04:00
5+
custom:
6+
Issue: "1010"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: FEATURES
2+
body: 'types/basetypes: Added interfaces `basetypes.Int32Typable`, `basetypes.Int32Valuable`,
3+
and `basetypes.Int32ValuableWithSemanticEquals` for Int32 custom type and value
4+
implementations.'
5+
time: 2024-06-21T13:22:43.724425-04:00
6+
custom:
7+
Issue: "1010"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'resource/schema: Added `Int32Attribute` implementation for Int32 value handling.'
3+
time: 2024-06-21T13:22:59.609657-04:00
4+
custom:
5+
Issue: "1010"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'datasource/schema: Added `Int32Attribute` implementation for Int32 value handling.'
3+
time: 2024-06-21T13:23:22.546135-04:00
4+
custom:
5+
Issue: "1010"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'provider/schema: Added `Int32Attribute` implementation for Int32 value handling.'
3+
time: 2024-06-21T13:23:50.972247-04:00
4+
custom:
5+
Issue: "1010"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'function: Added `Int32Parameter` and `Int32Return` for Int32 value handling.'
3+
time: 2024-06-21T13:24:10.410418-04:00
4+
custom:
5+
Issue: "1010"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'resource/schema/int32default: New package with `StaticValue` implementation
3+
for Int32 schema-based default values.'
4+
time: 2024-06-21T13:24:24.170126-04:00
5+
custom:
6+
Issue: "1010"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'resource/schema/int32planmodifier: New package with built-in implementations
3+
for Int32 value plan modification.'
4+
time: 2024-06-21T13:24:41.31229-04:00
5+
custom:
6+
Issue: "1010"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'resource/schema/defaults: New `Int32` interface for Int32 schema-based default
3+
implementations.'
4+
time: 2024-06-21T13:24:56.747674-04:00
5+
custom:
6+
Issue: "1010"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'resource/schema/planmodifier: New `Int32` interface for Int32 value plan modification
3+
implementations.'
4+
time: 2024-06-21T13:25:14.959554-04:00
5+
custom:
6+
Issue: "1010"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'schema/validator: New `Int32` interface for Int32 value schema validation.'
3+
time: 2024-06-21T13:25:28.832045-04:00
4+
custom:
5+
Issue: "1010"

datasource/schema/int32_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 = Int32Attribute{}
20+
_ fwxschema.AttributeWithInt32Validators = Int32Attribute{}
21+
)
22+
23+
// Int32Attribute represents a schema attribute that is a 32-bit integer.
24+
// When retrieving the value for this attribute, use types.Int32 as the value
25+
// type unless the CustomType field is set.
26+
//
27+
// Use Float32Attribute for 32-bit floating point number attributes or
28+
// NumberAttribute for 512-bit generic number attributes.
29+
//
30+
// Terraform configurations configure this attribute using expressions that
31+
// return a number or directly via an integer value.
32+
//
33+
// example_attribute = 123
34+
//
35+
// Terraform configurations reference this attribute using the attribute name.
36+
//
37+
// .example_attribute
38+
type Int32Attribute struct {
39+
// CustomType enables the use of a custom attribute type in place of the
40+
// default basetypes.Int32Type. When retrieving data, the basetypes.Int32Valuable
41+
// associated with this custom type must be used in place of types.Int32.
42+
CustomType basetypes.Int32Typable
43+
44+
// Required indicates whether the practitioner must enter a value for
45+
// this attribute or not. Required and Optional cannot both be true,
46+
// and Required and Computed cannot both be true.
47+
Required bool
48+
49+
// Optional indicates whether the practitioner can choose to enter a value
50+
// for this attribute or not. Optional and Required cannot both be true.
51+
Optional bool
52+
53+
// Computed indicates whether the provider may return its own value for
54+
// this Attribute or not. Required and Computed cannot both be true. If
55+
// Required and Optional are both false, Computed must be true, and the
56+
// attribute will be considered "read only" for the practitioner, with
57+
// only the provider able to set its value.
58+
Computed bool
59+
60+
// Sensitive indicates whether the value of this attribute should be
61+
// considered sensitive data. Setting it to true will obscure the value
62+
// in CLI output. Sensitive does not impact how values are stored, and
63+
// practitioners are encouraged to store their state as if the entire
64+
// file is sensitive.
65+
Sensitive bool
66+
67+
// Description is used in various tooling, like the language server, to
68+
// give practitioners more information about what this attribute is,
69+
// what it's for, and how it should be used. It should be written as
70+
// plain text, with no special formatting.
71+
Description string
72+
73+
// MarkdownDescription is used in various tooling, like the
74+
// documentation generator, to give practitioners more information
75+
// about what this attribute is, what it's for, and how it should be
76+
// used. It should be formatted using Markdown.
77+
MarkdownDescription string
78+
79+
// DeprecationMessage defines warning diagnostic details to display when
80+
// practitioner configurations use this Attribute. The warning diagnostic
81+
// summary is automatically set to "Attribute Deprecated" along with
82+
// configuration source file and line information.
83+
//
84+
// Set this field to a practitioner actionable message such as:
85+
//
86+
// - "Configure other_attribute instead. This attribute will be removed
87+
// in the next major version of the provider."
88+
// - "Remove this attribute's configuration as it no longer is used and
89+
// the attribute will be removed in the next major version of the
90+
// provider."
91+
//
92+
// In Terraform 1.2.7 and later, this warning diagnostic is displayed any
93+
// time a practitioner attempts to configure a value for this attribute and
94+
// certain scenarios where this attribute is referenced.
95+
//
96+
// In Terraform 1.2.6 and earlier, this warning diagnostic is only
97+
// displayed when the Attribute is Required or Optional, and if the
98+
// practitioner configuration sets the value to a known or unknown value
99+
// (which may eventually be null). It has no effect when the Attribute is
100+
// Computed-only (read-only; not Required or Optional).
101+
//
102+
// Across any Terraform version, there are no warnings raised for
103+
// practitioner configuration values set directly to null, as there is no
104+
// way for the framework to differentiate between an unset and null
105+
// configuration due to how Terraform sends configuration information
106+
// across the protocol.
107+
//
108+
// Additional information about deprecation enhancements for read-only
109+
// attributes can be found in:
110+
//
111+
// - https://github.com/hashicorp/terraform/issues/7569
112+
//
113+
DeprecationMessage string
114+
115+
// Validators define value validation functionality for the attribute. All
116+
// elements of the slice of AttributeValidator are run, regardless of any
117+
// previous error diagnostics.
118+
//
119+
// Many common use case validators can be found in the
120+
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
121+
//
122+
// If the Type field points to a custom type that implements the
123+
// xattr.TypeWithValidate interface, the validators defined in this field
124+
// are run in addition to the validation defined by the type.
125+
Validators []validator.Int32
126+
}
127+
128+
// ApplyTerraform5AttributePathStep always returns an error as it is not
129+
// possible to step further into a Int32Attribute.
130+
func (a Int32Attribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
131+
return a.GetType().ApplyTerraform5AttributePathStep(step)
132+
}
133+
134+
// Equal returns true if the given Attribute is a Int32Attribute
135+
// and all fields are equal.
136+
func (a Int32Attribute) Equal(o fwschema.Attribute) bool {
137+
if _, ok := o.(Int32Attribute); !ok {
138+
return false
139+
}
140+
141+
return fwschema.AttributesEqual(a, o)
142+
}
143+
144+
// GetDeprecationMessage returns the DeprecationMessage field value.
145+
func (a Int32Attribute) GetDeprecationMessage() string {
146+
return a.DeprecationMessage
147+
}
148+
149+
// GetDescription returns the Description field value.
150+
func (a Int32Attribute) GetDescription() string {
151+
return a.Description
152+
}
153+
154+
// GetMarkdownDescription returns the MarkdownDescription field value.
155+
func (a Int32Attribute) GetMarkdownDescription() string {
156+
return a.MarkdownDescription
157+
}
158+
159+
// GetType returns types.Int32Type or the CustomType field value if defined.
160+
func (a Int32Attribute) GetType() attr.Type {
161+
if a.CustomType != nil {
162+
return a.CustomType
163+
}
164+
165+
return types.Int32Type
166+
}
167+
168+
// Int32Validators returns the Validators field value.
169+
func (a Int32Attribute) Int32Validators() []validator.Int32 {
170+
return a.Validators
171+
}
172+
173+
// IsComputed returns the Computed field value.
174+
func (a Int32Attribute) IsComputed() bool {
175+
return a.Computed
176+
}
177+
178+
// IsOptional returns the Optional field value.
179+
func (a Int32Attribute) IsOptional() bool {
180+
return a.Optional
181+
}
182+
183+
// IsRequired returns the Required field value.
184+
func (a Int32Attribute) IsRequired() bool {
185+
return a.Required
186+
}
187+
188+
// IsSensitive returns the Sensitive field value.
189+
func (a Int32Attribute) IsSensitive() bool {
190+
return a.Sensitive
191+
}

0 commit comments

Comments
 (0)