Skip to content

Initial Setup for ValidateListResourceConfig in List RPCs #514

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

rainkwan
Copy link
Contributor

@rainkwan rainkwan commented May 20, 2025

Related Issue

Fixes #

Description

Includes support for RPCs ValidateListResourceConfig outlined by TF in https://github.com/hashicorp/terraform/blob/main/docs/plugin-protocol/tfplugin5.proto and https://github.com/hashicorp/terraform/blob/main/docs/plugin-protocol/tfplugin6.proto

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

No

@rainkwan rainkwan marked this pull request as ready for review May 20, 2025 13:48
@rainkwan rainkwan requested a review from a team as a code owner May 20, 2025 13:48
@rainkwan rainkwan marked this pull request as draft May 20, 2025 13:49
@rainkwan rainkwan changed the title rk/list-rpcs Initial Setup for List RPCs May 20, 2025
@bbasata bbasata added this to the v0.28.0 milestone May 20, 2025
@austinvalle austinvalle modified the milestones: v0.28.0, v0.29.0 May 21, 2025
@bbasata bbasata mentioned this pull request May 22, 2025
1 task
@rainkwan rainkwan marked this pull request as ready for review May 29, 2025 15:08
@rainkwan rainkwan changed the title Initial Setup for List RPCs Initial Setup for ValidateListResourceConfig in List RPCs May 29, 2025
Copy link
Contributor

@bbasata bbasata left a comment

Choose a reason for hiding this comment

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

Looks good to me :shipit:

I added line comments that are fine to address in a separate follow-up PR.

@@ -348,6 +359,7 @@ func TestGetProviderSchema_Response(t *testing.T) {
DataSourceSchemas: map[string]*tfplugin5.Schema{},
Diagnostics: []*tfplugin5.Diagnostic{},
EphemeralResourceSchemas: map[string]*tfplugin5.Schema{},
ListResourceSchemas: map[string]*tfplugin5.Schema{},
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 I'm also finding myself repeating the setup of empty maps in table-driven tests. An optional follow-up: how do we feel about using cmptopts.EquateEmpty to remove the repetitive setup of empty maps? I have never used it, but it seems useful here.

"context"
)

// ListResourceMetadata describes metadata for an list resource in the GetMetadata
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ListResourceMetadata describes metadata for an list resource in the GetMetadata
// ListResourceMetadata describes metadata for a list resource in the GetMetadata

& find-replace similar usages :)

// list resource configuration is valid. It is guaranteed to have types
// conforming to your schema, but it is not guaranteed that all values
// will be known. This is your opportunity to do custom or advanced
// validation prior to an list resource being opened.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// validation prior to an list resource being opened.
// validation prior to a list resource being used.

// ValidateListResourceConfigRequest is the request Terraform sends when it
// wants to validate an list resource's configuration.
type ValidateListResourceConfigRequest struct {
// TypeName is the type of resource Terraform is validating.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TypeName is the type of resource Terraform is validating.
// TypeName is the type of list resource Terraform is validating.

// list resource configuration is valid. It is guaranteed to have types
// conforming to your schema, but it is not guaranteed that all values
// will be known. This is your opportunity to do custom or advanced
// validation prior to an list resource being opened.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// validation prior to an list resource being opened.
// validation prior to a list resource being used.

// - ListResource
// - ValidateListResourceConfig
//
// Deprecated: All methods will be moved into the
Copy link
Contributor

Choose a reason for hiding this comment

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

rpc := "ValidateListResourceConfig"
ctx = s.loggingContext(ctx)
ctx = logging.RpcContext(ctx, rpc)
ctx = logging.ResourceContext(ctx, protoReq.TypeName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's define a new logging.ListResourceContext method, for consistency with DataSourceContext and EphemeralResourceContext.


ctx = tf5serverlogging.DownstreamRequest(ctx)

// TODO: Remove this check and error in preference of
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

// TODO: Remove this check and error in preference of
// s.downstream.ValidateListResourceConfig below once ProviderServer interface
// implements this RPC method.
// nolint:staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

😃

if !ok {
logging.ProtocolError(ctx, "ProviderServer does not implement ValidateListResourceConfig")

protoResp := &tfplugin5.ValidateListResourceConfig_Response{
Copy link
Contributor

Choose a reason for hiding this comment

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

A non-blocking thought for follow-up: in light of recent experience with unimplemented RPCs, I'm curious if Terraform prefers the provider to return an error instead of a diagnostic.

https://pkg.go.dev/google.golang.org/grpc/status#Error and https://pkg.go.dev/google.golang.org/[email protected]/codes#CodeUnimplemented Code = 12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants