From 32cec4523e9a6a23bb1440e17a7932c2011e4899 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 19 Dec 2025 18:36:05 +0100 Subject: [PATCH] fix: add backward compatible datacenter name handling --- plugins/modules/primary_ip.py | 5 ++++- plugins/modules/server.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/modules/primary_ip.py b/plugins/modules/primary_ip.py index 70d64f8..11a92f3 100644 --- a/plugins/modules/primary_ip.py +++ b/plugins/modules/primary_ip.py @@ -231,7 +231,10 @@ class AnsiblePrimaryIP(AnsibleHCloud): "after 1 July 2026. Please use the `location` argument instead. " "See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters." ) - params["datacenter"] = self.client.datacenters.get_by_name(value) + # Backward compatible datacenter argument. + # datacenter hel1-dc2 => location hel1 + part1, _, _ = str(value).partition("-") + params["location"] = self.client.locations.get_by_name(part1) elif (value := self.module.params.get("server")) is not None: server: BoundServer = self._client_get_by_name_or_id("servers", value) params["assignee_id"] = server.id diff --git a/plugins/modules/server.py b/plugins/modules/server.py index 124dc0f..02da21c 100644 --- a/plugins/modules/server.py +++ b/plugins/modules/server.py @@ -482,8 +482,16 @@ class AnsibleHCloudServer(AnsibleHCloud): "after 1 July 2026. Please use the `location` argument instead. " "See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters." ) - params["datacenter"] = self._client_get_by_name_or_id("datacenters", self.module.params.get("datacenter")) - server_type_location = params["datacenter"].location + value: str = self.module.params.get("datacenter") + # Backward compatible datacenter argument. + # datacenter hel1-dc2 => location hel1 + if value and not value.isdigit(): + part1, _, _ = value.partition("-") + params["location"] = self.client.locations.get_by_name(part1) + server_type_location = params["location"] + else: + params["datacenter"] = self._client_get_by_name_or_id("datacenters", value) + server_type_location = params["datacenter"].location if self.module.params.get("state") == "stopped" or self.module.params.get("state") == "created": params["start_after_create"] = False