Skip to content

Commit

Permalink
add env var for PluginCacheMayBreakDependencyLockFile (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero authored Jun 17, 2024
1 parent c88db3c commit 0c16f78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
18 changes: 12 additions & 6 deletions server/neptune/workflows/activities/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"bytes"
"context"
"fmt"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/command"
"io"
"path/filepath"
"strings"
"sync"

"github.com/runatlantis/atlantis/server/neptune/workflows/activities/command"

key "github.com/runatlantis/atlantis/server/neptune/context"
"go.temporal.io/sdk/activity"

Expand All @@ -23,11 +24,12 @@ import (
)

const (
TFInAutomation = "TF_IN_AUTOMATION"
TFInAutomationVal = "true"
AtlantisTerraformVersion = "ATLANTIS_TERRAFORM_VERSION"
Dir = "DIR"
TFPluginCacheDir = "TF_PLUGIN_CACHE_DIR"
TFInAutomation = "TF_IN_AUTOMATION"
TFInAutomationVal = "true"
AtlantisTerraformVersion = "ATLANTIS_TERRAFORM_VERSION"
Dir = "DIR"
TFPluginCacheDir = "TF_PLUGIN_CACHE_DIR"
PluginCacheMayBreakDependencyLockFile = "TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE"
)

// TerraformClientError can be used to assert a non-retryable error type for
Expand Down Expand Up @@ -419,4 +421,8 @@ func (t *terraformActivities) addTerraformEnvs(envs map[string]string, path stri
envs[AtlantisTerraformVersion] = tfVersion.String()
envs[Dir] = path
envs[TFPluginCacheDir] = t.CacheDir
// This is not a long-term fix. Eventually the underlying functionality in terraform will be changed.
// See https://developer.hashicorp.com/terraform/cli/config/config-file#allowing-the-provider-plugin-cache-to-break-the-dependency-lock-file
// and https://github.com/hashicorp/terraform/issues/32205 for discussions and context.
envs[PluginCacheMayBreakDependencyLockFile] = "true"
}
17 changes: 16 additions & 1 deletion server/neptune/workflows/activities/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package activities
import (
"context"
"fmt"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/command"
"strings"
"sync"
"testing"

"github.com/runatlantis/atlantis/server/neptune/workflows/activities/command"

"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/file"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
Expand Down Expand Up @@ -133,6 +134,7 @@ func TestTerraformInit_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand All @@ -157,6 +159,7 @@ func TestTerraformInit_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand All @@ -173,6 +176,7 @@ func TestTerraformInit_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},

// defaults
Expand Down Expand Up @@ -267,6 +271,7 @@ func TestTerraformInit_StreamsOutput(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
version: expectedVersion,
resp: expectedMsgStr,
Expand Down Expand Up @@ -337,6 +342,7 @@ func TestTerraformPlan_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand Down Expand Up @@ -367,6 +373,7 @@ func TestTerraformPlan_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand All @@ -387,6 +394,7 @@ func TestTerraformPlan_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand All @@ -404,6 +412,7 @@ func TestTerraformPlan_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},

// default
Expand Down Expand Up @@ -512,6 +521,7 @@ func TestTerraformPlan_ReturnsResponse(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
version: expectedVersion,
resp: expectedMsgStr,
Expand All @@ -526,6 +536,7 @@ func TestTerraformPlan_ReturnsResponse(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
version: expectedVersion,
resp: "{\"format_version\": \"1.0\",\"resource_changes\":[{\"change\":{\"actions\":[\"update\"]},\"address\":\"type.resource\"}]}",
Expand Down Expand Up @@ -602,6 +613,7 @@ func TestTerraformApply_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand All @@ -624,6 +636,7 @@ func TestTerraformApply_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
},
{
Expand All @@ -640,6 +653,7 @@ func TestTerraformApply_RequestValidation(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},

//default
Expand Down Expand Up @@ -720,6 +734,7 @@ func TestTerraformApply_StreamsOutput(t *testing.T) {
"DIR": "some/path",
"TF_IN_AUTOMATION": "true",
"TF_PLUGIN_CACHE_DIR": "some/dir",
"TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE": "true",
},
version: expectedVersion,
resp: expectedMsgStr,
Expand Down

0 comments on commit 0c16f78

Please sign in to comment.