-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: Add support for Manual Deferred Actions (#999)
* Implement manual deferred action support for `resource.importResourceState` * Implement manual deferred action support for `resource.readResource` * Implement manual deferred action support for `resource.modifyPlan` * Rename `DeferralReason` and `DeferralResponse` to `DeferredReason` and `DeferredResponse` respectively to match protobuf definition * Update `terraform-plugin-go` dependency to `v0.23.0` * Rename `deferral.go` to `deferred.go` * Implement manual deferred action support for data sources * Update documentation and diagnostic messages * Add copyright headers * Add changelog entries * Apply suggestions from code review Co-authored-by: Austin Valle <[email protected]> * Add comment and changelog notes to indicate experimental nature of deferred actions. * Rename constant to be specific to data sources * Remove TODO comment * Remove unnecessary nil check * Add default values for `ClientCapabilities` request fields * Rename `DeferredResponse` to `Deferred` * Remove error handling for deferral response without deferral capability * Remove variable indirection in tests * Add copyright headers * Apply suggestions from code review Co-authored-by: Brian Flad <[email protected]> * Add unit tests for client capabilities * Move client capabilities defaulting behavior to `fromproto5/6` package * Move `toproto5/6` `Deferred` conversion handling to its own files * Use `ResourceDeferred()` and `DataSourceDeferred()` functions in `toproto6` package --------- Co-authored-by: Austin Valle <[email protected]> Co-authored-by: Brian Flad <[email protected]>
- Loading branch information
1 parent
ec16ec0
commit 24d09fe
Showing
54 changed files
with
1,118 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'resource: Add `Deferred` field to `ReadResponse`, `ModifyPlanResponse`, and `ImportStateResponse` | ||
which indicates a resource deferred action to the Terraform client' | ||
time: 2024-05-08T10:51:05.90518-04:00 | ||
custom: | ||
Issue: "999" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'datasource: Add `Deferred` field to `ReadResponse` which indicates a data source deferred action | ||
to the Terraform client' | ||
time: 2024-05-08T10:51:41.663935-04:00 | ||
custom: | ||
Issue: "999" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'resource: Add `ClientCapabilities` field to `ReadRequest`, `ModifyPlanRequest`, and `ImportStateRequest` | ||
which specifies optionally supported protocol features for the Terraform client' | ||
time: 2024-05-08T11:07:15.955126-04:00 | ||
custom: | ||
Issue: "999" |
This file contains 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,6 @@ | ||
kind: FEATURES | ||
body: 'datasource: Add `ClientCapabilities` field to `ReadRequest` which specifies | ||
optionally supported protocol features for the Terraform client' | ||
time: 2024-05-08T11:10:23.66584-04:00 | ||
custom: | ||
Issue: "999" |
This file contains 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,7 @@ | ||
kind: NOTES | ||
body: This release contains support for deferred actions, which is an experimental | ||
feature only available in prerelease builds of Terraform 1.9 and later. This functionality | ||
is subject to change and is not protected by version compatibility guarantees. | ||
time: 2024-05-10T14:31:36.644869-04:00 | ||
custom: | ||
Issue: "999" |
This file contains 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 datasource | ||
|
||
const ( | ||
// DeferredReasonUnknown is used to indicate an invalid `DeferredReason`. | ||
// Provider developers should not use it. | ||
DeferredReasonUnknown DeferredReason = 0 | ||
|
||
// DeferredReasonDataSourceConfigUnknown is used to indicate that the resource configuration | ||
// is partially unknown and the real values need to be known before the change can be planned. | ||
DeferredReasonDataSourceConfigUnknown 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 "Data Source Config Unknown" | ||
case 2: | ||
return "Provider Config Unknown" | ||
case 3: | ||
return "Absent Prerequisite" | ||
} | ||
return "Unknown" | ||
} |
This file contains 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 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,63 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fromproto5 | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
) | ||
|
||
func ReadDataSourceClientCapabilities(in *tfprotov5.ReadDataSourceClientCapabilities) datasource.ReadClientCapabilities { | ||
if in == nil { | ||
// Client did not indicate any supported capabilities | ||
return datasource.ReadClientCapabilities{ | ||
DeferralAllowed: false, | ||
} | ||
} | ||
|
||
return datasource.ReadClientCapabilities{ | ||
DeferralAllowed: in.DeferralAllowed, | ||
} | ||
} | ||
|
||
func ReadResourceClientCapabilities(in *tfprotov5.ReadResourceClientCapabilities) resource.ReadClientCapabilities { | ||
if in == nil { | ||
// Client did not indicate any supported capabilities | ||
return resource.ReadClientCapabilities{ | ||
DeferralAllowed: false, | ||
} | ||
} | ||
|
||
return resource.ReadClientCapabilities{ | ||
DeferralAllowed: in.DeferralAllowed, | ||
} | ||
} | ||
|
||
func ModifyPlanClientCapabilities(in *tfprotov5.PlanResourceChangeClientCapabilities) resource.ModifyPlanClientCapabilities { | ||
if in == nil { | ||
// Client did not indicate any supported capabilities | ||
return resource.ModifyPlanClientCapabilities{ | ||
DeferralAllowed: false, | ||
} | ||
} | ||
|
||
return resource.ModifyPlanClientCapabilities{ | ||
DeferralAllowed: in.DeferralAllowed, | ||
} | ||
} | ||
|
||
func ImportStateClientCapabilities(in *tfprotov5.ImportResourceStateClientCapabilities) resource.ImportStateClientCapabilities { | ||
if in == nil { | ||
// Client did not indicate any supported capabilities | ||
return resource.ImportStateClientCapabilities{ | ||
DeferralAllowed: false, | ||
} | ||
} | ||
|
||
return resource.ImportStateClientCapabilities{ | ||
DeferralAllowed: in.DeferralAllowed, | ||
} | ||
} |
This file contains 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 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 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 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 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 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.