Skip to content

Commit

Permalink
added logging for req/resp deferred actions
Browse files Browse the repository at this point in the history
  • Loading branch information
austinvalle committed May 3, 2024
1 parent 3a4fbc8 commit a58e305
Show file tree
Hide file tree
Showing 11 changed files with 1,120 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/logging/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ const (
// The protocol version being used, as a string, such as "6"
KeyProtocolVersion = "tf_proto_version"

// The Deferred reason for an RPC response
KeyDeferredReason = "tf_deferred_reason"

// Whether the GetProviderSchemaOptional server capability is enabled
KeyServerCapabilityGetProviderSchemaOptional = "tf_server_capability_get_provider_schema_optional"

// Whether the PlanDestroy server capability is enabled
KeyServerCapabilityPlanDestroy = "tf_server_capability_plan_destroy"

// Whether the DeferralAllowed client capability is enabled
KeyClientCapabilityDeferralAllowed = "tf_client_capability_deferral_allowed"
)
76 changes: 76 additions & 0 deletions tfprotov5/internal/tf5serverlogging/client_capabilities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package tf5serverlogging

import (
"context"

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

// ConfigureProviderClientCapabilities generates a TRACE "Announced client capabilities" log.
func ConfigureProviderClientCapabilities(ctx context.Context, capabilities *tfprotov5.ConfigureProviderClientCapabilities) {
responseFields := map[string]interface{}{
logging.KeyClientCapabilityDeferralAllowed: false,
}

if capabilities != nil {
responseFields[logging.KeyClientCapabilityDeferralAllowed] = capabilities.DeferralAllowed
}

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

// ReadDataSourceClientCapabilities generates a TRACE "Announced client capabilities" log.
func ReadDataSourceClientCapabilities(ctx context.Context, capabilities *tfprotov5.ReadDataSourceClientCapabilities) {
responseFields := map[string]interface{}{
logging.KeyClientCapabilityDeferralAllowed: false,
}

if capabilities != nil {
responseFields[logging.KeyClientCapabilityDeferralAllowed] = capabilities.DeferralAllowed
}

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

// ReadResourceClientCapabilities generates a TRACE "Announced client capabilities" log.
func ReadResourceClientCapabilities(ctx context.Context, capabilities *tfprotov5.ReadResourceClientCapabilities) {
responseFields := map[string]interface{}{
logging.KeyClientCapabilityDeferralAllowed: false,
}

if capabilities != nil {
responseFields[logging.KeyClientCapabilityDeferralAllowed] = capabilities.DeferralAllowed
}

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

// PlanResourceChangeClientCapabilities generates a TRACE "Announced client capabilities" log.
func PlanResourceChangeClientCapabilities(ctx context.Context, capabilities *tfprotov5.PlanResourceChangeClientCapabilities) {
responseFields := map[string]interface{}{
logging.KeyClientCapabilityDeferralAllowed: false,
}

if capabilities != nil {
responseFields[logging.KeyClientCapabilityDeferralAllowed] = capabilities.DeferralAllowed
}

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

// ImportResourceStateClientCapabilities generates a TRACE "Announced client capabilities" log.
func ImportResourceStateClientCapabilities(ctx context.Context, capabilities *tfprotov5.ImportResourceStateClientCapabilities) {
responseFields := map[string]interface{}{
logging.KeyClientCapabilityDeferralAllowed: false,
}

if capabilities != nil {
responseFields[logging.KeyClientCapabilityDeferralAllowed] = capabilities.DeferralAllowed
}

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

0 comments on commit a58e305

Please sign in to comment.