### Question:
TerraformTask implements Task { 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 = getPath(cfg, com.walmartlabs.concord.sdk.Constants.Context.WORK_DIR_KEY, null); if (workDir == null) { throw new IllegalArgumentException("Can't determine the current '" + com.walmartlabs.concord.sdk.Constants.Context.WORK_DIR_KEY + "'"); } boolean debug = MapUtils.get(cfg, TaskConstants.DEBUG_KEY, false, Boolean.class); Action action = getAction(cfg); Backend backend = new BackendFactoryV1(ctx, lockService, objectStorage).getBackend(cfg); Map<String, String> env = getEnv(cfg, backend); 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<>()); 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, cfg, env); ctx.setVariable(TaskConstants.RESULT_KEY, objectMapper.convertValue(result, Map.class)); } finally { gitSshWrapper.cleanup(); } } @Inject  TerraformTask(SecretService secretService, LockService lockService, ObjectStorage objectStorage, DependencyManager dependencyManager); void execute(Context ctx);  }### Answer:
@Test @SuppressWarnings("unchecked") public void test() throws Exception { Map<String, Object> args = baseArguments(workDir, dstDir, Action.PLAN.name()); args.put(TaskConstants.VARS_FILES, varFiles()); args.put(TaskConstants.EXTRA_VARS_KEY, extraVars()); args.put(TaskConstants.GIT_SSH_KEY, gitSsh()); Context ctx = new MockContext(args); backendManager = new BackendFactoryV1(ctx, lockService, objectStorage); TerraformTask t = new TerraformTask(secretService, lockService, objectStorage, dependencyManager); t.execute(ctx); Map<String, Object> result = (Map<String, Object>) ctx.getVariable(TaskConstants.RESULT_KEY); assertTrue((boolean) result.get("ok")); assertNotNull(result.get("planPath")); verify(lockService, times(1)).projectLock(any(), any()); verify(lockService, times(1)).projectUnlock(any(), any()); System.out.println("==================================================================================="); args = baseArguments(workDir, dstDir, Action.APPLY.name()); args.put(TaskConstants.DESTROY_KEY, true); args.put(TaskConstants.PLAN_KEY, result.get("planPath")); ctx = new MockContext(args); t.execute(ctx); result = (Map<String, Object>) ctx.getVariable(TaskConstants.RESULT_KEY); System.out.println(result); assertTrue(((String) result.get("output")).contains("name_from_varfile0 = bob")); assertTrue(((String) result.get("output")).contains("time_from_varfile1 = now")); System.out.println("==================================================================================="); String terraformStateWithOutputs = responseTemplate("terraform.tfstate"); wireMockRule.stubFor(get("/test").willReturn(aResponse().withBody(terraformStateWithOutputs).withStatus(200))); args = baseArguments(workDir, dstDir, Action.OUTPUT.name()); ctx = new MockContext(args); t.execute(ctx); }