mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* fix: ensure workspace is reset to current value
* chore: linter
* chore: changelog
(cherry picked from commit c49a384a65
)
Co-authored-by: christophemorio <49184206+christophemorio@users.noreply.github.com>
This commit is contained in:
parent
4b07d45b7e
commit
eb4d7a4199
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)
|
command.append(plan_file)
|
||||||
|
|
||||||
if needs_application and not module.check_mode and not state == 'planned':
|
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
|
# 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:
|
if ' 0 added, 0 changed' not in out and not state == "absent" or ' 0 destroyed' not in out:
|
||||||
changed = True
|
changed = True
|
||||||
|
|
Loading…
Reference in a new issue