Skip to content

Feature gap: add gracefulShutdown field for beta#12963

Merged
trodge merged 2 commits intoGoogleCloudPlatform:mainfrom
Cezarus27:feature_graceful_shutdown
Feb 10, 2025
Merged

Feature gap: add gracefulShutdown field for beta#12963
trodge merged 2 commits intoGoogleCloudPlatform:mainfrom
Cezarus27:feature_graceful_shutdown

Conversation

@Cezarus27
Copy link
Copy Markdown
Contributor

@Cezarus27 Cezarus27 commented Feb 4, 2025

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)

Signed-off-by: Cezary Sobczak <Cezary.Sobczak@infogain.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 4, 2025

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@trodge, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@github-actions github-actions bot requested a review from trodge February 4, 2025 23:24
@modular-magician modular-magician added awaiting-approval Pull requests that need reviewer's approval to run presubmit tests service/compute-instances and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Feb 4, 2025
@modular-magician
Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 6 files changed, 60 insertions(+))
google-beta provider: Diff ( 10 files changed, 818 insertions(+), 2 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 137 insertions(+), 1 deletion(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_compute_instance (346 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance" "primary" {
  scheduling {
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
    maintenance_interval = # value needed
  }
}

Resource: google_compute_instance_from_machine_image (12 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance_from_machine_image" "primary" {
  scheduling {
    availability_domain = # value needed
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
    maintenance_interval = # value needed
    min_node_cpus        = # value needed
    preemptible          = # value needed
  }
}

Resource: google_compute_instance_from_template (20 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance_from_template" "primary" {
  scheduling {
    availability_domain = # value needed
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
    maintenance_interval = # value needed
    min_node_cpus        = # value needed
    on_host_maintenance  = # value needed
    preemptible          = # value needed
  }
}

Resource: google_compute_instance_template (247 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance_template" "primary" {
  scheduling {
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
  }
}

Resource: google_compute_region_instance_template (71 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_region_instance_template" "primary" {
  scheduling {
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
  }
}

@modular-magician
Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 1105
Passed tests: 1026
Skipped tests: 75
Affected tests: 4

Click here to see the affected service packages
  • compute

Action taken

Found 4 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccComputeInstanceTemplate_gracefulShutdown
  • TestAccComputeInstance_GracefulShutdownWithResetUpdate
  • TestAccComputeInstance_GracefulShutdownWithoutResetUpdate
  • TestAccComputeRegionInstanceTemplate_gracefulShutdown

Get to know how VCR tests work

@modular-magician
Copy link
Copy Markdown
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccComputeInstance_GracefulShutdownWithResetUpdate [Debug log]
TestAccComputeInstance_GracefulShutdownWithoutResetUpdate [Debug log]
TestAccComputeRegionInstanceTemplate_gracefulShutdown [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🔴 Tests failed during RECORDING mode:
TestAccComputeInstanceTemplate_gracefulShutdown [Error message] [Debug log]

🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.

View the build log or the debug log for each test

Signed-off-by: Cezary Sobczak <Cezary.Sobczak@infogain.com>
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Feb 5, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 7, 2025

@trodge This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Feb 7, 2025
@modular-magician
Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 6 files changed, 60 insertions(+))
google-beta provider: Diff ( 10 files changed, 819 insertions(+), 2 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 137 insertions(+), 1 deletion(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_compute_instance (346 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance" "primary" {
  scheduling {
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
    maintenance_interval = # value needed
  }
}

Resource: google_compute_instance_from_machine_image (12 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance_from_machine_image" "primary" {
  scheduling {
    availability_domain = # value needed
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
    maintenance_interval = # value needed
    min_node_cpus        = # value needed
    preemptible          = # value needed
  }
}

Resource: google_compute_instance_from_template (20 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance_from_template" "primary" {
  scheduling {
    availability_domain = # value needed
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
    maintenance_interval = # value needed
    min_node_cpus        = # value needed
    on_host_maintenance  = # value needed
    preemptible          = # value needed
  }
}

Resource: google_compute_instance_template (247 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_instance_template" "primary" {
  scheduling {
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
  }
}

Resource: google_compute_region_instance_template (71 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_compute_region_instance_template" "primary" {
  scheduling {
    graceful_shutdown {
      enabled = # value needed
      max_duration {
        nanos   = # value needed
        seconds = # value needed
      }
    }
  }
}

@modular-magician
Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 1105
Passed tests: 1029
Skipped tests: 75
Affected tests: 1

Click here to see the affected service packages
  • compute

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccComputeInstanceTemplate_gracefulShutdown

Get to know how VCR tests work

@modular-magician
Copy link
Copy Markdown
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccComputeInstanceTemplate_gracefulShutdown [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

@trodge trodge added this pull request to the merge queue Feb 10, 2025
Merged via the queue into GoogleCloudPlatform:main with commit a494af4 Feb 10, 2025
Dawid212 pushed a commit to Dawid212/magic-modules that referenced this pull request Feb 12, 2025
…rm#12963)

Signed-off-by: Cezary Sobczak <Cezary.Sobczak@infogain.com>
niharika-98 pushed a commit to niharika-98/magic-modules that referenced this pull request Feb 17, 2025
…rm#12963)

Signed-off-by: Cezary Sobczak <Cezary.Sobczak@infogain.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants