Skip to content

Commit 0b4635e

Browse files
committed
fix: back end data directory
Signed-off-by: matttrach <matt.trachier@suse.com>
1 parent 1c47ba5 commit 0b4635e

5 files changed

Lines changed: 23 additions & 22 deletions

File tree

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/deploy/destroy.sh.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TF_CLI_ARGS_init=""
44
TF_CLI_ARGS_apply=""
55
export TF_DATA_DIR="${tf_data_dir}"
66
if [ -z "${skip_destroy}" ]; then
7-
timeout -k 1m ${timeout} terraform init -upgrade
7+
timeout -k 1m ${timeout} terraform init -upgrade -reconfigure
88
timeout -k 1m ${timeout} terraform destroy -var-file="${deploy_path}/inputs.tfvars" -auto-approve -state="${deploy_path}/tfstate" || true
99
else
1010
echo "Not destroying deployed module, it will no longer be managed here."

modules/deploy/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ locals {
3434
interval = var.interval
3535
timeout = var.timeout
3636
init = var.init
37-
init_script = (local.init ? "terraform init -upgrade" : "")
37+
init_script = (local.init ? "terraform init -reconfigure -upgrade" : "")
3838
tf_data_dir = var.data_path != null ? var.data_path : path.root
3939
skip_destroy = (var.skip_destroy ? "true" : "")
4040
}

test/tests/three/basic_test.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ func TestThreeBasic(t *testing.T) {
5151
sshAgent := ssh.SshAgentWithKeyPair(t, keyPair.KeyPair)
5252
t.Logf("Key %s created and added to agent", keyPair.Name)
5353

54-
var tfOptions []*terraform.Options
5554
backendTerraformOptions, err := util.CreateObjectStorageBackend(t, testDir, id, owner, region)
56-
tfOptions = append(tfOptions, backendTerraformOptions)
55+
tfOptions := []*terraform.Options{backendTerraformOptions}
5756
if err != nil {
5857
t.Log("Test failed, tearing down...")
5958
util.Teardown(t, testDir, exampleDir, tfOptions, keyPair, sshAgent)
@@ -93,29 +92,25 @@ func TestThreeBasic(t *testing.T) {
9392
},
9493
// Environment variables to set when running Terraform
9594
EnvVars: map[string]string{
96-
"AWS_DEFAULT_REGION": region,
97-
"AWS_REGION": region,
98-
"TF_DATA_DIR": testDir,
99-
"TF_IN_AUTOMATION": "1",
100-
"TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"",
101-
"TF_CLI_ARGS_plan": "-no-color",
102-
"TF_CLI_ARGS_apply": "-no-color",
103-
"TF_CLI_ARGS_destroy": "-no-color",
104-
"TF_CLI_ARGS_output": "-no-color",
95+
"AWS_DEFAULT_REGION": region,
96+
"AWS_REGION": region,
97+
"TF_DATA_DIR": testDir,
98+
"TF_IN_AUTOMATION": "1",
99+
"TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"",
105100
},
106101
RetryableTerraformErrors: util.GetRetryableTerraformErrors(),
107102
NoColor: true,
108103
SshAgent: sshAgent,
104+
Reconfigure: true,
109105
Upgrade: true,
110106
})
111107
// we need to prepend the main options because we need to destroy it before the backend
112-
tfOptions = append([]*terraform.Options{terraformOptions}, tfOptions...)
113-
t.Logf("tfOptions: %v", tfOptions)
108+
newTfOptions := []*terraform.Options{terraformOptions, backendTerraformOptions}
114109
_, err = terraform.InitAndApplyE(t, terraformOptions)
115110
if err != nil {
116111
t.Log("Test failed, tearing down...")
117112
util.GetErrorLogs(t, testDir+"/kubeconfig")
118-
util.Teardown(t, testDir, exampleDir, tfOptions, keyPair, sshAgent)
113+
util.Teardown(t, testDir, exampleDir, newTfOptions, keyPair, sshAgent)
119114
t.Fatalf("Error creating cluster: %s", err)
120115
}
121116
util.CheckReady(t, testDir+"/kubeconfig")
@@ -125,5 +120,5 @@ func TestThreeBasic(t *testing.T) {
125120
} else {
126121
t.Log("Test passed...")
127122
}
128-
util.Teardown(t, testDir, exampleDir, tfOptions, keyPair, sshAgent)
123+
util.Teardown(t, testDir, exampleDir, newTfOptions, keyPair, sshAgent)
129124
}

test/tests/util.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tests
33
import (
44
"cmp"
55
"context"
6+
"encoding/json"
67
"errors"
78
"fmt"
89
"os"
@@ -399,6 +400,11 @@ func Teardown(t *testing.T, dataDir string, exampleDir string, options []*terraf
399400
if directoryExists {
400401
for _, option := range options {
401402
t.Logf("Tearing down %v", option.TerraformDir)
403+
jsonOptions, err := json.Marshal(option)
404+
if err != nil {
405+
t.Logf("Failed to marshal options for destroy log: %v", err)
406+
}
407+
fmt.Println(string(jsonOptions))
402408
_, err = terraform.InitE(t, option)
403409
if err != nil {
404410
t.Logf("Failed to init for destroy: %v", err)
@@ -514,15 +520,15 @@ func CreateObjectStorageBackend(t *testing.T, testDir string, id string, owner s
514520
EnvVars: map[string]string{
515521
"AWS_DEFAULT_REGION": region,
516522
"AWS_REGION": region,
517-
"TF_DATA_DIR": testDir,
523+
"TF_DATA_DIR": testDir + "/backend",
518524
"TF_IN_AUTOMATION": "1",
519-
"TF_CLI_ARGS_init": "-reconfigure",
520525
"TF_CLI_ARGS_plan": "-state=" + testDir + "/backend/tfstate",
521526
"TF_CLI_ARGS_apply": "-state=" + testDir + "/backend/tfstate",
522527
"TF_CLI_ARGS_destroy": "-state=" + testDir + "/backend/tfstate",
523528
"TF_CLI_ARGS_output": "-state=" + testDir + "/backend/tfstate",
524529
},
525530
RetryableTerraformErrors: GetRetryableTerraformErrors(),
531+
Reconfigure: true,
526532
NoColor: true,
527533
Upgrade: true,
528534
})

0 commit comments

Comments
 (0)