Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve unknown certificate error in load_balancer_service #570

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/improve-unkown-certificate-error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- hcloud_load_balancer_service - Improve unknown certificate id or name error.
17 changes: 7 additions & 10 deletions plugins/modules/load_balancer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@

from ..module_utils.hcloud import AnsibleHCloud
from ..module_utils.vendor.hcloud import APIException, HCloudException
from ..module_utils.vendor.hcloud.certificates import BoundCertificate
from ..module_utils.vendor.hcloud.load_balancers import (
BoundLoadBalancer,
LoadBalancerHealtCheckHttp,
Expand Down Expand Up @@ -389,16 +390,12 @@ def __get_service_http(self, http_arg):
if http_arg.get("certificates") is not None:
certificates = http_arg.get("certificates")
if certificates is not None:
for certificate in certificates:
hcloud_cert = None
try:
try:
hcloud_cert = self.client.certificates.get_by_name(certificate)
except Exception:
hcloud_cert = self.client.certificates.get_by_id(certificate)
except HCloudException as exception:
self.fail_json_hcloud(exception)
service_http.certificates.append(hcloud_cert)
for certificate_id_or_name in certificates:
certificate: BoundCertificate = self._client_get_by_name_or_id(
"certificates",
certificate_id_or_name,
)
service_http.certificates.append(certificate)

return service_http

Expand Down
19 changes: 19 additions & 0 deletions tests/integration/targets/load_balancer_service/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@
- result is failed
- 'result.msg == "resource (load_balancer) does not exist: not-existing"'

- name: Test create with not existing certificate
hetzner.hcloud.load_balancer_service:
load_balancer: "{{ hcloud_load_balancer_name }}"
listen_port: 443
destination_port: 80
protocol: https
http:
redirect_http: true
certificates:
- not-existing
state: present
ignore_errors: true
register: result
- name: Verify create with not existing certificate
ansible.builtin.assert:
that:
- result is failed
- 'result.msg == "resource (certificate) does not exist: not-existing"'

- name: Test update
hetzner.hcloud.load_balancer_service:
load_balancer: "{{ hcloud_load_balancer_name }}"
Expand Down