Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when tofu with version used #71

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@Service
public class OpenTofuDirectoryService {

private static final String STATE_FILE_NAME = "openTofu.tfstate";
private static final String STATE_FILE_NAME = "terraform.tfstate";
private static final String TEST_FILE_NAME = "hello-world.tf";
private static final String HEALTH_CHECK_DIR = UUID.randomUUID().toString();
private static final List<String> EXCLUDED_FILE_SUFFIX_LIST =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public boolean checkIfExecutorIsMatchedRequiredVersion(File executorFile,
* @return If true, the executor can be executed, otherwise return false.
*/
public boolean checkIfExecutorCanBeExecuted(File executorFile) {
String versionOutput = getVersionCommandOutput(executorFile);
String versionOutput = getVersionCommandOutput(executorFile.getAbsolutePath());
return StringUtils.isNotBlank(versionOutput);
}

Expand All @@ -191,7 +191,7 @@ public boolean checkIfExecutorCanBeExecuted(File executorFile) {
* @return exact version of executor.
*/
public String getExactVersionOfExecutor(String executorPath) {
String versionOutput = getVersionCommandOutput(new File(executorPath));
String versionOutput = getVersionCommandOutput(executorPath);
Matcher matcher = OPENTOFU_VERSION_OUTPUT_PATTERN.matcher(versionOutput);
if (matcher.find()) {
// return only the version number.
Expand All @@ -201,12 +201,10 @@ public String getExactVersionOfExecutor(String executorPath) {
}


private String getVersionCommandOutput(File executorFile) {
private String getVersionCommandOutput(String executorPath) {
try {
if (!executorFile.exists() && !executorFile.isFile()) {
return null;
}
if (!executorFile.canExecute()) {
File executorFile = new File(executorPath);
if (executorFile.exists() && !executorFile.canExecute()) {
SystemCmdResult chmodResult = systemCmd.execute(
String.format("chmod +x %s", executorFile.getAbsolutePath()),
5, System.getProperty("java.io.tmpdir"), false, new HashMap<>());
Expand All @@ -215,18 +213,20 @@ private String getVersionCommandOutput(File executorFile) {
}
}
SystemCmdResult versionCheckResult =
systemCmd.execute(executorFile.getAbsolutePath() + " version",
systemCmd.execute(executorPath + " version",
5, System.getProperty("java.io.tmpdir"), false, new HashMap<>());
if (versionCheckResult.isCommandSuccessful()) {
log.info("Get version of executor {} output: {}", executorPath,
versionCheckResult.getCommandStdOutput());
return versionCheckResult.getCommandStdOutput();
} else {
log.error(versionCheckResult.getCommandStdError());
return null;
log.error("Get version of executor {} output error: {}", executorPath,
versionCheckResult.getCommandStdError());
}
} catch (Exception e) {
log.error("Failed to get version of executor {}.", executorFile.getAbsolutePath(), e);
return null;
log.error("Failed to get version of executor {}.", executorPath, e);
}
return null;
}


Expand Down
Loading