-
Notifications
You must be signed in to change notification settings - Fork 99
action: Implement planning and invoking of actions #1185
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
20 commits
Select commit
Hold shift + click to select a range
9ec6758
go mod
austinvalle 5eeac4c
generate RPC methods
austinvalle bf10880
protov5 and fwserver impl
austinvalle 3c21a45
protov6 copy
austinvalle 61eadc9
add initial schema attributes and unlinked schema
austinvalle 0e5df9c
implement unlinked schemas, some attributes, and the rpcs
austinvalle 32b2083
the rest of the tests
austinvalle dcd6748
Merge branch 'main' into av/action-schema
austinvalle 3a1048c
fix double import
austinvalle 7e5fd9f
external interfaces for plan / configure
austinvalle 95e7673
plan action impl and fwserver tests
austinvalle 5d5960a
proto server tests
austinvalle 7ec37c2
from/to plan tests
austinvalle e43f576
from invoke
austinvalle 2f08b28
add invoke impl with just completed event
austinvalle 261ef7d
fix map access in unit tests
austinvalle 8fdf71d
Merge branch 'main' into av/unlinked-action-impl
austinvalle 47f9631
implementation of sending progress events
austinvalle 119f4c5
mention progress events
austinvalle 98f7232
comments
austinvalle 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package action | ||
|
|
||
| import "github.com/hashicorp/terraform-plugin-framework/diag" | ||
|
|
||
| // ConfigureRequest represents a request for the provider to configure an | ||
| // action, i.e., set provider-level data or clients. An instance of this | ||
| // request struct is supplied as an argument to the Action type Configure | ||
| // method. | ||
| type ConfigureRequest struct { | ||
| // ProviderData is the data set in the | ||
| // [provider.ConfigureResponse.ActionData] field. This data is | ||
| // provider-specifc and therefore can contain any necessary remote system | ||
| // clients, custom provider data, or anything else pertinent to the | ||
| // functionality of the Action. | ||
| // | ||
| // This data is only set after the ConfigureProvider RPC has been called | ||
| // by Terraform. | ||
| ProviderData any | ||
| } | ||
|
|
||
| // ConfigureResponse represents a response to a ConfigureRequest. An | ||
| // instance of this response struct is supplied as an argument to the | ||
| // Action type Configure method. | ||
| type ConfigureResponse struct { | ||
| // Diagnostics report errors or warnings related to configuring of the | ||
| // Datasource. An empty slice indicates a successful operation with no | ||
| // warnings or errors generated. | ||
| Diagnostics diag.Diagnostics | ||
| } |
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,50 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package action | ||
|
|
||
| const ( | ||
| // DeferredReasonUnknown is used to indicate an invalid `DeferredReason`. | ||
| // Provider developers should not use it. | ||
| DeferredReasonUnknown DeferredReason = 0 | ||
|
|
||
| // DeferredReasonActionConfigUnknown is used to indicate that the action configuration | ||
| // is partially unknown and the real values need to be known before the change can be planned. | ||
| DeferredReasonActionConfigUnknown DeferredReason = 1 | ||
|
|
||
| // DeferredReasonProviderConfigUnknown is used to indicate that the provider configuration | ||
| // is partially unknown and the real values need to be known before the change can be planned. | ||
| DeferredReasonProviderConfigUnknown DeferredReason = 2 | ||
|
|
||
| // DeferredReasonAbsentPrereq is used to indicate that a hard dependency has not been satisfied. | ||
| DeferredReasonAbsentPrereq DeferredReason = 3 | ||
| ) | ||
|
|
||
| // Deferred is used to indicate to Terraform that a change needs to be deferred for a reason. | ||
| // | ||
| // NOTE: This functionality is related to deferred action support, which is currently experimental and is subject | ||
| // to change or break without warning. It is not protected by version compatibility guarantees. | ||
| type Deferred struct { | ||
| // Reason is the reason for deferring the change. | ||
| Reason DeferredReason | ||
| } | ||
|
|
||
| // DeferredReason represents different reasons for deferring a change. | ||
| // | ||
| // NOTE: This functionality is related to deferred action support, which is currently experimental and is subject | ||
| // to change or break without warning. It is not protected by version compatibility guarantees. | ||
| type DeferredReason int32 | ||
|
|
||
| func (d DeferredReason) String() string { | ||
| switch d { | ||
| case 0: | ||
| return "Unknown" | ||
| case 1: | ||
| return "Action Config Unknown" | ||
| case 2: | ||
| return "Provider Config Unknown" | ||
| case 3: | ||
| return "Absent Prerequisite" | ||
| } | ||
| return "Unknown" | ||
| } |
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,45 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package action | ||
|
|
||
| import ( | ||
| "github.com/hashicorp/terraform-plugin-framework/diag" | ||
| "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. | ||
| type InvokeRequest struct { | ||
| // Config is the configuration the user supplied for the action. | ||
| Config tfsdk.Config | ||
|
|
||
| // TODO:Actions: Add linked resources once lifecycle/linked actions are implemented | ||
| } | ||
|
|
||
| // 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 | ||
| // 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 provided by the framework and can be called multiple times while action logic is running. | ||
| // | ||
| // TODO:Actions: More documentation about when you should use this / when you shouldn't | ||
| SendProgress func(event InvokeProgressEvent) | ||
|
|
||
| // TODO:Actions: Add linked resources once lifecycle/linked actions are implemented | ||
| } | ||
|
|
||
| // InvokeProgressEvent is the event returned to Terraform while an action is being invoked. | ||
| type InvokeProgressEvent struct { | ||
| // Message is the string that will be presented to the practitioner either via the console | ||
| // or an external system like HCP Terraform. | ||
| Message string | ||
| } | ||
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,62 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package action | ||
|
|
||
| import ( | ||
| "github.com/hashicorp/terraform-plugin-framework/diag" | ||
| "github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
| ) | ||
|
|
||
| // ModifyPlanClientCapabilities allows Terraform to publish information | ||
| // regarding optionally supported protocol features for the PlanAction RPC, | ||
| // such as forward-compatible Terraform behavior changes. | ||
| type ModifyPlanClientCapabilities struct { | ||
| // DeferralAllowed indicates whether the Terraform client initiating | ||
| // the request allows a deferral response. | ||
| // | ||
| // NOTE: This functionality is related to deferred action support, which is currently experimental and is subject | ||
| // to change or break without warning. It is not protected by version compatibility guarantees. | ||
| DeferralAllowed bool | ||
| } | ||
|
|
||
| // ModifyPlanRequest represents a request for the provider to modify the | ||
| // planned new state that Terraform has generated for any linked resources. | ||
| type ModifyPlanRequest struct { | ||
| // Config is the configuration the user supplied for the action. | ||
| // | ||
| // This configuration may contain unknown values if a user uses | ||
| // interpolation or other functionality that would prevent Terraform | ||
| // from knowing the value at request time. | ||
| Config tfsdk.Config | ||
|
|
||
| // TODO:Actions: Add linked resources once lifecycle/linked actions are implemented | ||
|
|
||
| // 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. | ||
| 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 diag.Diagnostics | ||
|
|
||
| // TODO:Actions: Add linked resources once lifecycle/linked actions are implemented | ||
|
|
||
| // Deferred indicates that Terraform should defer planning this | ||
| // action until a follow-up apply operation. | ||
| // | ||
| // This field can only be set if | ||
| // `(action.ModifyPlanRequest).ClientCapabilities.DeferralAllowed` is true. | ||
| // | ||
| // NOTE: This functionality is related to deferred action support, which is currently experimental and is subject | ||
| // to change or break without warning. It is not protected by version compatibility guarantees. | ||
| Deferred *Deferred | ||
| } |
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
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
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.
It didn't feel beneficial to expose much more than this function to provider developers. Open to discussion on any other ideas for improving this UX
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.
I think this design makes sense, we only need to expose progress events for now and if we want to expose other types, we can incrementally add callback functions for those types later. I doubt that we will need to expose every event type.