---
- name: 'ecs_cluster integration tests'
  collections:
    - amazon.aws
  module_defaults:
    group/aws:
      aws_access_key: '{{ aws_access_key }}'
      aws_secret_key: '{{ aws_secret_key }}'
      security_token: '{{ security_token | default(omit) }}'
      region: '{{ aws_region }}'
  block:

    - set_fact:
        virtualenv: "{{ remote_tmp_dir }}/virtualenv"
        virtualenv_command: "{{ ansible_python_interpreter }} -m virtualenv"

    - set_fact:
        virtualenv_interpreter: "{{ virtualenv }}/bin/python"

    - pip:
        name: virtualenv

    # Test graceful failures when botocore<1.8.4

    - pip:
        name:
          - 'botocore<1.8.4'
          - boto3
          - coverage<5
        virtualenv: "{{ virtualenv }}"
        virtualenv_command: "{{ virtualenv_command }}"
        virtualenv_site_packages: no

    - include_tasks: network_assign_public_ip_fail.yml
      vars:
        ansible_python_interpreter: "{{ virtualenv_interpreter }}"

    - include_tasks: network_force_new_deployment_fail.yml
      vars:
        ansible_python_interpreter: "{{ virtualenv_interpreter }}"

    - file:
        path: "{{ virtualenv }}"
        state: absent

    # Test graceful failures when botocore<1.12.38

    - pip:
        name:
          - 'botocore>=1.12.60'
          - 'boto3>=1.16.57'
          - coverage<5
        virtualenv: "{{ virtualenv }}"
        virtualenv_command: "{{ virtualenv_command }}"
        virtualenv_site_packages: no

    - include_tasks: network_force_new_deployment.yml
      vars:
        ansible_python_interpreter: "{{ virtualenv_interpreter }}"

    - include_tasks: full_test.yml
      vars:
        ansible_python_interpreter: "{{ virtualenv_interpreter }}"

    - file:
        path: "{{ virtualenv }}"
        state: absent
