---
- name: setup
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: absent
  register: vpcoffer
- name: verify setup
  assert:
    that:
    - vpcoffer is successful

- name: test fail if missing name
  cs_vpc_offering:
  register: vpcoffer
  ignore_errors: true
- name: verify results of fail if missing name
  assert:
    that:
    - vpcoffer is failed
    - 'vpcoffer.msg == "missing required arguments: name"'

- name: test fail if missing params
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
  register: vpcoffer
  ignore_errors: true
- name: verify results of fail if missing params
  assert:
    that:
    - vpcoffer is failed
    - 'vpcoffer.msg == "missing required arguments: display_text, supported_services"'

- name: test create vpc offer in check mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
  register: vpcoffer
  check_mode: yes
- name: verify results of vpc offer in check mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed

- name: test create vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
  register: vpcoffer
- name: verify results of vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description"
    - vpcoffer.distributed == false
    - vpcoffer.region_level == false

- name: test create vpc offer idempotence
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
  register: vpcoffer
- name: verify results of create vpc offer idempotence
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description"
    - vpcoffer.distributed == false
    - vpcoffer.region_level == false

- name: test enabling existing vpc offer in check_mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: enabled
  register: vpcoffer
  check_mode: yes
- name: verify results of enabling existing vpc offer in check_mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test enabling existing vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: enabled
  register: vpcoffer
- name: verify results of enabling existing vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Enabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test enabling existing vpc offer idempotence
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: enabled
  register: vpcoffer
- name: verify results of enabling existing vpc idempotence
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Enabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test disabling vpc offer in check_mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: vpcoffer
  check_mode: yes
- name: verify results of disabling vpc offer in check_mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Enabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test disabling vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: vpcoffer
- name: verify results of disabling vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test disabling vpc offer idempotence
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: vpcoffer
- name: verify results of disabling vpc idempotence
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test rename vpc offer in check_mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description renamed"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: vpcoffer
  check_mode: yes
- name: verify results of rename vpc offer in check_mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test rename vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description renamed"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: vpcoffer
- name: verify results of rename vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description renamed"

- name: test rename vpc offer idempotence
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description renamed"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: disabled
  register: vpcoffer
- name: verify results of rename vpc offer idempotence
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description renamed"

- name: test update offer with minimal params in check_mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description update"
  register: vpcoffer
  check_mode: yes
- name: verify results of update offer with minimal params in check_mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description renamed"

- name: test update offer with minimal params
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description update"
  register: vpcoffer
- name: verify results of update offer with minimal params
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description update"

- name: test update offer with minimal params idempotency
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description update"
  register: vpcoffer
- name: verify results of update offer with minimal params idempotency
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description update"

- name: test remove vpc offer in check_mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: absent
  register: vpcoffer
  check_mode: yes
- name: verify results of rename vpc offer in check_mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Disabled"
    - vpcoffer.display_text == "vpc offering description update"

- name: test remove vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: absent
  register: vpcoffer
- name: verify results of rename vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed

- name: test remove vpc offer idempotence
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: absent
  register: vpcoffer
- name: verify results of rename vpc offer idempotence
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed

- name: test create enabled vpc offer in check mode
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
  register: vpcoffer
  check_mode: yes
- name: verify results of create enabled vpc offer in check mode
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed

- name: test create enabled vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
  register: vpcoffer
- name: verify results of create enabled vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Enabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test create enabled vpc offer idempotence
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
  register: vpcoffer
- name: verify results of create enabled vpc offer idempotence
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is not changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc"
    - vpcoffer.state == "Enabled"
    - vpcoffer.display_text == "vpc offering description"

- name: test create enabled region level vpc offer with distrubuted router
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc_drl"
    display_text: "vpc offering description"
    supported_services: [ Dns, PortForwarding, Dhcp, SourceNat, UserData, StaticNat, Vpn, Lb ]
    service_providers:
      - { service: 'dns', provider: 'virtualrouter' }
      - { service: 'dhcp', provider: 'virtualrouter' }
    state: enabled
    service_capabilities:
      - {service: 'Connectivity', capabilitytype: 'DistributedRouter', capabilityvalue: true}
      - {service: 'Connectivity', capabilitytype: 'RegionLevelVPC', capabilityvalue: true}
  register: vpcoffer
- name: verify results of create enabled region level vpc offer with distrubuted router
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
    - vpcoffer.name == "{{ cs_resource_prefix }}_vpc_drl"
    - vpcoffer.state == "Enabled"
    - vpcoffer.display_text == "vpc offering description"
    - vpcoffer.distributed == true
    - vpcoffer.region_level == true

- name: remove vpc offer
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc"
    state: absent
  register: vpcoffer
- name: verify results of remove vpc offer
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed

- name: remove region level vpc offer with distrubuted router
  cs_vpc_offering:
    name: "{{ cs_resource_prefix }}_vpc_drl"
    state: absent
  register: vpcoffer
- name: verify results of remove region level vpc offer with distrubuted router
  assert:
    that:
    - vpcoffer is successful
    - vpcoffer is changed
