# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


- name: Prompt reminding about tags
  debug:
    msg: "IF you are trying to run this and do not see any progress, perhaps you forgot the '--tags never'"
  tags:
    - abm-remove

- name: "Remove the ABM installation (cluster removal only)"
  command:
    cmd: bmctl reset -c {{ cluster_name }}
  args:
    chdir: "{{ abm_install_folder }}"
  when:
    - primary_cluster_machine is defined
    - primary_cluster_machine == True
  environment:
    KUBECONFIG: "{{ kubeconfig_shared_location }}"
    GOOGLE_APPLICATION_CREDENTIALS: "/var/keys/gsa-key.json"
  tags:
    - abm-remove
    - never # must specify `--tags never` on the CLI to run this

- name: Remove install folder (bmctl_workspace)
  ansible.builtin.file:
    path: "{{ abm_workspace_folder }}"
    state: absent
  tags:
    - abm-remove
    - never # must specify `--tags never` on the CLI to run this

- name: Remove ACM Config files
  ansible.builtin.file:
    path: "{{ acm_config_files }}"
    state: absent
  tags:
    - abm-remove
    - never # must specify `--tags never` on the CLI to run this

- name: Remove kubeconfig folder
  ansible.builtin.file:
    path: "{{ kubeconfig_shared_root }}"
    state: absent
  tags:
  - abm-remove
  - kubeconfig-remove
  - never

- name: Archive current cluster snapshots
  include: remove-snapshot.yaml
  when:
    - (primary_cluster_machine is defined)
    - (primary_cluster_machine == true)
  tags:
    - snapshot-remove
    - never # must specify `--tags never` on the CLI to run this

- name: Remove ABM Workspace
  ansible.builtin.file:
    path: "{{ abm_install_folder }}/bmctl-workspace"
    state: absent
  tags:
    - abm-remove
    - never # must specify `--tags never` on the CLI to run this
