Skip to content

Commit b34d0f0

Browse files
Merge branch 'main' into zhiwei/collections-length-func
2 parents 8de6b0e + d4a5416 commit b34d0f0

File tree

89 files changed

+13071
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+13071
-130
lines changed

action/action.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,40 @@ type Action interface {
1212
// Metadata should return the full name of the action, such as examplecloud_do_thing.
1313
Metadata(context.Context, MetadataRequest, *MetadataResponse)
1414

15-
// TODO:Actions: Eventual landing place for all required methods to implement for an action
15+
// Invoke is called to run the logic of the action and update linked resources if applicable.
16+
// Config, linked resource planned state, and linked resource prior state values should
17+
// be read from the InvokeRequest and new linked resource state values set on the InvokeResponse.
18+
//
19+
// The [InvokeResponse.SendProgress] function can be called in the Invoke method to immediately
20+
// report progress events related to the invocation of the action to Terraform.
21+
Invoke(context.Context, InvokeRequest, *InvokeResponse)
22+
}
23+
24+
// ActionWithConfigure is an interface type that extends Action to
25+
// include a method which the framework will automatically call so provider
26+
// developers have the opportunity to setup any necessary provider-level data
27+
// or clients in the Action type.
28+
type ActionWithConfigure interface {
29+
Action
30+
31+
// Configure enables provider-level data or clients to be set in the
32+
// provider-defined Action type.
33+
Configure(context.Context, ConfigureRequest, *ConfigureResponse)
34+
}
35+
36+
// ActionWithModifyPlan represents an action with a ModifyPlan function.
37+
type ActionWithModifyPlan interface {
38+
Action
39+
40+
// ModifyPlan is called when the provider has an opportunity to modify
41+
// the plan for an action: once during the plan phase, and once
42+
// during the apply phase with any unknown values from configuration
43+
// filled in with their final values.
44+
//
45+
// Actions do not have computed attributes that can be modified during the plan,
46+
// but linked and lifecycle actions can modify the plan of linked resources.
47+
//
48+
// All action schema types can use the plan as an opportunity to raise early
49+
// diagnostics to practitioners, such as validation errors.
50+
ModifyPlan(context.Context, ModifyPlanRequest, *ModifyPlanResponse)
1651
}

action/configure.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package action
5+
6+
import "github.com/hashicorp/terraform-plugin-framework/diag"
7+
8+
// ConfigureRequest represents a request for the provider to configure an
9+
// action, i.e., set provider-level data or clients. An instance of this
10+
// request struct is supplied as an argument to the Action type Configure
11+
// method.
12+
type ConfigureRequest struct {
13+
// ProviderData is the data set in the
14+
// [provider.ConfigureResponse.ActionData] field. This data is
15+
// provider-specifc and therefore can contain any necessary remote system
16+
// clients, custom provider data, or anything else pertinent to the
17+
// functionality of the Action.
18+
//
19+
// This data is only set after the ConfigureProvider RPC has been called
20+
// by Terraform.
21+
ProviderData any
22+
}
23+
24+
// ConfigureResponse represents a response to a ConfigureRequest. An
25+
// instance of this response struct is supplied as an argument to the
26+
// Action type Configure method.
27+
type ConfigureResponse struct {
28+
// Diagnostics report errors or warnings related to configuring of the
29+
// Datasource. An empty slice indicates a successful operation with no
30+
// warnings or errors generated.
31+
Diagnostics diag.Diagnostics
32+
}

action/deferred.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package action
5+
6+
const (
7+
// DeferredReasonUnknown is used to indicate an invalid `DeferredReason`.
8+
// Provider developers should not use it.
9+
DeferredReasonUnknown DeferredReason = 0
10+
11+
// DeferredReasonActionConfigUnknown is used to indicate that the action configuration
12+
// is partially unknown and the real values need to be known before the change can be planned.
13+
DeferredReasonActionConfigUnknown DeferredReason = 1
14+
15+
// DeferredReasonProviderConfigUnknown is used to indicate that the provider configuration
16+
// is partially unknown and the real values need to be known before the change can be planned.
17+
DeferredReasonProviderConfigUnknown DeferredReason = 2
18+
19+
// DeferredReasonAbsentPrereq is used to indicate that a hard dependency has not been satisfied.
20+
DeferredReasonAbsentPrereq DeferredReason = 3
21+
)
22+
23+
// Deferred is used to indicate to Terraform that a change needs to be deferred for a reason.
24+
//
25+
// NOTE: This functionality is related to deferred action support, which is currently experimental and is subject
26+
// to change or break without warning. It is not protected by version compatibility guarantees.
27+
type Deferred struct {
28+
// Reason is the reason for deferring the change.
29+
Reason DeferredReason
30+
}
31+
32+
// DeferredReason represents different reasons for deferring a change.
33+
//
34+
// NOTE: This functionality is related to deferred action support, which is currently experimental and is subject
35+
// to change or break without warning. It is not protected by version compatibility guarantees.
36+
type DeferredReason int32
37+
38+
func (d DeferredReason) String() string {
39+
switch d {
40+
case 0:
41+
return "Unknown"
42+
case 1:
43+
return "Action Config Unknown"
44+
case 2:
45+
return "Provider Config Unknown"
46+
case 3:
47+
return "Absent Prerequisite"
48+
}
49+
return "Unknown"
50+
}

action/invoke.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package action
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework/diag"
8+
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
9+
)
10+
11+
// InvokeRequest represents a request for the provider to invoke the action and update
12+
// the requested action's linked resources.
13+
type InvokeRequest struct {
14+
// Config is the configuration the user supplied for the action.
15+
Config tfsdk.Config
16+
17+
// TODO:Actions: Add linked resources once lifecycle/linked actions are implemented
18+
}
19+
20+
// InvokeResponse represents a response to an InvokeRequest. An
21+
// instance of this response struct is supplied as
22+
// an argument to the action's Invoke function, in which the provider
23+
// should set values on the InvokeResponse as appropriate.
24+
type InvokeResponse struct {
25+
// Diagnostics report errors or warnings related to invoking the action or updating
26+
// the state of the requested action's linked resources. Returning an empty slice
27+
// indicates a successful invocation with no warnings or errors
28+
// generated.
29+
Diagnostics diag.Diagnostics
30+
31+
// SendProgress will immediately send a progress update to Terraform core during action invocation.
32+
// This function is provided by the framework and can be called multiple times while action logic is running.
33+
//
34+
// TODO:Actions: More documentation about when you should use this / when you shouldn't
35+
SendProgress func(event InvokeProgressEvent)
36+
37+
// TODO:Actions: Add linked resources once lifecycle/linked actions are implemented
38+
}
39+
40+
// InvokeProgressEvent is the event returned to Terraform while an action is being invoked.
41+
type InvokeProgressEvent struct {
42+
// Message is the string that will be presented to the practitioner either via the console
43+
// or an external system like HCP Terraform.
44+
Message string
45+
}

action/modify_plan.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package action
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework/diag"
8+
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
9+
)
10+
11+
// ModifyPlanClientCapabilities allows Terraform to publish information
12+
// regarding optionally supported protocol features for the PlanAction RPC,
13+
// such as forward-compatible Terraform behavior changes.
14+
type ModifyPlanClientCapabilities struct {
15+
// DeferralAllowed indicates whether the Terraform client initiating
16+
// the request allows a deferral response.
17+
//
18+
// NOTE: This functionality is related to deferred action support, which is currently experimental and is subject
19+
// to change or break without warning. It is not protected by version compatibility guarantees.
20+
DeferralAllowed bool
21+
}
22+
23+
// ModifyPlanRequest represents a request for the provider to modify the
24+
// planned new state that Terraform has generated for any linked resources.
25+
type ModifyPlanRequest struct {
26+
// Config is the configuration the user supplied for the action.
27+
//
28+
// This configuration may contain unknown values if a user uses
29+
// interpolation or other functionality that would prevent Terraform
30+
// from knowing the value at request time.
31+
Config tfsdk.Config
32+
33+
// TODO:Actions: Add linked resources once lifecycle/linked actions are implemented
34+
35+
// ClientCapabilities defines optionally supported protocol features for the
36+
// PlanAction RPC, such as forward-compatible Terraform behavior changes.
37+
ClientCapabilities ModifyPlanClientCapabilities
38+
}
39+
40+
// ModifyPlanResponse represents a response to a
41+
// ModifyPlanRequest. An instance of this response struct is supplied
42+
// as an argument to the action's ModifyPlan function, in which the provider
43+
// should modify the Plan of any linked resources as appropriate.
44+
type ModifyPlanResponse struct {
45+
// Diagnostics report errors or warnings related to determining the
46+
// planned state of the requested action's linked resources. Returning an empty slice
47+
// indicates a successful plan modification with no warnings or errors
48+
// generated.
49+
Diagnostics diag.Diagnostics
50+
51+
// TODO:Actions: Add linked resources once lifecycle/linked actions are implemented
52+
53+
// Deferred indicates that Terraform should defer planning this
54+
// action until a follow-up apply operation.
55+
//
56+
// This field can only be set if
57+
// `(action.ModifyPlanRequest).ClientCapabilities.DeferralAllowed` is true.
58+
//
59+
// NOTE: This functionality is related to deferred action support, which is currently experimental and is subject
60+
// to change or break without warning. It is not protected by version compatibility guarantees.
61+
Deferred *Deferred
62+
}

action/schema/attribute.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
88
)
99

10-
// TODO:Actions: Add all of the attribute and nested attribute types listed below
11-
//
1210
// Attribute define a value field inside an action type schema. Implementations in this
1311
// package include:
1412
// - BoolAttribute

action/schema/block.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
88
)
99

10-
// TODO:Actions: Add all of the block and nested block types listed below
11-
//
1210
// Block defines a structural field inside an action type schema. Implementations in this
1311
// package include:
1412
// - ListNestedBlock

action/schema/bool_attribute.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type BoolAttribute struct {
3636
CustomType basetypes.BoolTypable
3737

3838
// Required indicates whether the practitioner must enter a value for
39-
// this attribute or not. Required and Optional cannot both be true,
40-
// and Required and Computed cannot both be true.
39+
// this attribute or not. Required and Optional cannot both be true.
4140
Required bool
4241

4342
// Optional indicates whether the practitioner can choose to enter a value

action/schema/doc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// Package schema contains all available schema functionality for actions.
5+
// Action schemas define the structure and value types for configuration data.
6+
// Schemas are implemented via the action.Action type Schema method.
7+
//
8+
// There are three different types of action schemas, which define how a practitioner can trigger an action,
9+
// as well as what effect the action can have on the state.
10+
// - [UnlinkedSchema] actions are actions that cannot cause changes to resource states.
11+
// - [LifecycleSchema] actions are actions that can cause changes to exactly one resource state.
12+
// - [LinkedSchema] actions are actions that can cause changes to one or more resource states.
13+
package schema

0 commit comments

Comments
 (0)