From 6ee6b698efe9a89b104ce9c40bb06baba692df02 Mon Sep 17 00:00:00 2001 From: Jorge Gallegos Date: Tue, 20 May 2025 12:56:35 -0700 Subject: [PATCH] Add `discard_local_ssd` flag to compute instance If you have an instance with a Local (scratch) SSD attached you need to specify the behavior for this when changing the status to TERMINATED i.e. stopping the instance. Without setting this flag you'll get an error back from the API. --- plugins/modules/gcp_compute_instance.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/modules/gcp_compute_instance.py b/plugins/modules/gcp_compute_instance.py index 3c30338e..b71cda0b 100644 --- a/plugins/modules/gcp_compute_instance.py +++ b/plugins/modules/gcp_compute_instance.py @@ -61,6 +61,12 @@ options: - Whether the resource should be protected against deletion. required: false type: bool + discard_local_ssd: + description: + - Discards the contents of any attached Local SSD disks when changing status + to TERMINATED. Defaults to true. + required: false + type: bool disks: description: - An array of disks that are associated with the instances that are created from @@ -1112,6 +1118,7 @@ def main(): state=dict(default='present', choices=['present', 'absent'], type='str'), can_ip_forward=dict(type='bool', aliases=['ip_forward']), deletion_protection=dict(type='bool'), + discard_local_ssd=dict(type='bool', required=False, default=True), disks=dict( type='list', elements='dict', @@ -1506,7 +1513,7 @@ class InstancePower(object): return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances/{name}/start".format(**self.module.params) def _stop_url(self): - return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances/{name}/stop".format(**self.module.params) + return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances/{name}/stop?discardLocalSsd={discard_local_ssd}".format(**self.module.params) def deletion_protection_update(module, request, response):