From 755f211f5fd2deb0969b0fc689333b0bc9f454e9 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 14 Sep 2022 09:23:35 -0400 Subject: [PATCH] helper/resource: Add Terraform configuration to `TRACE` logging (#1059) Reference: https://github.com/hashicorp/terraform-plugin-sdk/issues/700 For example: ```console $ TF_ACC=1 TF_LOG=TRACE go test -count=1 -run='TestTest_TestStep_ExternalProviders_DifferentVersions' -v ./helper/resource ... 2022-09-13T22:40:05.009-0400 [TRACE] sdk.helper_resource: Setting Terraform configuration: test_name=TestTest_TestStep_ExternalProviders_DifferentVersions test_step_number=1 test_terraform_path=/opt/homebrew/bin/terraform test_working_directory=/var/folders/f3/2mhr8hkx72z9dllv0ry81zm40000gq/T/plugintest971555752 test_terraform_config= | | terraform { | required_providers { | null = { | source = "registry.terraform.io/hashicorp/null" | version = "3.1.0" | } | } | } | | provider "null" {} | ... ``` --- .changelog/1059.txt | 3 +++ internal/logging/keys.go | 3 +++ internal/plugintest/working_dir.go | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 .changelog/1059.txt diff --git a/.changelog/1059.txt b/.changelog/1059.txt new file mode 100644 index 00000000000..66a49f3a378 --- /dev/null +++ b/.changelog/1059.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +helper/resource: Added Terraform configuration to `TRACE` logging +``` diff --git a/internal/logging/keys.go b/internal/logging/keys.go index 86700506a99..ad510721847 100644 --- a/internal/logging/keys.go +++ b/internal/logging/keys.go @@ -31,6 +31,9 @@ const ( // The TestStep number of the test being executed. Starts at 1. KeyTestStepNumber = "test_step_number" + // Terraform configuration used during acceptance testing Terraform operations. + KeyTestTerraformConfiguration = "test_terraform_configuration" + // The Terraform CLI logging level (TF_LOG) used for an acceptance test. KeyTestTerraformLogLevel = "test_terraform_log_level" diff --git a/internal/plugintest/working_dir.go b/internal/plugintest/working_dir.go index f9f0e5923d1..123a7ed1195 100644 --- a/internal/plugintest/working_dir.go +++ b/internal/plugintest/working_dir.go @@ -76,6 +76,8 @@ func (wd *WorkingDir) GetHelper() *Helper { // Destroy to establish the configuration. Any previously-set configuration is // discarded and any saved plan is cleared. func (wd *WorkingDir) SetConfig(ctx context.Context, cfg string) error { + logging.HelperResourceTrace(ctx, "Setting Terraform configuration", map[string]any{logging.KeyTestTerraformConfiguration: cfg}) + outFilename := filepath.Join(wd.baseDir, ConfigFileName) rmFilename := filepath.Join(wd.baseDir, ConfigFileNameJSON) bCfg := []byte(cfg)