-
Notifications
You must be signed in to change notification settings - Fork 99
list: add primitive, list and map types #1177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
76b7831
add primitive types as well as list and map collection types
stephybun 7279487
sort the listresources result to prevent false positives in test
stephybun e64d1a7
omit mention of Computed in the code comment for the Required attribute
stephybun 50ce0a5
add number type
stephybun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
setattributes as wellThere was a problem hiding this comment.
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.
DynamicAttributesounds like a helpful thing to have here though so I'll add that in a follow up PR.