- name: Prepare facts
  set_fact:
    linux_plan_resource_group: "{{ resource_group_secondary }}"
    win_plan_name: "{{ (resource_prefix | replace('-','x'))[-8:] }}winplan"
    linux_plan_name: "{{ (resource_prefix | replace('-','x'))[-8:] }}linplan"

- name: create a windows plan
  azure_rm_appserviceplan:
    name: "{{ win_plan_name }}1"
    resource_group: "{{ resource_group }}"
    sku: B1
  register: output

- name: assert app service was created
  assert:
    that: 
      - output.changed
      - output.id

- name: create a linux plan
  azure_rm_appserviceplan:
    resource_group: "{{ linux_plan_resource_group }}"
    name: "{{ linux_plan_name }}1"
    sku: S1
    is_linux: true
    number_of_workers: 1
  register: output

- name: assert app service was created
  assert:
    that: 
      - output.changed
      - output.id

- name: get app service plan by name
  azure_rm_appserviceplan_info:
    resource_group: "{{ linux_plan_resource_group }}"
    name: "{{ linux_plan_name }}1"
  register: output

- name: assert is_linux is True
  assert:
    that:
      - output.appserviceplans | length == 1
      - output.appserviceplans[0].is_linux == True

- name: create linux app service plan idempotent
  azure_rm_appserviceplan:
    resource_group: "{{ linux_plan_resource_group }}"
    name: "{{ linux_plan_name }}1"
    sku: S1
    is_linux: true
    number_of_workers: 1
  register: output

- name: assert app service was created
  assert:
    that: not output.changed

- name: update a windows plan sku
  azure_rm_appserviceplan:
    name: "{{ win_plan_name }}1"
    resource_group: "{{ resource_group }}"
    sku: B2
  register: output

- name: assert app service was updated
  assert:
    that:
      - output.changed

- name: update a linux plan number of workers
  azure_rm_appserviceplan:
    resource_group: "{{ linux_plan_resource_group }}"
    name: "{{ linux_plan_name }}1"
    sku: S1
    is_linux: true
    number_of_workers: 2
  register: output

- name: assert app service was updated
  assert:
    that:
      - output.changed
