diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index a11eb04..d40da1e 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -110,13 +110,10 @@ func listTerraformStateResources(terraformDir string, environment []string) ([]s return strings.Fields(string(state)), nil } +var ansiEscapeSequence = regexp.MustCompile(`\x1b\[[0-?]*[ -/]*[@-~]`) + func terraformNoStateFile(stderr []byte) bool { - for _, line := range strings.Split(string(stderr), "\n") { - if strings.TrimSpace(line) == "No state file was found!" { - return true - } - } - return false + return strings.Contains(strings.ToLower(ansiEscapeSequence.ReplaceAllString(string(stderr), "")), "no state file") } var destroyTalosVMs = func(terraformDir string, environment []string) error { diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go index 1c8b72e..e6df307 100644 --- a/internal/bootstrap/bootstrap_test.go +++ b/internal/bootstrap/bootstrap_test.go @@ -911,11 +911,11 @@ func TestTerraformPlanPathIsAbsolute(t *testing.T) { } } -func TestTerraformStateResourcesAllowsNoStateFile(t *testing.T) { +func TestTerraformStateResourcesAllowsANSINoStateFile(t *testing.T) { original := runTerraformStateList t.Cleanup(func() { runTerraformStateList = original }) runTerraformStateList = func(string, []string) ([]byte, []byte, error) { - return nil, []byte("No state file was found!\n"), errors.New("exit status 1") + return nil, []byte("\x1b[31mError:\x1b[0m \x1b[31mNO STATE\x1b[0m FILE was found!\n"), errors.New("exit status 1") } resources, err := listTerraformStateResources("terraform", nil)