From e8fda3557cf835e4e711a934b46d4f672f9b517c Mon Sep 17 00:00:00 2001 From: Amirhossein Shaerpour <87924605+shaerpour@users.noreply.github.com> Date: Wed, 7 May 2025 12:14:39 +0330 Subject: [PATCH] fix!: do not detach volume if `server` is not provided (#632) Do not detach volume if `server` is not provided ##### SUMMARY Volumes were automatically detached from servers if they already exists and attached to a server. This PR fixes this issue after adding new ```volume_attachment``` module so user can attach/detach volumes with that module Fixes: #490 ##### ISSUE TYPE - Bugfix Pull Request ##### COMPONENT NAME ```volume``` --------- Co-authored-by: Jonas L. --- .../fragments/remove-auto-detach-volume.yml | 2 ++ plugins/modules/volume.py | 6 ----- .../integration/targets/volume/tasks/test.yml | 22 ------------------- 3 files changed, 2 insertions(+), 28 deletions(-) create mode 100644 changelogs/fragments/remove-auto-detach-volume.yml diff --git a/changelogs/fragments/remove-auto-detach-volume.yml b/changelogs/fragments/remove-auto-detach-volume.yml new file mode 100644 index 0000000..2c4bd06 --- /dev/null +++ b/changelogs/fragments/remove-auto-detach-volume.yml @@ -0,0 +1,2 @@ +breaking_changes: + - volume - Volumes are no longer detached when the server argument is not provided. Please use the ``volume_attachment`` module to manage volume attachments. diff --git a/plugins/modules/volume.py b/plugins/modules/volume.py index 1bcb442..118dc4c 100644 --- a/plugins/modules/volume.py +++ b/plugins/modules/volume.py @@ -244,12 +244,6 @@ class AnsibleHCloudVolume(AnsibleHCloud): action = self.hcloud_volume.attach(server, automount=automount) action.wait_until_finished() self._mark_as_changed() - else: - if self.hcloud_volume.server is not None: - if not self.module.check_mode: - action = self.hcloud_volume.detach() - action.wait_until_finished() - self._mark_as_changed() labels = self.module.params.get("labels") if labels is not None and labels != self.hcloud_volume.labels: diff --git a/tests/integration/targets/volume/tasks/test.yml b/tests/integration/targets/volume/tasks/test.yml index 60189aa..11f9e7c 100644 --- a/tests/integration/targets/volume/tasks/test.yml +++ b/tests/integration/targets/volume/tasks/test.yml @@ -99,28 +99,6 @@ - volume is not changed - volume.hcloud_volume.server == hcloud_server_name -- name: test detach Volume with checkmode - hetzner.hcloud.volume: - name: "{{hcloud_volume_name}}" - check_mode: true - register: volume -- name: verify detach Volume with checkmode - assert: - that: - - volume is changed - - volume.hcloud_volume.server == hcloud_server_name - -- name: test detach Volume - hetzner.hcloud.volume: - name: "{{hcloud_volume_name}}" - register: volume -- name: verify detach volume - assert: - that: - - volume is changed - - volume.hcloud_volume.location == hcloud_location_name - - volume.hcloud_volume.server != hcloud_server_name - - name: test update Volume label hetzner.hcloud.volume: name: "{{hcloud_volume_name}}"