Skip to content

Feature gap: add gracefulShutdown field for beta #9278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

modular-magician
Copy link
Collaborator

This patch adds graceful_shutdown field to resource_compute_instance, resource_compute_instance_template and resource_compute_region_instance_template. This fields is a configuration setting for a compute instance that allows it to perform a graceful shutdown. The graceful_shutdown field is responsible for:

  • Enabling or disabling the graceful shutdown feature for the compute instance.
  • Defining the maximum duration allowed for the shutdown process, ensuring that the instance has enough time to close resources and complete operations before transitioning to the STOPPING state.
  • Providing a detailed configuration for the shutdown duration, including both seconds and nanoseconds for precise control.
  • This configuration helps ensure that the instance can shut down in a controlled manner, minimizing the risk of data loss or corruption.

Gracefull shutdown overview.

Related issue here.

This PR provides a workaround for max_duration.0.nanos due to an issue with the API. Please find the details below:

  • When the seconds field is set (1–3600 s) and the nanos field is also set, the value is passed in the request body but is not updated in the cloud, as observed in the GET response.
  • It is not possible to set seconds to zero (the API returns an error).
  • Because of this, a workaround is needed — the value of nanos is read from the resource state to avoid not updated tfstate (constant diff between setup and state).

POST REQUEST:

POST /compute/beta/projects/iac-poc-krakow4/zones/us-central1-a/instances/test/setScheduling?alt=json&prettyPrint=false HTTP/1.1  

Host: compute.googleapis.com  

User-Agent: google-api-go-client/0.5 Terraform/1.10.3 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-google-beta/dev6  

Content-Length: 272  

Content-Type: application/json  

X-Goog-Api-Client: gl-go/1.23.0 gdcl/0.214.0  

Accept-Encoding: gzip  

Request body:

{  

"automaticRestart": true,  

"gracefulShutdown": {  

  "enabled": true,  

  "maxDuration": {  

   "nanos": 1000,  

   "seconds": "1"  

  }  

},  

"hostErrorTimeoutSeconds": null,  

"instanceTerminationAction": "",  

"nodeAffinities": [  

  null  

],  

"onHostMaintenance": "MIGRATE",  

"preemptible": false,  

"provisioningModel": "STANDARD"  

}  

GET REQUEST RESPONSE

(…) 

"scheduling": { 

"onHostMaintenance": "MIGRATE", 

"automaticRestart": true, 

"preemptible": false, 

"provisioningModel": "STANDARD", 

"gracefulShutdown": { 

  "enabled": true, 

  "maxDuration": { 

   "seconds": "1" 

  } 
} 
}, 

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

compute: added `graceful_shutdown` field to `google_compute_instance`, `google_compute_instance_template` and `google_compute_region_instance_template` resource (beta)

Derived from GoogleCloudPlatform/magic-modules#12963

Signed-off-by: Cezary Sobczak <[email protected]>

[upstream:a494af4af8addbd142651fdfcf12ad71e6de8062]

Signed-off-by: Modular Magician <[email protected]>
@modular-magician modular-magician requested a review from a team as a code owner February 10, 2025 18:20
@modular-magician modular-magician merged commit ca1e3ca into hashicorp:main Feb 10, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant