diff --git a/changelogs/fragments/improve-modules-api-arguments.yml b/changelogs/fragments/improve-modules-api-arguments.yml new file mode 100644 index 0000000..5879821 --- /dev/null +++ b/changelogs/fragments/improve-modules-api-arguments.yml @@ -0,0 +1,3 @@ +minor_changes: + - Renamed the `endpoint` module argument to `api_endpoint`, backward compatibility is maintained using an alias. + - Allow to set the `api_endpoint` module argument using the `HCLOUD_ENDPOINT` environment variable. diff --git a/plugins/doc_fragments/hcloud.py b/plugins/doc_fragments/hcloud.py index 6426ee0..1a55fd5 100644 --- a/plugins/doc_fragments/hcloud.py +++ b/plugins/doc_fragments/hcloud.py @@ -5,22 +5,26 @@ class ModuleDocFragment: DOCUMENTATION = """ options: - api_token: - description: - - This is the API Token for the Hetzner Cloud. - - You can also set this option by using the environment variable HCLOUD_TOKEN - required: True - type: str - endpoint: - description: - - This is the API Endpoint for the Hetzner Cloud. - default: https://api.hetzner.cloud/v1 - type: str + api_token: + description: + - The API Token for the Hetzner Cloud. + - You can also set this option by using the C(HCLOUD_TOKEN) environment variable. + required: True + type: str + api_endpoint: + description: + - The API Endpoint for the Hetzner Cloud. + - You can also set this option by using the C(HCLOUD_ENDPOINT) environment variable. + default: https://api.hetzner.cloud/v1 + type: str + aliases: [endpoint] + requirements: - python-dateutil >= 2.7.5 - requests >=2.20 + seealso: -- name: Documentation for Hetzner Cloud API - description: Complete reference for the Hetzner Cloud API. - link: https://docs.hetzner.cloud/ + - name: Documentation for Hetzner Cloud API + description: Complete reference for the Hetzner Cloud API. + link: https://docs.hetzner.cloud """ diff --git a/plugins/module_utils/hcloud.py b/plugins/module_utils/hcloud.py index 871c3c5..49bda6d 100644 --- a/plugins/module_utils/hcloud.py +++ b/plugins/module_utils/hcloud.py @@ -86,7 +86,7 @@ class AnsibleHCloud: def _build_client(self) -> None: self.client = Client( token=self.module.params["api_token"], - api_endpoint=self.module.params["endpoint"], + api_endpoint=self.module.params["api_endpoint"], application_name="ansible-module", application_version=version, ) @@ -124,9 +124,11 @@ class AnsibleHCloud: "fallback": (env_fallback, ["HCLOUD_TOKEN"]), "no_log": True, }, - "endpoint": { + "api_endpoint": { "type": "str", + "fallback": (env_fallback, ["HCLOUD_ENDPOINT"]), "default": "https://api.hetzner.cloud/v1", + "aliases": ["endpoint"], }, } diff --git a/tests/unit/module_utils/test_hcloud.py b/tests/unit/module_utils/test_hcloud.py index 90c7416..197de85 100644 --- a/tests/unit/module_utils/test_hcloud.py +++ b/tests/unit/module_utils/test_hcloud.py @@ -18,7 +18,7 @@ def test_hcloud_fail_json_hcloud(): module = MagicMock() module.params = { "api_token": "fake_token", - "endpoint": "https://api.hetzner.cloud/v1", + "api_endpoint": "https://api.hetzner.cloud/v1", } AnsibleHCloud.represent = "hcloud_test" hcloud = AnsibleHCloud(module)