-
Notifications
You must be signed in to change notification settings - Fork 19
/
teardown_resources_instances_terraform.yml
73 lines (60 loc) · 2.29 KB
/
teardown_resources_instances_terraform.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
- name: Teardown AWS infrastructure via Terraform
hosts: localhost
gather_facts: no
vars_files:
- ./vars/default-vars.yml
tasks:
- name: Teardown GCP infrastructure via Terraform
block:
- name: Ensure GCP Terraform Directory Exists
stat:
path: /tmp/gcp_deploy
register: gcp_deploy_directory
- name: Teardown GCP infrastructure via Terraform
terraform:
project_path: /tmp/gcp_deploy
variables:
gcp_key: '{{ lookup("env", "GCE_CREDENTIALS_FILE_PATH") }}'
state: absent
register: terraform_output
when: gcp_deploy_directory.stat.exists and gcp_deploy_directory.stat.isdir
no_log: true
- name: Debug Terraform output
debug:
var: terraform_output
when: gcp_deploy_directory.stat.exists and gcp_deploy_directory.stat.isdir
- name: delete terraform directory
file:
path: /tmp/gcp_deploy
state: absent
when: gcp_deploy_directory.stat.exists and gcp_deploy_directory.stat.isdir
when: cloud_provider == "gcp"
- name: Teardown AWS infrastructure via Terraform
block:
- name: Ensure AWS Terraform Directory Exists
stat:
path: /tmp/aws_deploy
register: aws_deploy_directory
- name: Teardown AWS infrastructure via Terraform
terraform:
variables:
ec2_region: "{{ ec2_region }}"
ec2_prefix: "{{ ec2_prefix }}"
access_key: '{{ lookup("env", "AWS_ACCESS_KEY_ID") }}'
secret_key: '{{ lookup("env", "AWS_SECRET_ACCESS_KEY") }}'
project_path: /tmp/aws_deploy
state: absent
register: terraform_output
when: aws_deploy_directory.stat.exists and aws_deploy_directory.stat.isdir
no_log: true
- name: Debug Terraform output
debug:
var: terraform_output
when: aws_deploy_directory.stat.exists and aws_deploy_directory.stat.isdir
- name: delete terraform directory
file:
path: /tmp/aws_deploy
state: absent
when: aws_deploy_directory.stat.exists and aws_deploy_directory.stat.isdir
when: cloud_provider == "aws"