mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Terraform: ensure workspace is reset to current value (#2634)
* fix: ensure workspace is reset to current value * chore: linter * chore: changelog
This commit is contained in:
parent
a343756e6f
commit
c49a384a65
2 changed files with 10 additions and 1 deletions
2
changelogs/fragments/2634-terraform-switch-workspace.yml
Normal file
2
changelogs/fragments/2634-terraform-switch-workspace.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- terraform - ensure the workspace is set back to its previous value when the apply fails (https://github.com/ansible-collections/community.general/pull/2634).
|
|
@ -447,7 +447,14 @@ def main():
|
|||
command.append(plan_file)
|
||||
|
||||
if needs_application and not module.check_mode and not state == 'planned':
|
||||
rc, out, err = module.run_command(command, check_rc=True, cwd=project_path)
|
||||
rc, out, err = module.run_command(command, check_rc=False, cwd=project_path)
|
||||
if rc != 0:
|
||||
if workspace_ctx["current"] != workspace:
|
||||
select_workspace(command[0], project_path, workspace_ctx["current"])
|
||||
module.fail_json(msg=err.rstrip(), rc=rc, stdout=out,
|
||||
stdout_lines=out.splitlines(), stderr=err,
|
||||
stderr_lines=err.splitlines(),
|
||||
cmd=' '.join(command))
|
||||
# checks out to decide if changes were made during execution
|
||||
if ' 0 added, 0 changed' not in out and not state == "absent" or ' 0 destroyed' not in out:
|
||||
changed = True
|
||||
|
|
Loading…
Reference in a new issue