- name: Retrieve AWS billing metrics for resources with specific tags
  vars:
    output_file: "ibm_billing_metrics.json"
    tag_key: "tag"
    tag_value: "{{ item }}-{{ tag_uuid }}"
  loop:
    - karpenter
    - cas
  block:
    - name: Retrieve billing data using custom python script
      ansible.builtin.command:
        cmd: python3 fetch_billing_data_ibm.py --tag_key '{{ tag_key }}' --tag_value '{{ tag_value }}'
      register: billing_data

    - name: Write billing data to file
      ansible.builtin.copy:
        content: "{{ billing_data.stdout }}"
        dest: "{{ output_file | replace('.json', '-'+item+'.json') }}"
      when: billing_data is defined  
