1
0
Fork 0
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) (#2720)

* 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:
patchback[bot] 2021-06-04 21:12:53 +02:00 committed by GitHub
parent 4b07d45b7e
commit eb4d7a4199
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View 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).

View file

@ -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