mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-12-05 01:59:14 +00:00
fix: improve unknown certificate error in load_balancer_service
(#570)
##### SUMMARY Closes #563 ##### ISSUE TYPE - Bugfix Pull Request ##### COMPONENT NAME load_balancer_service
This commit is contained in:
parent
d9f49144bc
commit
fe3bfa9020
3 changed files with 28 additions and 10 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- hcloud_load_balancer_service - Improve unknown certificate id or name error.
|
|
@ -282,6 +282,7 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
from ..module_utils.hcloud import AnsibleHCloud
|
from ..module_utils.hcloud import AnsibleHCloud
|
||||||
from ..module_utils.vendor.hcloud import APIException, HCloudException
|
from ..module_utils.vendor.hcloud import APIException, HCloudException
|
||||||
|
from ..module_utils.vendor.hcloud.certificates import BoundCertificate
|
||||||
from ..module_utils.vendor.hcloud.load_balancers import (
|
from ..module_utils.vendor.hcloud.load_balancers import (
|
||||||
BoundLoadBalancer,
|
BoundLoadBalancer,
|
||||||
LoadBalancerHealtCheckHttp,
|
LoadBalancerHealtCheckHttp,
|
||||||
|
@ -389,16 +390,12 @@ class AnsibleHCloudLoadBalancerService(AnsibleHCloud):
|
||||||
if http_arg.get("certificates") is not None:
|
if http_arg.get("certificates") is not None:
|
||||||
certificates = http_arg.get("certificates")
|
certificates = http_arg.get("certificates")
|
||||||
if certificates is not None:
|
if certificates is not None:
|
||||||
for certificate in certificates:
|
for certificate_id_or_name in certificates:
|
||||||
hcloud_cert = None
|
certificate: BoundCertificate = self._client_get_by_name_or_id(
|
||||||
try:
|
"certificates",
|
||||||
try:
|
certificate_id_or_name,
|
||||||
hcloud_cert = self.client.certificates.get_by_name(certificate)
|
)
|
||||||
except Exception:
|
service_http.certificates.append(certificate)
|
||||||
hcloud_cert = self.client.certificates.get_by_id(certificate)
|
|
||||||
except HCloudException as exception:
|
|
||||||
self.fail_json_hcloud(exception)
|
|
||||||
service_http.certificates.append(hcloud_cert)
|
|
||||||
|
|
||||||
return service_http
|
return service_http
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,25 @@
|
||||||
- result is failed
|
- result is failed
|
||||||
- 'result.msg == "resource (load_balancer) does not exist: not-existing"'
|
- '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
|
- name: Test update
|
||||||
hetzner.hcloud.load_balancer_service:
|
hetzner.hcloud.load_balancer_service:
|
||||||
load_balancer: "{{ hcloud_load_balancer_name }}"
|
load_balancer: "{{ hcloud_load_balancer_name }}"
|
||||||
|
|
Loading…
Reference in a new issue