- name: Delete IKS cluster karpenter and cas
  ibm.cloudcollection.ibm_container_vpc_cluster:
    ibmcloud_api_key: "{{ IBM_CLOUD_TOKEN }}"
    name: "{{ item }}"
    vpc_id: "{{ VPC_ID }}"
    flavor: "bx2.2x8" 
    zones:
      - name: us-south-1
        subnet_id: "{{ SUBNET_ID.US_SOUTH_1 }}"
      - name: us-south-2
        subnet_id: "{{ SUBNET_ID.US_SOUTH_2 }}"
      - name: us-south-3
        subnet_id: "{{ SUBNET_ID.US_SOUTH_3 }}"
    force_delete_storage: true
    state: absent
  loop:
    - karpenter
    - cas

- name: Delete EKS cluster karpenter and cas
  community.general.terraform:
    project_path: "{{ playbook_dir }}/../terraform-eks"
    state: absent
    complex_vars: true
    variables:
      tag_uuid: "{{ tag_uuid }}"
      aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}"
      aws_access_key: "{{ AWS_ACCESS_KEY_ID }}"
      flavour: "m5.large"
      kube_version: "1.29" # EKS only uspports major.minor
      worker_count: 1
      worker_pool_count: 3

- name: Delete all files in kubeconfig directories
  ansible.builtin.file:
    path: "{{ playbook_dir }}/files/{{ item }}"
    state: absent
  loop:
    - kubeconfig-iks-cas
    - kubeconfig-iks-karpenter
    - kubeconfig-eks-cas
    - kubeconfig-eks-karpenter

- name: Recreate kubeconfig directories
  ansible.builtin.file:
    path: "{{ playbook_dir }}/files/{{ item }}"
    state: directory
    mode: '0755'
  loop:
    - kubeconfig-iks-cas
    - kubeconfig-iks-karpenter
    - kubeconfig-eks-cas
    - kubeconfig-eks-karpenter
