Skip to content

Commit

Permalink
helper/resource: Add Terraform configuration to TRACE logging (#1059)
Browse files Browse the repository at this point in the history
Reference: #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" {}
  |
...
```
  • Loading branch information
bflad committed Sep 14, 2022
1 parent 0f41bb0 commit 755f211
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1059.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
helper/resource: Added Terraform configuration to `TRACE` logging
```
3 changes: 3 additions & 0 deletions internal/logging/keys.go
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions internal/plugintest/working_dir.go
Expand Up @@ -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)
Expand Down

0 comments on commit 755f211

Please sign in to comment.