diff --git a/changelogs/fragments/query-hcloud_floating_ip_info-by-name.yml b/changelogs/fragments/query-hcloud_floating_ip_info-by-name.yml new file mode 100644 index 0000000..44d61f3 --- /dev/null +++ b/changelogs/fragments/query-hcloud_floating_ip_info-by-name.yml @@ -0,0 +1,2 @@ +minor_changes: + - hcloud_floating_ip_info - Allow querying floating ip by name. diff --git a/plugins/modules/hcloud_floating_ip_info.py b/plugins/modules/hcloud_floating_ip_info.py index 0cc120e..0d2fb78 100644 --- a/plugins/modules/hcloud_floating_ip_info.py +++ b/plugins/modules/hcloud_floating_ip_info.py @@ -22,6 +22,10 @@ options: - The ID of the Floating IP you want to get. - The module will fail if the provided ID is invalid. type: int + name: + description: + - The name for the Floating IP you want to get. + type: str label_selector: description: - The label selector for the Floating IP you want to get. @@ -133,6 +137,8 @@ class AnsibleHCloudFloatingIPInfo(AnsibleHCloud): try: if self.module.params.get("id") is not None: self.hcloud_floating_ip_info = [self.client.floating_ips.get_by_id(self.module.params.get("id"))] + elif self.module.params.get("name") is not None: + self.hcloud_floating_ip_info = [self.client.floating_ips.get_by_name(self.module.params.get("name"))] elif self.module.params.get("label_selector") is not None: self.hcloud_floating_ip_info = self.client.floating_ips.get_all( label_selector=self.module.params.get("label_selector") @@ -148,6 +154,7 @@ class AnsibleHCloudFloatingIPInfo(AnsibleHCloud): return AnsibleModule( argument_spec=dict( id={"type": "int"}, + name={"type": "str"}, label_selector={"type": "str"}, **super().base_module_arguments(), ), diff --git a/tests/integration/targets/hcloud_floating_ip_info/tasks/test.yml b/tests/integration/targets/hcloud_floating_ip_info/tasks/test.yml index de9fedf..3f31d6d 100644 --- a/tests/integration/targets/hcloud_floating_ip_info/tasks/test.yml +++ b/tests/integration/targets/hcloud_floating_ip_info/tasks/test.yml @@ -37,23 +37,23 @@ that: - result is failed -# - name: Gather hcloud_floating_ip_info with correct name -# hetzner.hcloud.hcloud_floating_ip_info: -# name: "{{ hcloud_floating_ip_name }}" -# register: result -# - name: Verify hcloud_floating_ip_info with correct name -# ansible.builtin.assert: -# that: -# - result.hcloud_floating_ip_info | list | count == 1 +- name: Gather hcloud_floating_ip_info with correct name + hetzner.hcloud.hcloud_floating_ip_info: + name: "{{ hcloud_floating_ip_name }}" + register: result +- name: Verify hcloud_floating_ip_info with correct name + ansible.builtin.assert: + that: + - result.hcloud_floating_ip_info | list | count == 1 -# - name: Gather hcloud_floating_ip_info with wrong name -# hetzner.hcloud.hcloud_floating_ip_info: -# name: "{{ hcloud_floating_ip_name }}-invalid" -# register: result -# - name: Verify hcloud_floating_ip_info with wrong name -# ansible.builtin.assert: -# that: -# - result.hcloud_floating_ip_info | list | count == 0 +- name: Gather hcloud_floating_ip_info with wrong name + hetzner.hcloud.hcloud_floating_ip_info: + name: "{{ hcloud_floating_ip_name }}-invalid" + register: result +- name: Verify hcloud_floating_ip_info with wrong name + ansible.builtin.assert: + that: + - result.hcloud_floating_ip_info | list | count == 0 - name: Gather hcloud_floating_ip_info with correct label selector hetzner.hcloud.hcloud_floating_ip_info: