Skip to content

Commit 758afb7

Browse files
SBGoodsaustinvalle
andauthored
all: Add float32 type, attribute, and function support (#1014)
* Initial Float32 implementation * Chang `NewFloat32Value` implementation * Add debug logs * Fix accuracy variable shadowing * Fix broken unit tests * Update documentation * Add changelog entries * Update debug logging * Add comment about float32 test variables * Add debug log only when value has exact accuracy in both `float32` and `float64` --------- Co-authored-by: Austin Valle <[email protected]>
1 parent 79b0229 commit 758afb7

File tree

95 files changed

+9266
-7
lines changed

Some content is hidden

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

95 files changed

+9266
-7
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 `Float32Type` and `Float32Value` implementations for
3+
Float32 value handling.'
4+
time: 2024-06-26T12:35:13.705873-04:00
5+
custom:
6+
Issue: "1014"
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.Float32Typable`, `basetypes.Float32Valuable`,
3+
and `basetypes.Float32ValuableWithSemanticEquals` for Float32 custom type and value
4+
implementations.'
5+
time: 2024-06-26T12:35:33.490507-04:00
6+
custom:
7+
Issue: "1014"
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: Added `Float32Attribute` implementation for Float32 value
3+
handling.'
4+
time: 2024-06-26T12:35:45.867977-04:00
5+
custom:
6+
Issue: "1014"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'datasource/schema: Added `Float32Attribute` implementation for Float32 value
3+
handling.'
4+
time: 2024-06-26T12:36:15.026076-04:00
5+
custom:
6+
Issue: "1014"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'provider/schema: Added `Float32Attribute` implementation for Float32 value
3+
handling.'
4+
time: 2024-06-26T12:36:40.047935-04:00
5+
custom:
6+
Issue: "1014"
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 `Float32Parameter` and `Float32Return` for Float32 value handling.'
3+
time: 2024-06-26T12:36:51.027757-04:00
4+
custom:
5+
Issue: "1014"
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/float32default: New package with `StaticValue` implementation
3+
for Float32 schema-based default values.'
4+
time: 2024-06-26T12:37:38.728292-04:00
5+
custom:
6+
Issue: "1014"
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/float32planmodifier: New package with built-in implementations
3+
for Float32 value plan modification.'
4+
time: 2024-06-26T12:38:20.591646-04:00
5+
custom:
6+
Issue: "1014"
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 `Float32` interface for Float32 schema-based
3+
default implementations.'
4+
time: 2024-06-26T12:38:36.234337-04:00
5+
custom:
6+
Issue: "1014"
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 `Float32` interface for Float32 value plan
3+
modification implementations.'
4+
time: 2024-06-26T12:39:09.284352-04:00
5+
custom:
6+
Issue: "1014"
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 `Float32` interface for Float32 value schema validation.'
3+
time: 2024-06-26T12:39:22.726132-04:00
4+
custom:
5+
Issue: "1014"
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 = Float32Attribute{}
20+
_ fwxschema.AttributeWithFloat32Validators = Float32Attribute{}
21+
)
22+
23+
// Float32Attribute represents a schema attribute that is a 32-bit floating
24+
// point number. When retrieving the value for this attribute, use
25+
// types.Float32 as the value type unless the CustomType field is set.
26+
//
27+
// Use Int32Attribute for 32-bit integer attributes or NumberAttribute for
28+
// 512-bit generic number attributes.
29+
//
30+
// Terraform configurations configure this attribute using expressions that
31+
// return a number or directly via a floating point value.
32+
//
33+
// example_attribute = 123.45
34+
//
35+
// Terraform configurations reference this attribute using the attribute name.
36+
//
37+
// .example_attribute
38+
type Float32Attribute struct {
39+
// CustomType enables the use of a custom attribute type in place of the
40+
// default basetypes.Float32Type. When retrieving data, the basetypes.Float32Valuable
41+
// associated with this custom type must be used in place of types.Float32.
42+
CustomType basetypes.Float32Typable
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.Float32
126+
}
127+
128+
// ApplyTerraform5AttributePathStep always returns an error as it is not
129+
// possible to step further into a Float32Attribute.
130+
func (a Float32Attribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
131+
return a.GetType().ApplyTerraform5AttributePathStep(step)
132+
}
133+
134+
// Equal returns true if the given Attribute is a Float32Attribute
135+
// and all fields are equal.
136+
func (a Float32Attribute) Equal(o fwschema.Attribute) bool {
137+
if _, ok := o.(Float32Attribute); !ok {
138+
return false
139+
}
140+
141+
return fwschema.AttributesEqual(a, o)
142+
}
143+
144+
// Float32Validators returns the Validators field value.
145+
func (a Float32Attribute) Float32Validators() []validator.Float32 {
146+
return a.Validators
147+
}
148+
149+
// GetDeprecationMessage returns the DeprecationMessage field value.
150+
func (a Float32Attribute) GetDeprecationMessage() string {
151+
return a.DeprecationMessage
152+
}
153+
154+
// GetDescription returns the Description field value.
155+
func (a Float32Attribute) GetDescription() string {
156+
return a.Description
157+
}
158+
159+
// GetMarkdownDescription returns the MarkdownDescription field value.
160+
func (a Float32Attribute) GetMarkdownDescription() string {
161+
return a.MarkdownDescription
162+
}
163+
164+
// GetType returns types.Float32Type or the CustomType field value if defined.
165+
func (a Float32Attribute) GetType() attr.Type {
166+
if a.CustomType != nil {
167+
return a.CustomType
168+
}
169+
170+
return types.Float32Type
171+
}
172+
173+
// IsComputed returns the Computed field value.
174+
func (a Float32Attribute) IsComputed() bool {
175+
return a.Computed
176+
}
177+
178+
// IsOptional returns the Optional field value.
179+
func (a Float32Attribute) IsOptional() bool {
180+
return a.Optional
181+
}
182+
183+
// IsRequired returns the Required field value.
184+
func (a Float32Attribute) IsRequired() bool {
185+
return a.Required
186+
}
187+
188+
// IsSensitive returns the Sensitive field value.
189+
func (a Float32Attribute) IsSensitive() bool {
190+
return a.Sensitive
191+
}

0 commit comments

Comments
 (0)