| 1 |
# Copyright: (c) 2020, Hetzner Cloud GmbH <[email protected]> |
| 2 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 |
--- |
| 4 |
- name: Test missing required parameters |
| 5 |
hetzner.hcloud.load_balancer: |
| 6 |
name: "{{ hcloud_load_balancer_name }}" |
| 7 |
state: present |
| 8 |
ignore_errors: true |
| 9 |
register: result |
| 10 |
- name: Verify missing required parameters |
| 11 |
ansible.builtin.assert: |
| 12 |
that: |
| 13 |
- result is failed |
| 14 |
- 'result.msg == "missing required arguments: load_balancer_type"' |
| 15 |
|
| 16 |
- name: Test create with check mode |
| 17 |
hetzner.hcloud.load_balancer: |
| 18 |
name: "{{ hcloud_load_balancer_name }}" |
| 19 |
load_balancer_type: lb11 |
| 20 |
network_zone: "{{ hcloud_network_zone_name }}" |
| 21 |
state: present |
| 22 |
check_mode: true |
| 23 |
register: result |
| 24 |
- name: Verify create with check mode |
| 25 |
ansible.builtin.assert: |
| 26 |
that: |
| 27 |
- result is changed |
| 28 |
|
| 29 |
- name: Test create |
| 30 |
hetzner.hcloud.load_balancer: |
| 31 |
name: "{{ hcloud_load_balancer_name }}" |
| 32 |
load_balancer_type: lb11 |
| 33 |
network_zone: "{{ hcloud_network_zone_name }}" |
| 34 |
labels: |
| 35 |
key: value |
| 36 |
label: value123 |
| 37 |
state: present |
| 38 |
register: result |
| 39 |
- name: Verify create |
| 40 |
ansible.builtin.assert: |
| 41 |
that: |
| 42 |
- result is changed |
| 43 |
- result.hcloud_load_balancer.name == hcloud_load_balancer_name |
| 44 |
- result.hcloud_load_balancer.load_balancer_type == "lb11" |
| 45 |
- result.hcloud_load_balancer.algorithm == "round_robin" |
| 46 |
- result.hcloud_load_balancer.labels.key == "value" |
| 47 |
- result.hcloud_load_balancer.labels.label == "value123" |
| 48 |
- result.hcloud_load_balancer.delete_protection == false |
| 49 |
|
| 50 |
- name: Test create idempotency |
| 51 |
hetzner.hcloud.load_balancer: |
| 52 |
name: "{{ hcloud_load_balancer_name }}" |
| 53 |
load_balancer_type: lb11 |
| 54 |
network_zone: "{{ hcloud_network_zone_name }}" |
| 55 |
state: present |
| 56 |
register: result |
| 57 |
- name: Verify create idempotency |
| 58 |
ansible.builtin.assert: |
| 59 |
that: |
| 60 |
- result is not changed |
| 61 |
|
| 62 |
- name: Test update algorithm |
| 63 |
hetzner.hcloud.load_balancer: |
| 64 |
name: "{{ hcloud_load_balancer_name }}" |
| 65 |
algorithm: least_connections |
| 66 |
state: present |
| 67 |
register: result |
| 68 |
- name: Verify update algorithm |
| 69 |
ansible.builtin.assert: |
| 70 |
that: |
| 71 |
- result is changed |
| 72 |
- result.hcloud_load_balancer.algorithm == "least_connections" |
| 73 |
|
| 74 |
- name: Test update load_balancer_type |
| 75 |
hetzner.hcloud.load_balancer: |
| 76 |
name: "{{ hcloud_load_balancer_name }}" |
| 77 |
load_balancer_type: lb21 |
| 78 |
state: present |
| 79 |
register: result |
| 80 |
- name: Verify update load_balancer_type |
| 81 |
ansible.builtin.assert: |
| 82 |
that: |
| 83 |
- result is changed |
| 84 |
- result.hcloud_load_balancer.load_balancer_type == "lb21" |
| 85 |
|
| 86 |
- name: Test update labels |
| 87 |
hetzner.hcloud.load_balancer: |
| 88 |
name: "{{ hcloud_load_balancer_name }}" |
| 89 |
labels: |
| 90 |
key: changed |
| 91 |
label: changed123 |
| 92 |
state: present |
| 93 |
register: result |
| 94 |
- name: Verify update load_balancer_type |
| 95 |
ansible.builtin.assert: |
| 96 |
that: |
| 97 |
- result is changed |
| 98 |
- result.hcloud_load_balancer.labels.key == "changed" |
| 99 |
- result.hcloud_load_balancer.labels.label == "changed123" |
| 100 |
|
| 101 |
- name: Test update delete_protection |
| 102 |
hetzner.hcloud.load_balancer: |
| 103 |
name: "{{ hcloud_load_balancer_name }}" |
| 104 |
delete_protection: true |
| 105 |
state: present |
| 106 |
register: result |
| 107 |
- name: Verify update load_balancer_type |
| 108 |
ansible.builtin.assert: |
| 109 |
that: |
| 110 |
- result is changed |
| 111 |
- result.hcloud_load_balancer.delete_protection == true |
| 112 |
|
| 113 |
- name: Test delete with protection |
| 114 |
hetzner.hcloud.load_balancer: |
| 115 |
name: "{{ hcloud_load_balancer_name }}" |
| 116 |
state: absent |
| 117 |
register: result |
| 118 |
ignore_errors: true |
| 119 |
- name: Verify delete with protection |
| 120 |
ansible.builtin.assert: |
| 121 |
that: |
| 122 |
- result is failed |
| 123 |
- result.failure.code == "protected" |
| 124 |
|
| 125 |
- name: Test update delete_protection |
| 126 |
hetzner.hcloud.load_balancer: |
| 127 |
name: "{{ hcloud_load_balancer_name }}" |
| 128 |
delete_protection: false |
| 129 |
state: present |
| 130 |
register: result |
| 131 |
- name: Verify update delete_protection |
| 132 |
ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- result is changed |
| 135 |
- result.hcloud_load_balancer.delete_protection == false |
| 136 |
|
| 137 |
- name: Test delete |
| 138 |
hetzner.hcloud.load_balancer: |
| 139 |
name: "{{ hcloud_load_balancer_name }}" |
| 140 |
state: absent |
| 141 |
register: result |
| 142 |
- name: Verify delete |
| 143 |
ansible.builtin.assert: |
| 144 |
that: |
| 145 |
- result is changed |