Skip to content

Commit 1c932cf

Browse files
authored
internal/plugintest: Set CHECKPOINT_DISABLE=1 in terraform-exec directly (#913)
Reference: hashicorp/terraform-plugin-sdk#684
1 parent a0e2144 commit 1c932cf

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

.changelog/913.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
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+
```

helper/resource/plugin.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl
4343
// plugins.
4444
os.Setenv("PLUGIN_PROTOCOL_VERSIONS", "5")
4545

46-
// Terraform doesn't need to reach out to Checkpoint during testing.
47-
wd.Setenv("CHECKPOINT_DISABLE", "1")
48-
4946
// Terraform 0.12.X and 0.13.X+ treat namespaceless providers
5047
// differently in terms of what namespace they default to. So we're
5148
// going to set both variations, as we don't know which version of

internal/plugintest/environment_variables.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package plugintest
22

33
// Environment variables
44
const (
5+
// Disables checkpoint.hashicorp.com calls in Terraform CLI.
6+
EnvCheckpointDisable = "CHECKPOINT_DISABLE"
7+
58
// Environment variable with acceptance testing temporary directory for
69
// testing files and Terraform CLI installation, if installation is
710
// required. By default, the operating system temporary directory is used.

internal/plugintest/helper.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,17 @@ func (h *Helper) NewWorkingDir(ctx context.Context) (*WorkingDir, error) {
119119
}
120120

121121
tf, err := tfexec.NewTerraform(dir, h.terraformExec)
122+
122123
if err != nil {
123-
return nil, err
124+
return nil, fmt.Errorf("unable to create terraform-exec instance: %w", err)
125+
}
126+
127+
err = tf.SetEnv(map[string]string{
128+
EnvCheckpointDisable: "1",
129+
})
130+
131+
if err != nil {
132+
return nil, fmt.Errorf("unable to set terraform-exec environment variables: %w", err)
124133
}
125134

126135
return &WorkingDir{

internal/plugintest/working_dir.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ type WorkingDir struct {
4747
// reattachInfo stores the gRPC socket info required for Terraform's
4848
// plugin reattach functionality
4949
reattachInfo tfexec.ReattachInfo
50-
51-
env map[string]string
5250
}
5351

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

61-
// Setenv sets an environment variable on the WorkingDir.
62-
func (wd *WorkingDir) Setenv(envVar, val string) {
63-
if wd.env == nil {
64-
wd.env = map[string]string{}
65-
}
66-
wd.env[envVar] = val
67-
}
68-
69-
// Unsetenv removes an environment variable from the WorkingDir.
70-
func (wd *WorkingDir) Unsetenv(envVar string) {
71-
delete(wd.env, envVar)
72-
}
73-
7459
func (wd *WorkingDir) SetReattachInfo(ctx context.Context, reattachInfo tfexec.ReattachInfo) {
7560
logging.HelperResourceTrace(ctx, "Setting Terraform CLI reattach configuration", map[string]interface{}{"tf_reattach_config": reattachInfo})
7661
wd.reattachInfo = reattachInfo

0 commit comments

Comments
 (0)