Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/proto5server/server_getmetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ func TestServerGetMetadata(t *testing.T) {
return got.Functions[i].Name < got.Functions[j].Name
})

sort.Slice(got.ListResources, func(i int, j int) bool {
return got.ListResources[i].TypeName < got.ListResources[j].TypeName
})

sort.Slice(got.Resources, func(i int, j int) bool {
return got.Resources[i].TypeName < got.Resources[j].TypeName
})
Expand Down
4 changes: 4 additions & 0 deletions internal/proto6server/server_getmetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ func TestServerGetMetadata(t *testing.T) {
return got.Functions[i].Name < got.Functions[j].Name
})

sort.Slice(got.ListResources, func(i int, j int) bool {
return got.ListResources[i].TypeName < got.ListResources[j].TypeName
})

sort.Slice(got.Resources, func(i int, j int) bool {
return got.Resources[i].TypeName < got.Resources[j].TypeName
})
Expand Down
8 changes: 8 additions & 0 deletions list/schema/attribute.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, as we can always come back later and add more types

Is it written down anywhere the full list of attribute types we'll end up supporting for list configs? I couldn't find it in any of the RFCs 👀

Since the configuration syntax is in a nested block, we should be able to support all of the nested types as well (nested attributes, nested blocks), unless we are explicitly choosing not to support them.

If we don't support either nested types, we might want to consider also supporting single object types via an ObjectAttribute.


I'd also be interested if we are going to support DynamicAttribute / DynamicPseudoType, which is also kind of a "primitive" attribute depending on how you view it 😆


And related to collections, the set attributes as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it was agreed to limit support to lists and maps of primitives in an internal discussion. DynamicAttribute sounds like a helpful thing to have here though so I'll add that in a follow up PR.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import (

// Attribute define a value field inside the Schema. Implementations in this
// package include:
// - BoolAttribute
// - Float32Attribute
// - Float64Attribute
// - Int32Attribute
// - Int64Attribute
// - ListAttribute
// - MapAttribute
// - NumberAttribute
// - StringAttribute
//
// In practitioner configurations, an equals sign (=) is required to set
Expand Down
190 changes: 190 additions & 0 deletions list/schema/bool_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
// 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.
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

// 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 false because it does not apply to ListResource schemas.
func (a BoolAttribute) IsComputed() bool {
return false
}

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

// IsSensitive returns false because it does not apply to ListResource schemas.
func (a BoolAttribute) IsSensitive() bool {
return false
}

// IsWriteOnly returns false because it does not apply to ListResource schemas.
func (a BoolAttribute) IsWriteOnly() bool {
return false
}

// 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
}
Loading
Loading