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
15 changes: 10 additions & 5 deletions action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package action

import (
"github.com/hashicorp/terraform-plugin-framework/action/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
)

// SchemaRequest represents a request for the Action to return its schema.
Expand All @@ -17,10 +17,15 @@ type SchemaRequest struct{}
// response struct is supplied as an argument to the Action type Schema
// method.
type SchemaResponse struct {
// TODO:Actions: This will eventually be replaced by an interface defined in
// an "actions/schema" package. Schema implementations that will fulfill this
// interface will be unlinked, linked, or lifecycle. (also defined in the "actions/schema" package)
Schema fwschema.Schema

// Schema is the schema of the action.
//
// There are three different types of actions, which define how a practitioner can trigger an action,
// as well as what effect the action can have on the state.
// - [schema.UnlinkedSchema] actions are actions that cannot cause changes to resource states.
// - [schema.LifecycleSchema] actions are actions that can cause changes to exactly one resource state.
// - [schema.LinkedSchema] actions are actions that can cause changes to one or more resource states.
Schema schema.SchemaType

// Diagnostics report errors or warnings related to retrieving the action schema.
// An empty slice indicates success, with no warnings or errors generated.
Expand Down
52 changes: 52 additions & 0 deletions action/schema/attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package schema

import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
)

// TODO:Actions: Add all of the attribute and nested attribute types listed below
//
// Attribute define a value field inside an action type schema. Implementations in this
// package include:
// - BoolAttribute
// - DynamicAttribute
// - Float32Attribute
// - Float64Attribute
// - Int32Attribute
// - Int64Attribute
// - ListAttribute
// - MapAttribute
// - NumberAttribute
// - ObjectAttribute
// - SetAttribute
// - StringAttribute
//
// Additionally, the NestedAttribute interface extends Attribute with nested
// attributes. Only supported in protocol version 6. Implementations in this
// package include:
// - ListNestedAttribute
// - MapNestedAttribute
// - SetNestedAttribute
// - SingleNestedAttribute
//
// In practitioner configurations, an equals sign (=) is required to set
// the value. [Configuration Reference]
//
// [Configuration Reference]: https://developer.hashicorp.com/terraform/language/syntax/configuration
type Attribute interface {
fwschema.Attribute
}

// schemaAttributes is an action attribute to fwschema type conversion function.
func schemaAttributes(attributes map[string]Attribute) map[string]fwschema.Attribute {
result := make(map[string]fwschema.Attribute, len(attributes))

for name, attribute := range attributes {
result[name] = attribute
}

return result
}
43 changes: 43 additions & 0 deletions action/schema/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package schema

import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
)

// TODO:Actions: Add all of the block and nested block types listed below
//
// Block defines a structural field inside an action type schema. Implementations in this
// package include:
// - ListNestedBlock
// - SetNestedBlock
// - SingleNestedBlock
//
// In practitioner configurations, an equals sign (=) cannot be used to set the
// value. Blocks are instead repeated as necessary, or require the use of
// [Dynamic Block Expressions].
//
// Prefer NestedAttribute over Block. Blocks should typically be used for
// configuration compatibility with previously existing schemas from an older
// Terraform Plugin SDK. Efforts should be made to convert from Block to
// NestedAttribute as a breaking change for practitioners.
//
// [Dynamic Block Expressions]: https://developer.hashicorp.com/terraform/language/expressions/dynamic-blocks
//
// [Configuration Reference]: https://developer.hashicorp.com/terraform/language/syntax/configuration
type Block interface {
fwschema.Block
}

// schemaBlocks is an action block to fwschema type conversion function.
func schemaBlocks(blocks map[string]Block) map[string]fwschema.Block {
result := make(map[string]fwschema.Block, len(blocks))

for name, block := range blocks {
result[name] = block
}

return result
}
170 changes: 170 additions & 0 deletions action/schema/bool_attribute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// 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/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// Ensure the implementation satisfies the desired interfaces.
var (
_ Attribute = 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,
// 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

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

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

// 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 always returns false as action schema attributes cannot be Computed.
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 always returns false as action schema attributes cannot be Sensitive.
func (a BoolAttribute) IsSensitive() bool {
return false
}

// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
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