Skip to content

Commit

Permalink
helper/resource: Set CHECKPOINT_DISABLE environment variable outside …
Browse files Browse the repository at this point in the history
…terraform-exec (#937)

Reference: #935

When using `(tfexec.Terraform).SetEnv()`, it will no longer copy `os.Environ()`. It is also not possible for the code to call `tfexec.CleanEnv(os.Environ())` with the additional environment variable as it would strip previously accepted `TF_VAR_` environment variables. There are no plans to change this behavior in terraform-exec.
  • Loading branch information
bflad committed Apr 12, 2022
1 parent fd9ac3c commit 85b9ee9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .changelog/pending.txt
@@ -0,0 +1,3 @@
```release-note:bug
helper/resource: Prevented regression since 2.13.0 with the removal of environment variables, including `TF_VAR_*`, when calling Terraform CLI commands
```
8 changes: 8 additions & 0 deletions helper/resource/plugin.go
Expand Up @@ -43,6 +43,14 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl
// plugins.
os.Setenv("PLUGIN_PROTOCOL_VERSIONS", "5")

// Acceptance testing does not need to call checkpoint as the output
// is not accessible, nor desirable if explicitly using
// TF_ACC_TERRAFORM_PATH or TF_ACC_TERRAFORM_VERSION environment variables.
//
// Avoid calling (tfexec.Terraform).SetEnv() as it will stop copying
// os.Environ() and prevents TF_VAR_ environment variable usage.
os.Setenv("CHECKPOINT_DISABLE", "1")

// Terraform 0.12.X and 0.13.X+ treat namespaceless providers
// differently in terms of what namespace they default to. So we're
// going to set both variations, as we don't know which version of
Expand Down
3 changes: 0 additions & 3 deletions internal/plugintest/environment_variables.go
Expand Up @@ -2,9 +2,6 @@ package plugintest

// Environment variables
const (
// Disables checkpoint.hashicorp.com calls in Terraform CLI.
EnvCheckpointDisable = "CHECKPOINT_DISABLE"

// Environment variable with acceptance testing temporary directory for
// testing files and Terraform CLI installation, if installation is
// required. By default, the operating system temporary directory is used.
Expand Down
8 changes: 0 additions & 8 deletions internal/plugintest/helper.go
Expand Up @@ -124,14 +124,6 @@ func (h *Helper) NewWorkingDir(ctx context.Context) (*WorkingDir, error) {
return nil, fmt.Errorf("unable to create terraform-exec instance: %w", err)
}

err = tf.SetEnv(map[string]string{
EnvCheckpointDisable: "1",
})

if err != nil {
return nil, fmt.Errorf("unable to set terraform-exec environment variables: %w", err)
}

return &WorkingDir{
h: h,
tf: tf,
Expand Down

0 comments on commit 85b9ee9

Please sign in to comment.