Skip to content

Commit

Permalink
all: Add int32 type, attribute, and function support (#1010)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
SBGoods and austinvalle authored Jun 26, 2024
1 parent c9804e9 commit 79b0229
Show file tree
Hide file tree
Showing 100 changed files with 9,065 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132125.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'types/basetypes: Added `Int32Type` and `Int32Value` implementations for Int32
value handling.'
time: 2024-06-21T13:21:25.992757-04:00
custom:
Issue: "1010"
7 changes: 7 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132243.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: FEATURES
body: 'types/basetypes: Added interfaces `basetypes.Int32Typable`, `basetypes.Int32Valuable`,
and `basetypes.Int32ValuableWithSemanticEquals` for Int32 custom type and value
implementations.'
time: 2024-06-21T13:22:43.724425-04:00
custom:
Issue: "1010"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132259.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'resource/schema: Added `Int32Attribute` implementation for Int32 value handling.'
time: 2024-06-21T13:22:59.609657-04:00
custom:
Issue: "1010"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132322.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'datasource/schema: Added `Int32Attribute` implementation for Int32 value handling.'
time: 2024-06-21T13:23:22.546135-04:00
custom:
Issue: "1010"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132350.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'provider/schema: Added `Int32Attribute` implementation for Int32 value handling.'
time: 2024-06-21T13:23:50.972247-04:00
custom:
Issue: "1010"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132410.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'function: Added `Int32Parameter` and `Int32Return` for Int32 value handling.'
time: 2024-06-21T13:24:10.410418-04:00
custom:
Issue: "1010"
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132424.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'resource/schema/int32default: New package with `StaticValue` implementation
for Int32 schema-based default values.'
time: 2024-06-21T13:24:24.170126-04:00
custom:
Issue: "1010"
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132441.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'resource/schema/int32planmodifier: New package with built-in implementations
for Int32 value plan modification.'
time: 2024-06-21T13:24:41.31229-04:00
custom:
Issue: "1010"
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132456.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'resource/schema/defaults: New `Int32` interface for Int32 schema-based default
implementations.'
time: 2024-06-21T13:24:56.747674-04:00
custom:
Issue: "1010"
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132514.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'resource/schema/planmodifier: New `Int32` interface for Int32 value plan modification
implementations.'
time: 2024-06-21T13:25:14.959554-04:00
custom:
Issue: "1010"
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20240621-132528.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'schema/validator: New `Int32` interface for Int32 value schema validation.'
time: 2024-06-21T13:25:28.832045-04:00
custom:
Issue: "1010"
191 changes: 191 additions & 0 deletions datasource/schema/int32_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// 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 = Int32Attribute{}
_ fwxschema.AttributeWithInt32Validators = Int32Attribute{}
)

// Int32Attribute represents a schema attribute that is a 32-bit integer.
// When retrieving the value for this attribute, use types.Int32 as the value
// type unless the CustomType field is set.
//
// Use Float32Attribute for 32-bit floating point number attributes or
// NumberAttribute for 512-bit generic number attributes.
//
// Terraform configurations configure this attribute using expressions that
// return a number or directly via an integer value.
//
// example_attribute = 123
//
// Terraform configurations reference this attribute using the attribute name.
//
// .example_attribute
type Int32Attribute struct {
// CustomType enables the use of a custom attribute type in place of the
// default basetypes.Int32Type. When retrieving data, the basetypes.Int32Valuable
// associated with this custom type must be used in place of types.Int32.
CustomType basetypes.Int32Typable

// 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.Int32
}

// ApplyTerraform5AttributePathStep always returns an error as it is not
// possible to step further into a Int32Attribute.
func (a Int32Attribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// Equal returns true if the given Attribute is a Int32Attribute
// and all fields are equal.
func (a Int32Attribute) Equal(o fwschema.Attribute) bool {
if _, ok := o.(Int32Attribute); !ok {
return false
}

return fwschema.AttributesEqual(a, o)
}

// GetDeprecationMessage returns the DeprecationMessage field value.
func (a Int32Attribute) GetDeprecationMessage() string {
return a.DeprecationMessage
}

// GetDescription returns the Description field value.
func (a Int32Attribute) GetDescription() string {
return a.Description
}

// GetMarkdownDescription returns the MarkdownDescription field value.
func (a Int32Attribute) GetMarkdownDescription() string {
return a.MarkdownDescription
}

// GetType returns types.Int32Type or the CustomType field value if defined.
func (a Int32Attribute) GetType() attr.Type {
if a.CustomType != nil {
return a.CustomType
}

return types.Int32Type
}

// Int32Validators returns the Validators field value.
func (a Int32Attribute) Int32Validators() []validator.Int32 {
return a.Validators
}

// IsComputed returns the Computed field value.
func (a Int32Attribute) IsComputed() bool {
return a.Computed
}

// IsOptional returns the Optional field value.
func (a Int32Attribute) IsOptional() bool {
return a.Optional
}

// IsRequired returns the Required field value.
func (a Int32Attribute) IsRequired() bool {
return a.Required
}

// IsSensitive returns the Sensitive field value.
func (a Int32Attribute) IsSensitive() bool {
return a.Sensitive
}
Loading

0 comments on commit 79b0229

Please sign in to comment.