Skip to content

Commit 8e4acd3

Browse files
austinvalledependabot[bot]jbardinhc-github-team-tf-provider-devex
authored
tfprotov5+tfprotov6: Add deferred action support to related RPCs (#403)
* generate protocol bindings * add protocol bindings to external interface * build(deps): Bump google.golang.org/grpc from 1.63.0 to 1.63.2 (#394) Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.63.0 to 1.63.2. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](grpc/grpc-go@v1.63.0...v1.63.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * workflows: Remove wildcard suffix from Terraform workflow call (#395) * don't marshal integer values as msgpack floats (#396) * don't marshal integer values as msgpack floats Round-tripping a large integer through a float64, even if the binary representation is exact, causes us to end up with a rounded string representation after decoding, because the decoded number has 52-bit precision instead of the 512 we use when dealing with string representations of large integers. * update CHANGELOG.md * update to changie log --------- Co-authored-by: Austin Valle <[email protected]> * Update changelog * breaking: update protocol bindings for new client capabilities struct + add configure provider bindings * add Go pkg docs * add copywrite headers * add changelog * split client capabilities per RPC * added logging for req/resp deferred actions * add test for ensuring global variable is updated * add diagnostic for invalid deferred * move helper diag into function * add a separate log for nil client capabilities --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: James Bardin <[email protected]> Co-authored-by: hc-github-team-tf-provider-devex <[email protected]>
1 parent 5cc939c commit 8e4acd3

Some content is hidden

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

58 files changed

+5245
-1930
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: FEATURES
2+
body: 'tfprotov5+tfprotov6: Upgraded protocols and added types to support deferred
3+
actions'
4+
time: 2024-05-01T17:40:28.845566-04:00
5+
custom:
6+
Issue: "403"

internal/logging/keys.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ const (
6363
// The protocol version being used, as a string, such as "6"
6464
KeyProtocolVersion = "tf_proto_version"
6565

66+
// The Deferred reason for an RPC response
67+
KeyDeferredReason = "tf_deferred_reason"
68+
6669
// Whether the GetProviderSchemaOptional server capability is enabled
6770
KeyServerCapabilityGetProviderSchemaOptional = "tf_server_capability_get_provider_schema_optional"
6871

6972
// Whether the PlanDestroy server capability is enabled
7073
KeyServerCapabilityPlanDestroy = "tf_server_capability_plan_destroy"
74+
75+
// Whether the DeferralAllowed client capability is enabled
76+
KeyClientCapabilityDeferralAllowed = "tf_client_capability_deferral_allowed"
7177
)

tfprotov5/client_capabilities.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package tfprotov5
5+
6+
// ConfigureProviderClientCapabilities allows Terraform to publish information
7+
// regarding optionally supported protocol features for the ConfigureProvider RPC,
8+
// such as forward-compatible Terraform behavior changes.
9+
type ConfigureProviderClientCapabilities struct {
10+
// DeferralAllowed signals that the request from Terraform is able to
11+
// handle deferred responses from the provider.
12+
DeferralAllowed bool
13+
}
14+
15+
// ReadDataSourceClientCapabilities allows Terraform to publish information
16+
// regarding optionally supported protocol features for the ReadDataSource RPC,
17+
// such as forward-compatible Terraform behavior changes.
18+
type ReadDataSourceClientCapabilities struct {
19+
// DeferralAllowed signals that the request from Terraform is able to
20+
// handle deferred responses from the provider.
21+
DeferralAllowed bool
22+
}
23+
24+
// ReadResourceClientCapabilities allows Terraform to publish information
25+
// regarding optionally supported protocol features for the ReadResource RPC,
26+
// such as forward-compatible Terraform behavior changes.
27+
type ReadResourceClientCapabilities struct {
28+
// DeferralAllowed signals that the request from Terraform is able to
29+
// handle deferred responses from the provider.
30+
DeferralAllowed bool
31+
}
32+
33+
// PlanResourceChangeClientCapabilities allows Terraform to publish information
34+
// regarding optionally supported protocol features for the PlanResourceChange RPC,
35+
// such as forward-compatible Terraform behavior changes.
36+
type PlanResourceChangeClientCapabilities struct {
37+
// DeferralAllowed signals that the request from Terraform is able to
38+
// handle deferred responses from the provider.
39+
DeferralAllowed bool
40+
}
41+
42+
// ImportResourceStateClientCapabilities allows Terraform to publish information
43+
// regarding optionally supported protocol features for the ImportResourceState RPC,
44+
// such as forward-compatible Terraform behavior changes.
45+
type ImportResourceStateClientCapabilities struct {
46+
// DeferralAllowed signals that the request from Terraform is able to
47+
// handle deferred responses from the provider.
48+
DeferralAllowed bool
49+
}

tfprotov5/data_source.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ type ReadDataSourceRequest struct {
8787
//
8888
// This configuration will have known values for all fields.
8989
ProviderMeta *DynamicValue
90+
91+
// ClientCapabilities defines optionally supported protocol features for the
92+
// ReadDataSource RPC, such as forward-compatible Terraform behavior changes.
93+
ClientCapabilities *ReadDataSourceClientCapabilities
9094
}
9195

9296
// ReadDataSourceResponse is the response from the provider about the current
@@ -105,4 +109,8 @@ type ReadDataSourceResponse struct {
105109
// indicates a successful validation with no warnings or errors
106110
// generated.
107111
Diagnostics []*Diagnostic
112+
113+
// Deferred is used to indicate to Terraform that the ReadDataSource operation
114+
// needs to be deferred for a reason.
115+
Deferred *Deferred
108116
}

tfprotov5/deferred.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package tfprotov5
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+
// DeferredReasonResourceConfigUnknown is used to indicate that the resource configuration
12+
// is partially unknown and the real values need to be known before the change can be planned.
13+
DeferredReasonResourceConfigUnknown 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+
type Deferred struct {
25+
// Reason is the reason for deferring the change.
26+
Reason DeferredReason
27+
}
28+
29+
// DeferredReason represents different reasons for deferring a change.
30+
type DeferredReason int32
31+
32+
func (d DeferredReason) String() string {
33+
switch d {
34+
case 0:
35+
return "UNKNOWN"
36+
case 1:
37+
return "RESOURCE_CONFIG_UNKNOWN"
38+
case 2:
39+
return "PROVIDER_CONFIG_UNKNOWN"
40+
case 3:
41+
return "ABSENT_PREREQ"
42+
}
43+
return "UNKNOWN"
44+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package fromproto
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
8+
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
9+
)
10+
11+
func ConfigureProviderClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ConfigureProviderClientCapabilities {
12+
if in == nil {
13+
return nil
14+
}
15+
16+
resp := &tfprotov5.ConfigureProviderClientCapabilities{
17+
DeferralAllowed: in.DeferralAllowed,
18+
}
19+
20+
return resp
21+
}
22+
23+
func ReadDataSourceClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ReadDataSourceClientCapabilities {
24+
if in == nil {
25+
return nil
26+
}
27+
28+
resp := &tfprotov5.ReadDataSourceClientCapabilities{
29+
DeferralAllowed: in.DeferralAllowed,
30+
}
31+
32+
return resp
33+
}
34+
35+
func ReadResourceClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ReadResourceClientCapabilities {
36+
if in == nil {
37+
return nil
38+
}
39+
40+
resp := &tfprotov5.ReadResourceClientCapabilities{
41+
DeferralAllowed: in.DeferralAllowed,
42+
}
43+
44+
return resp
45+
}
46+
47+
func PlanResourceChangeClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.PlanResourceChangeClientCapabilities {
48+
if in == nil {
49+
return nil
50+
}
51+
52+
resp := &tfprotov5.PlanResourceChangeClientCapabilities{
53+
DeferralAllowed: in.DeferralAllowed,
54+
}
55+
56+
return resp
57+
}
58+
59+
func ImportResourceStateClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ImportResourceStateClientCapabilities {
60+
if in == nil {
61+
return nil
62+
}
63+
64+
resp := &tfprotov5.ImportResourceStateClientCapabilities{
65+
DeferralAllowed: in.DeferralAllowed,
66+
}
67+
68+
return resp
69+
}

0 commit comments

Comments
 (0)