Vince Power
2020-03-13 db6af5c6a60e5f02e0a831aac21e73901f8dbba3
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
74
75
76
77
78
79
80
81
82
---
- name: Find managed_zone
  gcp_dns_managed_zone_facts:
    dns_name: '{{ cluster_dns_zone + "."}}'
    project: "{{ gcp_project_id }}"
    auth_kind: "{{ gcp_auth_type }}"
    service_account_file: "{{ gcp_credentials_file }}"
  register: gcp_managed_zone
  when:
    - HostedZoneId != "none"
  tags:
    - destroying
    - destroy_cloud_deployment
    - destroy_gcp_deployment
    
- name: Remove delegation for NS from the main DNSZone
  gcp_dns_resource_record_set:
    project: "{{ gcp_project_id }}"
    auth_kind: "{{ gcp_auth_type }}"
    service_account_file: "{{ gcp_credentials_file }}"
    managed_zone: "{{ gcp_managed_zone.resources[0] }}"
    name: '{{ guid + "." + cluster_dns_zone + "."}}'
    type: NS
    state: absent
  when:
    - HostedZoneId != "none"
  tags:
    - destroying
    - destroy_cloud_deployment
    - destroy_gcp_deployment
 
- name: Remove bastion entry from the main DNSZone
  gcp_dns_resource_record_set:
    project: "{{ gcp_project_id }}"
    auth_kind: "{{ gcp_auth_type }}"
    service_account_file: "{{ gcp_credentials_file }}"
    managed_zone: "{{ gcp_managed_zone.resources[0] }}"
    name: '{{ "bastion." + guid + "." + cluster_dns_zone + "."}}'
    type: A
    state: absent
  when:
    - HostedZoneId != "none"
  tags:
    - destroying
    - destroy_cloud_deployment
    - destroy_gcp_deployment
 
- name: Destroy method deployment-manager
  block:
    - name: Delete the deployment
      command: "gcloud deployment-manager deployments delete {{ project_tag }}-base -q"
      environment:
        CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: "{{ gcp_credentials_file }}"
        CLOUDSDK_COMPUTE_REGION: "{{ gcp_region }}"
        CLOUDSDK_CONFIG: "{{ output_dir }}/.gcloud-{{ guid }}"
        CLOUDSDK_CORE_PROJECT: "{{ gcp_project_id }}"
      tags:
        - destroying
        - destroy_cloud_deployment
        - destroy_gcp_deployment
      register: gcp_result
      until: gcp_result is succeeded
      retries: 6
      delay: 10
      ignore_errors: yes
      when:
        - cloud_provider == "gcp"
      tags:
        - destroying
        - destroy_cloud_deployment
        - destroy_gcp_deployment
 
    - name: report error
      fail:
        msg: "FAIL {{ gcp_project_id }} GCP delete deployment"
      when:
        - gcp_result is failed
        - cloud_provider == "gcp"
      tags:
        - destroying
        - destroy_cloud_deployment
        - destroy_gcp_deployment