Skip to content

Commit

Permalink
remove duplicate error
Browse files Browse the repository at this point in the history
  • Loading branch information
c4po committed Apr 2, 2024
1 parent c86c152 commit 932768b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/wrapper/checkargs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package wrapper

import (
"errors"
"fmt"
"os"
"strings"

Expand All @@ -14,12 +14,16 @@ func checkStateCommand(args []string, version *semver.Version) error {
versionRemoved, _ := semver.NewConstraint(">= 1.7.0")
STATE_COMMAND_VAR := "TF_DEMUX_ALLOW_STATE_COMMANDS"

errorMsg := func(command string, suggestion string) error {
return fmt.Errorf("need to set %s=true for the '%s' command. Consider using Terraform configuration %s block instead", STATE_COMMAND_VAR, command, suggestion)
}

if checkArgsExists(args, "import") >= 0 &&
versionImport.Check(version) {
if allowStateCommand(STATE_COMMAND_VAR) {
return nil
} else {
return errors.New("need set TF_DEMUX_ALLOW_STATE_COMMANDS=true for the 'import' command. Consider using Terraform configuration import block instead")
return errorMsg("import", "import")
}
}

Expand All @@ -29,7 +33,7 @@ func checkStateCommand(args []string, version *semver.Version) error {
if allowStateCommand(STATE_COMMAND_VAR) {
return nil
} else {
return errors.New("need set TF_DEMUX_ALLOW_STATE_COMMANDS=true for the 'state mv' command. Consider using Terraform configuration moved block instead")
return errorMsg("state mv", "moved")
}
}

Expand All @@ -39,7 +43,7 @@ func checkStateCommand(args []string, version *semver.Version) error {
if allowStateCommand(STATE_COMMAND_VAR) {
return nil
} else {
return errors.New("need set TF_DEMUX_ALLOW_STATE_COMMANDS=true for the 'state rm' command. Consider using Terraform configuration removed block instead")
return errorMsg("state rm", "removed")
}
}

Expand Down

0 comments on commit 932768b

Please sign in to comment.