Skip to content

Commit f07c491

Browse files
Add -terraform-dir option to acceptance tests (#3497)
## Changes This flag makes the download location of the Terraform CLI and providers configurable instead of defaulting to acceptance/build. ## Why DBR does not allow creating symlinks between the workspace file system and the local file system mount on an serverless instance. So in order to run acceptance tests on workspace file system, the Databricks terraform provider must also live on the workspace file system. ## Background We configure file system mirrors in acceptance tests for Terraform providers in order to only download the provider once: ``` provider_installation { filesystem_mirror { path = "/Users/shreyas.goenka/repos/cli/acceptance/build/darwin_arm64/tfplugins" include = ["registry.terraform.io/databricks/databricks"] } } ``` Because the DBR CLI repo lives on the local file mount, but the tests are run on the workspace file system, this file system mirror fails because it cannot create the necessary symlinks during `terraform init` (which is called during `bundle deploy`). Making the Terraform installation directory configurable allows us to install TF on the workspace file system, bypassing this limitation. ## Tests Manually verified that: 1. The `install_terraform.py` script respects the—terraform-dir value, and the Terraform CLI and provider are installed in the correct directory. 2. The correct environment variables are set when the test is executed: ``` DATABRICKS_TF_CLI_CONFIG_FILE=/Users/shreyas.goenka/repos/cli/somecustomdir/.terraformrc DATABRICKS_TF_EXEC_PATH=/Users/shreyas.goenka/repos/cli/somecustomdir/terraform ```
1 parent 85537b5 commit f07c491

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

acceptance/acceptance_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
SkipLocal bool
4848
UseVersion string
4949
WorkspaceTmpDir bool
50+
TerraformDir string
5051
)
5152

5253
// In order to debug CLI running under acceptance test, search for TestInprocessMode and update
@@ -72,6 +73,11 @@ func init() {
7273
// DABs in the workspace runs on the workspace file system. This flags does the same for acceptance tests
7374
// to simulate an identical environment.
7475
flag.BoolVar(&WorkspaceTmpDir, "workspace-tmp-dir", false, "Run tests on the workspace file system (For DBR testing).")
76+
77+
// Symlinks from workspace file system to local file mount are not supported on DBR. Terraform implicitly
78+
// creates these symlinks when a file_mirror is used for a provider (in .terraformrc). This flag
79+
// allows us to download the provider to the workspace file system on DBR enabling DBR integration testing.
80+
flag.StringVar(&TerraformDir, "terraform-dir", "", "Directory to download the terraform provider to")
7581
}
7682

7783
const (
@@ -148,9 +154,16 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
148154
t.Setenv("LC_ALL", "C")
149155

150156
buildDir := filepath.Join(cwd, "build", fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH))
157+
err = os.MkdirAll(buildDir, os.ModePerm)
158+
require.NoError(t, err)
159+
160+
terraformDir := TerraformDir
161+
if terraformDir == "" {
162+
terraformDir = buildDir
163+
}
151164

152-
// Download terraform and provider and create config; this also creates build directory.
153-
RunCommand(t, []string{"python3", filepath.Join(cwd, "install_terraform.py"), "--targetdir", buildDir}, ".")
165+
// Download terraform and provider and create config.
166+
RunCommand(t, []string{"python3", filepath.Join(cwd, "install_terraform.py"), "--targetdir", terraformDir}, ".")
154167

155168
wheelPath := buildDatabricksBundlesWheel(t, buildDir)
156169
if wheelPath != "" {
@@ -226,12 +239,12 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
226239
repls.Set(testDefaultWarehouseId, "[TEST_DEFAULT_WAREHOUSE_ID]")
227240
}
228241

229-
terraformrcPath := filepath.Join(buildDir, ".terraformrc")
242+
terraformrcPath := filepath.Join(terraformDir, ".terraformrc")
230243
t.Setenv("TF_CLI_CONFIG_FILE", terraformrcPath)
231244
t.Setenv("DATABRICKS_TF_CLI_CONFIG_FILE", terraformrcPath)
232245
repls.SetPath(terraformrcPath, "[DATABRICKS_TF_CLI_CONFIG_FILE]")
233246

234-
terraformExecPath := filepath.Join(buildDir, "terraform") + exeSuffix
247+
terraformExecPath := filepath.Join(terraformDir, "terraform") + exeSuffix
235248
t.Setenv("DATABRICKS_TF_EXEC_PATH", terraformExecPath)
236249
t.Setenv("TERRAFORM", terraformExecPath)
237250
repls.SetPath(terraformExecPath, "[TERRAFORM]")

0 commit comments

Comments
 (0)