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