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
5 changes: 2 additions & 3 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ type Action interface {
// Metadata should return the full name of the action, such as examplecloud_do_thing.
Metadata(context.Context, MetadataRequest, *MetadataResponse)

// Invoke is called to run the logic of the action and update linked resources if applicable.
// Config, linked resource planned state, and linked resource prior state values should
// be read from the InvokeRequest and new linked resource state values set on the InvokeResponse.
// Invoke is called to run the logic of the action. Config values should be read from the InvokeRequest
// and potential diagnostics set in InvokeResponse.
//
// The [InvokeResponse.SendProgress] function can be called in the Invoke method to immediately
// report progress events related to the invocation of the action to Terraform.
Expand Down
12 changes: 3 additions & 9 deletions action/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,25 @@ import (
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// InvokeRequest represents a request for the provider to invoke the action and update
// the requested action's linked resources.
// InvokeRequest represents a request for the provider to invoke the action.
type InvokeRequest struct {
// Config is the configuration the user supplied for the action.
Config tfsdk.Config

// TODO:Actions: Add linked resources when new action schema types are introduced
}

// InvokeResponse represents a response to an InvokeRequest. An
// instance of this response struct is supplied as
// an argument to the action's Invoke function, in which the provider
// should set values on the InvokeResponse as appropriate.
type InvokeResponse struct {
// Diagnostics report errors or warnings related to invoking the action or updating
// the state of the requested action's linked resources. Returning an empty slice
// Diagnostics report errors or warnings related to invoking the action. Returning an empty slice
// indicates a successful invocation with no warnings or errors
// generated.
Diagnostics diag.Diagnostics

// SendProgress will immediately send a progress update to Terraform core during action invocation.
// This function is pre-populated by the framework and can be called multiple times while action logic is running.
// This function is provided by the framework and can be called multiple times while action logic is running.
SendProgress func(event InvokeProgressEvent)

// TODO:Actions: Add linked resources when new action schema types are introduced
}

// InvokeProgressEvent is the event returned to Terraform while an action is being invoked.
Expand Down
19 changes: 7 additions & 12 deletions action/modify_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type ModifyPlanClientCapabilities struct {
DeferralAllowed bool
}

// ModifyPlanRequest represents a request for the provider to modify the
// planned new state that Terraform has generated for any linked resources.
// ModifyPlanRequest represents a request for the provider during planning.
// The plan can be used as an opportunity to raise early
// diagnostics to practitioners, such as validation errors.
type ModifyPlanRequest struct {
// Config is the configuration the user supplied for the action.
//
Expand All @@ -30,26 +31,20 @@ type ModifyPlanRequest struct {
// from knowing the value at request time.
Config tfsdk.Config

// TODO:Actions: Add linked resources when new action schema types are introduced

// ClientCapabilities defines optionally supported protocol features for the
// PlanAction RPC, such as forward-compatible Terraform behavior changes.
ClientCapabilities ModifyPlanClientCapabilities
}

// ModifyPlanResponse represents a response to a
// ModifyPlanRequest. An instance of this response struct is supplied
// as an argument to the action's ModifyPlan function, in which the provider
// should modify the Plan of any linked resources as appropriate.
// as an argument to the action's ModifyPlan function.
type ModifyPlanResponse struct {
// Diagnostics report errors or warnings related to determining the
// planned state of the requested action's linked resources. Returning an empty slice
// indicates a successful plan modification with no warnings or errors
// generated.
// Diagnostics report early errors or warnings related action.
// Returning an empty slice indicates a successful plan modification
// with no warnings or errors generated.
Diagnostics diag.Diagnostics

// TODO:Actions: Add linked resources when new action schema types are introduced

// Deferred indicates that Terraform should defer planning this
// action until a follow-up apply operation.
//
Expand Down
6 changes: 1 addition & 5 deletions action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ type SchemaRequest struct{}
type SchemaResponse struct {

// Schema is the schema of the action.
//
// There is currently only one type of action, which defines 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 schema.SchemaType
Schema schema.Schema

// Diagnostics report errors or warnings related to retrieving the action schema.
// An empty slice indicates success, with no warnings or errors generated.
Expand Down
4 changes: 0 additions & 4 deletions action/schema/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
// Package schema contains all available schema functionality for actions.
// Action schemas define the structure and value types for configuration data.
// Schemas are implemented via the action.Action type Schema method.
//
// There is currently one type of action schema, which defines how a practitioner can trigger an action,
// as well as what effect the action can have on the state.
// - [UnlinkedSchema] actions are actions that cannot cause changes to resource states.
package schema
37 changes: 18 additions & 19 deletions action/schema/unlinked_schema.go → action/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ package schema
import (
"context"

"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

var _ SchemaType = UnlinkedSchema{}
var _ fwschema.Schema = Schema{}

// UnlinkedSchema defines the structure and value types of an unlinked action. An unlinked action
// Schema defines the structure and value types of an action. An action currently
// cannot cause changes to resource state.
type UnlinkedSchema struct {
type Schema struct {
// Attributes is the mapping of underlying attribute names to attribute
// definitions.
//
Expand Down Expand Up @@ -58,78 +59,76 @@ type UnlinkedSchema struct {
DeprecationMessage string
}

func (s UnlinkedSchema) isActionSchemaType() {}

// ApplyTerraform5AttributePathStep applies the given AttributePathStep to the
// schema.
func (s UnlinkedSchema) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (any, error) {
func (s Schema) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (any, error) {
return fwschema.SchemaApplyTerraform5AttributePathStep(s, step)
}

// AttributeAtPath returns the Attribute at the passed path. If the path points
// to an element or attribute of a complex type, rather than to an Attribute,
// it will return an ErrPathInsideAtomicAttribute error.
func (s UnlinkedSchema) AttributeAtPath(ctx context.Context, p path.Path) (fwschema.Attribute, diag.Diagnostics) {
func (s Schema) AttributeAtPath(ctx context.Context, p path.Path) (fwschema.Attribute, diag.Diagnostics) {
return fwschema.SchemaAttributeAtPath(ctx, s, p)
}

// AttributeAtPath returns the Attribute at the passed path. If the path points
// to an element or attribute of a complex type, rather than to an Attribute,
// it will return an ErrPathInsideAtomicAttribute error.
func (s UnlinkedSchema) AttributeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (fwschema.Attribute, error) {
func (s Schema) AttributeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (fwschema.Attribute, error) {
return fwschema.SchemaAttributeAtTerraformPath(ctx, s, p)
}

// GetAttributes returns the Attributes field value.
func (s UnlinkedSchema) GetAttributes() map[string]fwschema.Attribute {
func (s Schema) GetAttributes() map[string]fwschema.Attribute {
return schemaAttributes(s.Attributes)
}

// GetBlocks returns the Blocks field value.
func (s UnlinkedSchema) GetBlocks() map[string]fwschema.Block {
func (s Schema) GetBlocks() map[string]fwschema.Block {
return schemaBlocks(s.Blocks)
}

// GetDeprecationMessage returns the DeprecationMessage field value.
func (s UnlinkedSchema) GetDeprecationMessage() string {
func (s Schema) GetDeprecationMessage() string {
return s.DeprecationMessage
}

// GetDescription returns the Description field value.
func (s UnlinkedSchema) GetDescription() string {
func (s Schema) GetDescription() string {
return s.Description
}

// GetMarkdownDescription returns the MarkdownDescription field value.
func (s UnlinkedSchema) GetMarkdownDescription() string {
func (s Schema) GetMarkdownDescription() string {
return s.MarkdownDescription
}

// GetVersion always returns 0 as action schemas cannot be versioned.
func (s UnlinkedSchema) GetVersion() int64 {
func (s Schema) GetVersion() int64 {
return 0
}

// Type returns the framework type of the schema.
func (s UnlinkedSchema) Type() attr.Type {
func (s Schema) Type() attr.Type {
return fwschema.SchemaType(s)
}

// TypeAtPath returns the framework type at the given schema path.
func (s UnlinkedSchema) TypeAtPath(ctx context.Context, p path.Path) (attr.Type, diag.Diagnostics) {
func (s Schema) TypeAtPath(ctx context.Context, p path.Path) (attr.Type, diag.Diagnostics) {
return fwschema.SchemaTypeAtPath(ctx, s, p)
}

// TypeAtTerraformPath returns the framework type at the given tftypes path.
func (s UnlinkedSchema) TypeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (attr.Type, error) {
func (s Schema) TypeAtTerraformPath(ctx context.Context, p *tftypes.AttributePath) (attr.Type, error) {
return fwschema.SchemaTypeAtTerraformPath(ctx, s, p)
}

// ValidateImplementation contains logic for validating the provider-defined
// implementation of the schema and underlying attributes and blocks to prevent
// unexpected errors or panics. This logic runs during the GetProviderSchema RPC,
// or via provider-defined unit testing, and should never include false positives.
func (s UnlinkedSchema) ValidateImplementation(ctx context.Context) diag.Diagnostics {
func (s Schema) ValidateImplementation(ctx context.Context) diag.Diagnostics {
var diags diag.Diagnostics

for attributeName, attribute := range s.GetAttributes() {
Expand Down
Loading
Loading