Skip to content

Commit

Permalink
internal/plugintest: Set CHECKPOINT_DISABLE=1 in terraform-exec direc…
Browse files Browse the repository at this point in the history
…tly (#913)

Reference: #684
  • Loading branch information
bflad committed Mar 28, 2022
1 parent a0e2144 commit 1c932cf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .changelog/913.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
helper/resource: Execute Terraform CLI commands during acceptance testing with `CHECKPOINT_DISABLE=1` set, removing extraneous calls to checkpoint.hashicorp.com to check for latest Terraform CLI version
```
3 changes: 0 additions & 3 deletions helper/resource/plugin.go
Expand Up @@ -43,9 +43,6 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl
// plugins.
os.Setenv("PLUGIN_PROTOCOL_VERSIONS", "5")

// Terraform doesn't need to reach out to Checkpoint during testing.
wd.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: 3 additions & 0 deletions internal/plugintest/environment_variables.go
Expand Up @@ -2,6 +2,9 @@ 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
11 changes: 10 additions & 1 deletion internal/plugintest/helper.go
Expand Up @@ -119,8 +119,17 @@ func (h *Helper) NewWorkingDir(ctx context.Context) (*WorkingDir, error) {
}

tf, err := tfexec.NewTerraform(dir, h.terraformExec)

if err != nil {
return nil, err
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{
Expand Down
15 changes: 0 additions & 15 deletions internal/plugintest/working_dir.go
Expand Up @@ -47,8 +47,6 @@ type WorkingDir struct {
// reattachInfo stores the gRPC socket info required for Terraform's
// plugin reattach functionality
reattachInfo tfexec.ReattachInfo

env map[string]string
}

// Close deletes the directories and files created to represent the receiving
Expand All @@ -58,19 +56,6 @@ func (wd *WorkingDir) Close() error {
return os.RemoveAll(wd.baseDir)
}

// Setenv sets an environment variable on the WorkingDir.
func (wd *WorkingDir) Setenv(envVar, val string) {
if wd.env == nil {
wd.env = map[string]string{}
}
wd.env[envVar] = val
}

// Unsetenv removes an environment variable from the WorkingDir.
func (wd *WorkingDir) Unsetenv(envVar string) {
delete(wd.env, envVar)
}

func (wd *WorkingDir) SetReattachInfo(ctx context.Context, reattachInfo tfexec.ReattachInfo) {
logging.HelperResourceTrace(ctx, "Setting Terraform CLI reattach configuration", map[string]interface{}{"tf_reattach_config": reattachInfo})
wd.reattachInfo = reattachInfo
Expand Down

0 comments on commit 1c932cf

Please sign in to comment.