use of com.walmartlabs.concord.plugins.terraform.actions.TerraformActionResult in project concord-plugins by walmartlabs.
the class TerraformTask method execute.
public void execute(Context ctx) throws Exception {
String instanceId = (String) ctx.getVariable(com.walmartlabs.concord.sdk.Constants.Context.TX_ID_KEY);
Map<String, Object> cfg = createCfg(ctx);
Path workDir = ContextUtils.getWorkDir(ctx);
boolean debug = MapUtils.get(cfg, TaskConstants.DEBUG_KEY, false, Boolean.class);
Action action = getAction(cfg);
// configure the state backend and populate the environment with necessary parameters
Backend backend = new BackendFactoryV1(ctx, lockService, objectStorage).getBackend(cfg);
Map<String, String> env = getEnv(cfg, backend);
// configure the environment to support Terraform's git modules using Concord Secrets for authentication
GitSshWrapper.SecretProvider secretProvider = (orgName, secretName, password) -> {
Map<String, String> result = secretService.exportKeyAsFile(ctx, instanceId, workDir.toAbsolutePath().toString(), orgName, secretName, password);
return workDir.resolve(result.get("private"));
};
GitSshWrapper gitSshWrapper = GitSshWrapper.createFrom(secretProvider, workDir, cfg, debug);
Map<String, String> baseEnv = gitSshWrapper.updateEnv(workDir, new HashMap<>());
// configure the Terraform's binary
TerraformBinaryResolver binaryResolver = new TerraformBinaryResolver(cfg, workDir, debug, url -> dependencyManager.resolve(URI.create(url)));
Terraform terraform = new Terraform(binaryResolver, debug, baseEnv);
if (debug) {
terraform.exec(workDir, "version", "version");
}
try {
TerraformActionResult result = TerraformTaskCommon.execute(terraform, action, backend, workDir, cfg, env);
ctx.setVariable(TaskConstants.RESULT_KEY, objectMapper.convertValue(result, Map.class));
} finally {
gitSshWrapper.cleanup();
}
}
use of com.walmartlabs.concord.plugins.terraform.actions.TerraformActionResult in project concord-plugins by walmartlabs.
the class TerraformTaskV2 method execute.
@Override
public TaskResult execute(Variables input) throws Exception {
Path workDir = ctx.workingDirectory();
Map<String, Object> cfg = createCfg(workDir, input, ctx.defaultVariables());
boolean debug = MapUtils.get(cfg, TaskConstants.DEBUG_KEY, false, Boolean.class);
Action action = getAction(cfg);
// configure the state backend and populate the environment with necessary parameters
Backend backend = new BackendFactoryV2(ctx, apiClient, lockService).getBackend(cfg);
Map<String, String> env = getEnv(cfg, backend);
// configure the environment to support Terraform's git modules using Concord Secrets for authentication
GitSshWrapper.SecretProvider secretProvider = (orgName, secretName, password) -> {
SecretService.KeyPair result = secretService.exportKeyAsFile(orgName, secretName, password);
return result.privateKey();
};
GitSshWrapper gitSshWrapper = GitSshWrapper.createFrom(secretProvider, workDir, cfg, debug);
Map<String, String> baseEnv = gitSshWrapper.updateEnv(workDir, new HashMap<>());
// configure the Terraform's binary
TerraformBinaryResolver binaryResolver = new TerraformBinaryResolver(cfg, workDir, debug, url -> dependencyManager.resolve(URI.create(url)));
Terraform terraform = new Terraform(binaryResolver, debug, baseEnv);
if (debug) {
terraform.exec(workDir, "version", "version");
}
try {
TerraformActionResult result = TerraformTaskCommon.execute(terraform, action, backend, workDir, cfg, env);
return convertResult(result);
} finally {
gitSshWrapper.cleanup();
}
}
Aggregations