-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: main
Are you sure you want to change the base?
Conversation
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.
Looks good to me
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{}, |
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'm also finding myself repeating the setup of empty map
s in table-driven tests. An optional follow-up: how do we feel about using cmptopts.EquateEmpty
to remove the repetitive setup of empty map
s? I have never used it, but it seems useful here.
"context" | ||
) | ||
|
||
// ListResourceMetadata describes metadata for an list resource in the GetMetadata |
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.
// 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. |
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.
// 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. |
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.
// 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. |
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.
// 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 |
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.
✨
rpc := "ValidateListResourceConfig" | ||
ctx = s.loggingContext(ctx) | ||
ctx = logging.RpcContext(ctx, rpc) | ||
ctx = logging.ResourceContext(ctx, protoReq.TypeName) |
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.
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 |
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.
💯
// TODO: Remove this check and error in preference of | ||
// s.downstream.ValidateListResourceConfig below once ProviderServer interface | ||
// implements this RPC method. | ||
// nolint:staticcheck |
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.
😃
if !ok { | ||
logging.ProtocolError(ctx, "ProviderServer does not implement ValidateListResourceConfig") | ||
|
||
protoResp := &tfplugin5.ValidateListResourceConfig_Response{ |
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.
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#Code – Unimplemented Code = 12
.
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
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
No