Skip to content

tfprotov5+tfprotov6: Write-only Attribute Implementation #462

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 24 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2a6cf6e
Upgrade Go to `v1.22`
SBGoods Aug 16, 2024
a1813c4
Add support for ephemeral resources in protocol version 6
SBGoods Aug 16, 2024
8b3457c
Add support for ephemeral resources in protocol version 5
SBGoods Aug 19, 2024
bd78dc5
Add ephemeral resources field to `GetMetadata_Response()`
SBGoods Aug 19, 2024
005c5e6
Update tfplugin5.proto and tfplugin5.proto to support write-only attr…
SBGoods Aug 26, 2024
3c613f8
Implement write-only attributes in `tfprotov5` and `tfprotov6` packages
SBGoods Aug 26, 2024
145d7bc
Remove `State` field from `RenewEphemeralResource` RPC response and r…
SBGoods Aug 27, 2024
76f72b3
Update tfplugin5.proto and tfplugin5.proto to support write-only attr…
SBGoods Aug 26, 2024
05fa3f9
Implement write-only attributes in `tfprotov5` and `tfprotov6` packages
SBGoods Aug 26, 2024
38321c9
Merge remote-tracking branch 'origin/SBGoods/write-only-attributes' i…
SBGoods Aug 27, 2024
0af2658
Update protobuf stubs after rebase
SBGoods Aug 27, 2024
5eafe6a
Increase protocol minor version for write-only attributes
SBGoods Aug 30, 2024
7ea64ad
switch interfaces to be optional
austinvalle Sep 4, 2024
01ad1de
Merge branch 'main' into SBGoods/ephemeral-resources
austinvalle Sep 24, 2024
cd3b665
removed `config` from renew request
austinvalle Sep 24, 2024
daaf44b
Merge branch 'SBGoods/ephemeral-resources' into SBGoods/write-only-at…
SBGoods Sep 26, 2024
adf4d55
Update protocol bindings
SBGoods Sep 26, 2024
9019c19
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Nov 25, 2024
89be6e8
Merge branch 'main' into SBGoods/write-only-attributes
austinvalle Dec 17, 2024
dcf8f64
remove ApplyResourceChange client capabilities + add server logging f…
austinvalle Dec 17, 2024
2f466c8
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Jan 17, 2025
200b886
Update `protoc` to `v29.3` in CI
SBGoods Jan 17, 2025
0cf16f3
Add changelog entry
SBGoods Jan 21, 2025
ba35cea
Apply suggestions from code review
SBGoods Jan 21, 2025
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: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250121-163456.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'tfprotov5+tfprotov6: Upgraded protocols and added types to support write-only attributes'
time: 2025-01-21T16:34:56.142885-05:00
custom:
Issue: "462"
2 changes: 1 addition & 1 deletion .github/workflows/ci-protobuf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# pinned here to prevent unexpected differences. Follow the
# https://github.com/protocolbuffers/protobuf repository for protoc
# release updates.
version: '27.3'
version: '29.3'
- run: go mod download
- run: make tools
- run: make protoc
Expand Down
3 changes: 3 additions & 0 deletions internal/logging/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ const (

// Whether the DeferralAllowed client capability is enabled
KeyClientCapabilityDeferralAllowed = "tf_client_capability_deferral_allowed"

// Whether the WriteOnlyAttributesAllowed client capability is enabled
KeyClientCapabilityWriteOnlyAttributesAllowed = "tf_client_capability_write_only_attributes_allowed"
)
9 changes: 9 additions & 0 deletions tfprotov5/client_capabilities.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specific feedback to this work, more of an observation, but I see that Terraform core is sending these client capabilities in every RPC request regardless of whether we use them. So in theory we could add, say, the WriteOnlyAttributesAllowed capability to PlanResourceChange with an SDK only change.

Not saying we should, but thought it was interesting.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

package tfprotov5

// ValidateResourceTypeConfigClientCapabilities allows Terraform to publish information
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My monthly reminder that this RPC is named different in protocol v5 😆

// regarding optionally supported protocol features for the ValidateResourceTypeConfig RPC,
// such as forward-compatible Terraform behavior changes.
type ValidateResourceTypeConfigClientCapabilities struct {
// WriteOnlyAttributesAllowed signals that the client is able to
// handle write_only attributes for managed resources.
WriteOnlyAttributesAllowed bool
}

// ConfigureProviderClientCapabilities allows Terraform to publish information
// regarding optionally supported protocol features for the ConfigureProvider RPC,
// such as forward-compatible Terraform behavior changes.
Expand Down
12 changes: 12 additions & 0 deletions tfprotov5/internal/fromproto/client_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
)

func ValidateResourceTypeConfigClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ValidateResourceTypeConfigClientCapabilities {
if in == nil {
return nil
}

resp := &tfprotov5.ValidateResourceTypeConfigClientCapabilities{
WriteOnlyAttributesAllowed: in.WriteOnlyAttributesAllowed,
}

return resp
}

func ConfigureProviderClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ConfigureProviderClientCapabilities {
if in == nil {
return nil
Expand Down
41 changes: 41 additions & 0 deletions tfprotov5/internal/fromproto/client_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,52 @@ import (
"testing"

"github.com/google/go-cmp/cmp"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/fromproto"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
)

func TestValidateResourceTypeConfigClientCapabilities(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
in *tfplugin5.ClientCapabilities
expected *tfprotov5.ValidateResourceTypeConfigClientCapabilities
}{
"nil": {
in: nil,
expected: nil,
},
"zero": {
in: &tfplugin5.ClientCapabilities{},
expected: &tfprotov5.ValidateResourceTypeConfigClientCapabilities{},
},
"WriteOnlyAttributesAllowed": {
in: &tfplugin5.ClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
expected: &tfprotov5.ValidateResourceTypeConfigClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := fromproto.ValidateResourceTypeConfigClientCapabilities(testCase.in)

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestConfigureProviderClientCapabilities(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 3 additions & 2 deletions tfprotov5/internal/fromproto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ func ValidateResourceTypeConfigRequest(in *tfplugin5.ValidateResourceTypeConfig_
}

resp := &tfprotov5.ValidateResourceTypeConfigRequest{
Config: DynamicValue(in.Config),
TypeName: in.TypeName,
ClientCapabilities: ValidateResourceTypeConfigClientCapabilities(in.ClientCapabilities),
Config: DynamicValue(in.Config),
TypeName: in.TypeName,
}

return resp
Expand Down
13 changes: 13 additions & 0 deletions tfprotov5/internal/fromproto/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/fromproto"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
Expand Down Expand Up @@ -471,6 +472,18 @@ func TestValidateResourceTypeConfigRequest(t *testing.T) {
in: &tfplugin5.ValidateResourceTypeConfig_Request{},
expected: &tfprotov5.ValidateResourceTypeConfigRequest{},
},
"ClientCapabilities": {
in: &tfplugin5.ValidateResourceTypeConfig_Request{
ClientCapabilities: &tfplugin5.ClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
},
expected: &tfprotov5.ValidateResourceTypeConfigRequest{
ClientCapabilities: &tfprotov5.ValidateResourceTypeConfigClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
},
},
"Config": {
in: &tfplugin5.ValidateResourceTypeConfig_Request{
Config: testTfplugin5DynamicValue(),
Expand Down
14 changes: 14 additions & 0 deletions tfprotov5/internal/tf5serverlogging/client_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import (
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
)

// ValidateResourceTypeConfigClientCapabilities generates a TRACE "Announced client capabilities" log.
func ValidateResourceTypeConfigClientCapabilities(ctx context.Context, capabilities *tfprotov5.ValidateResourceTypeConfigClientCapabilities) {
if capabilities == nil {
logging.ProtocolTrace(ctx, "No announced client capabilities", map[string]interface{}{})
return
}

responseFields := map[string]interface{}{
logging.KeyClientCapabilityWriteOnlyAttributesAllowed: capabilities.WriteOnlyAttributesAllowed,
}

logging.ProtocolTrace(ctx, "Announced client capabilities", responseFields)
}

// ConfigureProviderClientCapabilities generates a TRACE "Announced client capabilities" log.
func ConfigureProviderClientCapabilities(ctx context.Context, capabilities *tfprotov5.ConfigureProviderClientCapabilities) {
if capabilities == nil {
Expand Down
74 changes: 72 additions & 2 deletions tfprotov5/internal/tf5serverlogging/client_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,83 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-log/tfsdklog"
"github.com/hashicorp/terraform-plugin-log/tfsdklogtest"

"github.com/hashicorp/terraform-plugin-go/internal/logging"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tf5serverlogging"
"github.com/hashicorp/terraform-plugin-log/tfsdklog"
"github.com/hashicorp/terraform-plugin-log/tfsdklogtest"
)

func TestValidateResourceTypeConfigClientCapabilities(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
capabilities *tfprotov5.ValidateResourceTypeConfigClientCapabilities
expected []map[string]interface{}
}{
"nil": {
capabilities: nil,
expected: []map[string]interface{}{
{
"@level": "trace",
"@message": "No announced client capabilities",
"@module": "sdk.proto",
},
},
},
"empty": {
capabilities: &tfprotov5.ValidateResourceTypeConfigClientCapabilities{},
expected: []map[string]interface{}{
{
"@level": "trace",
"@message": "Announced client capabilities",
"@module": "sdk.proto",
"tf_client_capability_write_only_attributes_allowed": false,
},
},
},
"write_only_attributes_allowed": {
capabilities: &tfprotov5.ValidateResourceTypeConfigClientCapabilities{
WriteOnlyAttributesAllowed: true,
},
expected: []map[string]interface{}{
{
"@level": "trace",
"@message": "Announced client capabilities",
"@module": "sdk.proto",
"tf_client_capability_write_only_attributes_allowed": true,
},
},
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

var output bytes.Buffer

ctx := tfsdklogtest.RootLogger(context.Background(), &output)
ctx = logging.ProtoSubsystemContext(ctx, tfsdklog.Options{})

tf5serverlogging.ValidateResourceTypeConfigClientCapabilities(ctx, testCase.capabilities)

entries, err := tfsdklogtest.MultilineJSONDecode(&output)

if err != nil {
t.Fatalf("unable to read multiple line JSON: %s", err)
}

if diff := cmp.Diff(entries, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestConfigureProviderClientCapabilities(t *testing.T) {
t.Parallel()

Expand Down
Loading
Loading