fix: back end data directory
Signed-off-by: matttrach <matt.trachier@suse.com>
This commit is contained in:
parent
1c47ba50c9
commit
0b4635ea32
|
|
@ -20,11 +20,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1750811787,
|
||||
"narHash": "sha256-rD/978c35JXz6JLAzciTIOCMenPumF6zrQOj4rVZeHE=",
|
||||
"lastModified": 1751180975,
|
||||
"narHash": "sha256-BKk4yDiXr4LdF80OTVqYJ53Q74rOcA/82EClXug8xsY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "992f916556fcfaa94451ebc7fc6e396134bbf5b1",
|
||||
"rev": "a48741b083d4f36dd79abd9f760c84da6b4dc0e5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ TF_CLI_ARGS_init=""
|
|||
TF_CLI_ARGS_apply=""
|
||||
export TF_DATA_DIR="${tf_data_dir}"
|
||||
if [ -z "${skip_destroy}" ]; then
|
||||
timeout -k 1m ${timeout} terraform init -upgrade
|
||||
timeout -k 1m ${timeout} terraform init -upgrade -reconfigure
|
||||
timeout -k 1m ${timeout} terraform destroy -var-file="${deploy_path}/inputs.tfvars" -auto-approve -state="${deploy_path}/tfstate" || true
|
||||
else
|
||||
echo "Not destroying deployed module, it will no longer be managed here."
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ locals {
|
|||
interval = var.interval
|
||||
timeout = var.timeout
|
||||
init = var.init
|
||||
init_script = (local.init ? "terraform init -upgrade" : "")
|
||||
init_script = (local.init ? "terraform init -reconfigure -upgrade" : "")
|
||||
tf_data_dir = var.data_path != null ? var.data_path : path.root
|
||||
skip_destroy = (var.skip_destroy ? "true" : "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,9 +51,8 @@ func TestThreeBasic(t *testing.T) {
|
|||
sshAgent := ssh.SshAgentWithKeyPair(t, keyPair.KeyPair)
|
||||
t.Logf("Key %s created and added to agent", keyPair.Name)
|
||||
|
||||
var tfOptions []*terraform.Options
|
||||
backendTerraformOptions, err := util.CreateObjectStorageBackend(t, testDir, id, owner, region)
|
||||
tfOptions = append(tfOptions, backendTerraformOptions)
|
||||
tfOptions := []*terraform.Options{backendTerraformOptions}
|
||||
if err != nil {
|
||||
t.Log("Test failed, tearing down...")
|
||||
util.Teardown(t, testDir, exampleDir, tfOptions, keyPair, sshAgent)
|
||||
|
|
@ -93,29 +92,25 @@ func TestThreeBasic(t *testing.T) {
|
|||
},
|
||||
// Environment variables to set when running Terraform
|
||||
EnvVars: map[string]string{
|
||||
"AWS_DEFAULT_REGION": region,
|
||||
"AWS_REGION": region,
|
||||
"TF_DATA_DIR": testDir,
|
||||
"TF_IN_AUTOMATION": "1",
|
||||
"TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"",
|
||||
"TF_CLI_ARGS_plan": "-no-color",
|
||||
"TF_CLI_ARGS_apply": "-no-color",
|
||||
"TF_CLI_ARGS_destroy": "-no-color",
|
||||
"TF_CLI_ARGS_output": "-no-color",
|
||||
"AWS_DEFAULT_REGION": region,
|
||||
"AWS_REGION": region,
|
||||
"TF_DATA_DIR": testDir,
|
||||
"TF_IN_AUTOMATION": "1",
|
||||
"TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"",
|
||||
},
|
||||
RetryableTerraformErrors: util.GetRetryableTerraformErrors(),
|
||||
NoColor: true,
|
||||
SshAgent: sshAgent,
|
||||
Reconfigure: true,
|
||||
Upgrade: true,
|
||||
})
|
||||
// we need to prepend the main options because we need to destroy it before the backend
|
||||
tfOptions = append([]*terraform.Options{terraformOptions}, tfOptions...)
|
||||
t.Logf("tfOptions: %v", tfOptions)
|
||||
newTfOptions := []*terraform.Options{terraformOptions, backendTerraformOptions}
|
||||
_, err = terraform.InitAndApplyE(t, terraformOptions)
|
||||
if err != nil {
|
||||
t.Log("Test failed, tearing down...")
|
||||
util.GetErrorLogs(t, testDir+"/kubeconfig")
|
||||
util.Teardown(t, testDir, exampleDir, tfOptions, keyPair, sshAgent)
|
||||
util.Teardown(t, testDir, exampleDir, newTfOptions, keyPair, sshAgent)
|
||||
t.Fatalf("Error creating cluster: %s", err)
|
||||
}
|
||||
util.CheckReady(t, testDir+"/kubeconfig")
|
||||
|
|
@ -125,5 +120,5 @@ func TestThreeBasic(t *testing.T) {
|
|||
} else {
|
||||
t.Log("Test passed...")
|
||||
}
|
||||
util.Teardown(t, testDir, exampleDir, tfOptions, keyPair, sshAgent)
|
||||
util.Teardown(t, testDir, exampleDir, newTfOptions, keyPair, sshAgent)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package tests
|
|||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
|
@ -399,6 +400,11 @@ func Teardown(t *testing.T, dataDir string, exampleDir string, options []*terraf
|
|||
if directoryExists {
|
||||
for _, option := range options {
|
||||
t.Logf("Tearing down %v", option.TerraformDir)
|
||||
jsonOptions, err := json.Marshal(option)
|
||||
if err != nil {
|
||||
t.Logf("Failed to marshal options for destroy log: %v", err)
|
||||
}
|
||||
fmt.Println(string(jsonOptions))
|
||||
_, err = terraform.InitE(t, option)
|
||||
if err != nil {
|
||||
t.Logf("Failed to init for destroy: %v", err)
|
||||
|
|
@ -514,15 +520,15 @@ func CreateObjectStorageBackend(t *testing.T, testDir string, id string, owner s
|
|||
EnvVars: map[string]string{
|
||||
"AWS_DEFAULT_REGION": region,
|
||||
"AWS_REGION": region,
|
||||
"TF_DATA_DIR": testDir,
|
||||
"TF_DATA_DIR": testDir + "/backend",
|
||||
"TF_IN_AUTOMATION": "1",
|
||||
"TF_CLI_ARGS_init": "-reconfigure",
|
||||
"TF_CLI_ARGS_plan": "-state=" + testDir + "/backend/tfstate",
|
||||
"TF_CLI_ARGS_apply": "-state=" + testDir + "/backend/tfstate",
|
||||
"TF_CLI_ARGS_destroy": "-state=" + testDir + "/backend/tfstate",
|
||||
"TF_CLI_ARGS_output": "-state=" + testDir + "/backend/tfstate",
|
||||
},
|
||||
RetryableTerraformErrors: GetRetryableTerraformErrors(),
|
||||
Reconfigure: true,
|
||||
NoColor: true,
|
||||
Upgrade: true,
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue