- block:

  - name: set connection information for all tasks
    set_fact:
      aws_connection_info: &aws_connection_info
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
        security_token: "{{ security_token }}"
        region: "{{ aws_region }}"
    no_log: yes

  - name: create NLB with a listener
    elb_network_lb:
      name: "{{ nlb_name }}"
      subnets: "{{ nlb_subnets }}"
      state: present
      listeners:
        - Protocol: TCP
          Port: 80
          DefaultActions:
            - Type: forward
              TargetGroupName: "{{ tg_name }}"
      <<: *aws_connection_info
    register: nlb

  - assert:
      that:
        - nlb.changed
        - nlb.listeners|length == 1

  - name: test idempotence creating NLB with a listener
    elb_network_lb:
      name: "{{ nlb_name }}"
      subnets: "{{ nlb_subnets }}"
      state: present
      listeners:
        - Protocol: TCP
          Port: 80
          DefaultActions:
            - Type: forward
              TargetGroupName: "{{ tg_name }}"
      <<: *aws_connection_info
    register: nlb

  - assert:
      that:
        - not nlb.changed
        - nlb.listeners|length == 1
