Skip to content

Commit 15ff4b0

Browse files
committed
remove dedicated logging context and temporary interface
1 parent 0348efb commit 15ff4b0

File tree

6 files changed

+6
-58
lines changed

6 files changed

+6
-58
lines changed

internal/logging/context.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,6 @@ func ActionContext(ctx context.Context, action string) context.Context {
109109
return ctx
110110
}
111111

112-
// GenerateResourceConfig injects the resource type into logger contexts.
113-
func GenerateResourceConfigContext(ctx context.Context, action string) context.Context {
114-
ctx = tfsdklog.SetField(ctx, KeyGenerateResourceConfigType, action)
115-
ctx = tfsdklog.SubsystemSetField(ctx, SubsystemProto, KeyGenerateResourceConfigType, action)
116-
ctx = tflog.SetField(ctx, KeyGenerateResourceConfigType, action)
117-
118-
return ctx
119-
}
120-
121112
// RpcContext injects the RPC name into logger contexts.
122113
func RpcContext(ctx context.Context, rpc string) context.Context {
123114
ctx = tfsdklog.SetField(ctx, KeyRPC, rpc)

internal/logging/keys.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ const (
6666
// The action being operated on
6767
KeyActionType = "tf_action_type"
6868

69-
// The type of resource being operated on
70-
KeyGenerateResourceConfigType = "tf_generate_resource_config_type"
71-
7269
// Path to protocol data file, such as "/tmp/example.json"
7370
KeyProtocolDataFile = "tf_proto_data_file"
7471

@@ -87,7 +84,7 @@ const (
8784
// Whether the PlanDestroy server capability is enabled
8885
KeyServerCapabilityPlanDestroy = "tf_server_capability_plan_destroy"
8986

90-
// Whether the PlanDestroy server capability is enabled
87+
// Whether the GenerateResourceConfig server capability is enabled
9188
KeyServerCapabilityGenerateResourceConfig = "tf_server_capability_generate_resource_config"
9289

9390
// Whether the DeferralAllowed client capability is enabled

tfprotov5/provider.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,6 @@ type ProviderServerWithListResource interface {
9393
ListResourceServer
9494
}
9595

96-
// ProviderServerGenerateResourceConfig is a temporary interface for servers
97-
// to implement the GenerateResourceConfig RPC
98-
//
99-
// - GenerateResourceConfig
100-
//
101-
// Deprecated: All methods will be moved into the
102-
// ProviderServer interface and this interface will be removed in a future
103-
// version.
104-
type ProviderServerGenerateResourceConfig interface {
105-
ProviderServer
106-
107-
// GenerateResourceConfig is an interface encapsulating the GenerateResourceConfig RPC request.
108-
GenerateResourceConfig(context.Context, *GenerateResourceConfigRequest) (*GenerateResourceConfigResponse, error)
109-
}
110-
11196
// ProviderServerWithActions is a temporary interface for servers
11297
// to implement Action RPCs
11398
//

tfprotov5/resource.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ type ResourceServer interface {
7070
// identity state to upgrade it to the latest state schema.
7171
UpgradeResourceIdentity(context.Context, *UpgradeResourceIdentityRequest) (*UpgradeResourceIdentityResponse, error)
7272

73-
// TODO: Once this interface is no longer optional we can uncomment this
7473
// GenerateResourceConfig is called when Terraform wants to generate a resource
7574
// configuration for importing to a resource address that doesn't exist yet.
7675
// It is called during a plan when the -generate-config-out flag is provided.
7776
//
7877
// This functionality is only supported in Terraform 1.14 and later. The
7978
// provider must have enabled the GenerateResourceConfig server capability to
8079
// enable these requests.
81-
// GenerateResourceConfig(context.Context, *GenerateResourceConfigRequest) (*GenerateResourceConfigResponse, error)
80+
GenerateResourceConfig(context.Context, *GenerateResourceConfigRequest) (*GenerateResourceConfigResponse, error)
8281
}
8382

8483
// ValidateResourceTypeConfigRequest is the request Terraform sends when it

tfprotov5/tf5server/server.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func (s *server) stoppableContext(ctx context.Context) context.Context {
456456
// terraform-plugin-log loggers injected.
457457
func (s *server) loggingContext(ctx context.Context) context.Context {
458458
if s.useTFLogSink {
459-
ctx = tfsdklog.ContextWithTestLogging(ctx, s.testHandle.Name())
459+
//ctx = tfsdklog.ContextWithStandardLogging(ctx, s.testHandle.Name())
460460
}
461461

462462
ctx = logging.InitContext(ctx, s.tflogSDKOpts, s.tflogOpts)
@@ -1488,7 +1488,7 @@ func (s *server) GenerateResourceConfig(ctx context.Context, protoReq *tfplugin5
14881488
rpc := "GenerateResourceConfig"
14891489
ctx = s.loggingContext(ctx)
14901490
ctx = logging.RpcContext(ctx, rpc)
1491-
ctx = logging.GenerateResourceConfigContext(ctx, protoReq.TypeName)
1491+
ctx = logging.ResourceContext(ctx, protoReq.TypeName)
14921492
ctx = s.stoppableContext(ctx)
14931493
logging.ProtocolTrace(ctx, "Received request")
14941494
defer logging.ProtocolTrace(ctx, "Served request")
@@ -1499,31 +1499,7 @@ func (s *server) GenerateResourceConfig(ctx context.Context, protoReq *tfplugin5
14991499

15001500
ctx = tf5serverlogging.DownstreamRequest(ctx)
15011501

1502-
// TODO: Remove this check and error in preference of
1503-
// s.downstream.GenerateResourceConfig below once ProviderServer interface
1504-
// implements this RPC method.
1505-
// nolint:staticcheck
1506-
generateResourceConfigProviderServer, ok := s.downstream.(tfprotov5.ProviderServerGenerateResourceConfig)
1507-
if !ok {
1508-
logging.ProtocolError(ctx, "ProviderServer does not implement GenerateResourceConfig")
1509-
1510-
protoResp := &tfplugin5.GenerateResourceConfig_Response{
1511-
Diagnostics: []*tfplugin5.Diagnostic{
1512-
{
1513-
Severity: tfplugin5.Diagnostic_ERROR,
1514-
Summary: "Provider GenerateResourceConfig Not Implemented",
1515-
Detail: "A GenerateResourceConfig call was received by the provider, however the provider does not implement the call. " +
1516-
"Either upgrade the provider to a version that implements action support or this is a bug in Terraform that should be reported to the Terraform maintainers.",
1517-
},
1518-
},
1519-
}
1520-
1521-
return protoResp, nil
1522-
}
1523-
1524-
// TODO: Update this to call downstream once optional interface is removed
1525-
// resp, err := s.downstream.GenerateResourceConfig(ctx, req)
1526-
resp, err := generateResourceConfigProviderServer.GenerateResourceConfig(ctx, req)
1502+
resp, err := s.downstream.GenerateResourceConfig(ctx, req)
15271503
if err != nil {
15281504
logging.ProtocolError(ctx, "Error from downstream", map[string]any{logging.KeyError: err})
15291505
return nil, err

tfprotov6/tf6server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func (s *server) stoppableContext(ctx context.Context) context.Context {
456456
// terraform-plugin-log loggers injected.
457457
func (s *server) loggingContext(ctx context.Context) context.Context {
458458
if s.useTFLogSink {
459-
ctx = tfsdklog.ContextWithTestLogging(ctx, s.testHandle.Name())
459+
//ctx = tfsdklog.ContextWithStandardLogging(ctx, s.testHandle.Name())
460460
}
461461

462462
ctx = logging.InitContext(ctx, s.tflogSDKOpts, s.tflogOpts)

0 commit comments

Comments
 (0)