zuul-jobs/test-playbooks/terraform/test-terraform-role.yaml
Albin Vass 7ef4d9f3f5 Allow deleting workspace after running terraform destroy
Also fixes a bug where the workspace was created from the wrong directory.

Change-Id: I28b54b9aa57a3f449254574956701ee663618e8b
2020-07-01 13:25:39 +02:00

41 lines
1.3 KiB
YAML

- hosts: all
tasks:
- name: Create workspace
include_role:
name: terraform
vars:
zuul_work_dir: '{{ zuul.project.src_dir }}/test-playbooks/terraform'
terraform_command: plan
terraform_create_workspace: true
- name: Make sure workspace was created
command: "{{ terraform_executable }} workspace select -no-color {{ terraform_workspace }}"
args:
chdir: "{{ zuul.project.src_dir }}/test-playbooks/terraform"
- name: Select default workspace
command: "{{ terraform_executable }} workspace select default"
args:
chdir: "{{ zuul.project.src_dir }}/test-playbooks/terraform"
- name: Use created workspace
include_role:
name: terraform
vars:
terraform_command: apply
- name: Delete workspace
include_role:
name: terraform
vars:
zuul_work_dir: '{{ zuul.project.src_dir }}/test-playbooks/terraform'
terraform_command: destroy
terraform_purge_workspace: true
- name: Make sure workspace was removed
register: terraform_workspace_stat
failed_when: terraform_workspace_stat.rc == 0
command: "{{ terraform_executable }} workspace select -no-color {{ terraform_workspace }}"
args:
chdir: "{{ zuul.project.src_dir }}/test-playbooks/terraform"