diff --git a/changelogs/fragments/lb-allow-change-type.yml b/changelogs/fragments/lb-allow-change-type.yml new file mode 100644 index 0000000..5c7aa2a --- /dev/null +++ b/changelogs/fragments/lb-allow-change-type.yml @@ -0,0 +1,2 @@ +minor_changes: + - hcloud_load_balancer Allow changing the type of a Load Balancer diff --git a/plugins/modules/hcloud_load_balancer.py b/plugins/modules/hcloud_load_balancer.py index 4ece8b3..ce4b48a 100644 --- a/plugins/modules/hcloud_load_balancer.py +++ b/plugins/modules/hcloud_load_balancer.py @@ -243,6 +243,18 @@ class AnsibleHcloudLoadBalancer(Hcloud): else: self.hcloud_load_balancer.enable_public_interface().wait_until_finished() self._mark_as_changed() + + load_balancer_type = self.module.params.get("load_balancer_type") + if load_balancer_type is not None and self.hcloud_load_balancer.load_balancer_type.name != load_balancer_type: + new_load_balancer_type = self.client.server_types.get_by_name(load_balancer_type) + if not new_load_balancer_type: + self.module.fail_json(msg="unknown load balancer type") + if not self.module.check_mode: + self.hcloud_load_balancer.change_type( + load_balancer_type=new_load_balancer_type, + ).wait_until_finished(max_retries=1000) + + self._mark_as_changed() self._get_load_balancer() except APIException as e: self.module.fail_json(msg=e.message) diff --git a/tests/integration/targets/hcloud_load_balancer/tasks/main.yml b/tests/integration/targets/hcloud_load_balancer/tasks/main.yml index ec555c9..99386b6 100644 --- a/tests/integration/targets/hcloud_load_balancer/tasks/main.yml +++ b/tests/integration/targets/hcloud_load_balancer/tasks/main.yml @@ -60,6 +60,29 @@ that: - result is not changed +- name: test change Load Balancer type + hcloud_load_balancer: + name: "{{ hcloud_load_balancer_name }}" + load_balancer_type: lb21 + state: present + register: result_after_test + ignore_errors: true +- name: verify change Load Balancer type + assert: + that: + - result_after_test is changed + - result_after_test.hcloud_load_balancer.load_balancer_type == "lb21" + +- name: test Load Balancer without type set to be idempotent + hcloud_load_balancer: + name: "{{hcloud_load_balancer_name}}" + register: result_after_test +- name: verify test Load Balancer without type set to be idempotent + assert: + that: + - result_after_test is not changed + - result_after_test.hcloud_load_balancer.load_balancer_type == "lb21" + - name: test update Load Balancer protection hcloud_load_balancer: name: "{{ hcloud_load_balancer_name }}" diff --git a/tests/integration/targets/hcloud_server_network/aliases b/tests/integration/targets/hcloud_server_network/aliases index 55ec821..7f17468 100644 --- a/tests/integration/targets/hcloud_server_network/aliases +++ b/tests/integration/targets/hcloud_server_network/aliases @@ -1,2 +1,3 @@ cloud/hcloud shippable/hcloud/group2 +disabled