Skip to content

sql: support in-place storage shrink for google_sql_database_instance#18327

Open
DrFaust92 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
DrFaust92:sql-in-place-storage-shrink
Open

sql: support in-place storage shrink for google_sql_database_instance#18327
DrFaust92 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
DrFaust92:sql-in-place-storage-shrink

Conversation

@DrFaust92

Copy link
Copy Markdown
Contributor

Summary

Reducing disk_size on google_sql_database_instance (with disk_autoresize disabled) previously forced the instance to be recreated — a destructive operation for a data disk. Cloud SQL now supports reducing storage in place via the dedicated Instances.PerformDiskShrink operation (GA for MySQL/PostgreSQL, and available for SQL Server).

This change wires that up:

  • diskSizeCutomizeDiff no longer calls ForceNew on a shrink; the shrink is kept as an in-place update.
  • On update, a disk_size decrease is carried out with Projects.Instances.PerformDiskShrink (the settings update keeps the current size, so it's a no-op for disk).
  • A pre-flight GetDiskShrinkConfig call returns a clear error when the requested size is below the instance's current minimum shrinkable size, instead of letting the shrink operation start and then fail.
  • disk_size field docs updated.

Increases are unaffected (still applied via the settings update). A shrink with disk_autoresize enabled continues to be ignored, as before.

Tests

Acceptance tests were run against real GCP:

  • TestAccSqlDatabaseInstance_storageShrink (new) — creates a 100GB instance and shrinks it in place to 90GB, asserting the disk size and that the instance is not recreated (same ID). PASS
  • TestAccSqlDatabaseInstance_DiskSizeAutoResizeWithDiskSize (updated) — the step that previously asserted a forced recreate now asserts an in-place update plan (PlanOnly + ExpectNonEmptyPlan). PASS

Note: storage shrink is not supported on shared-core machine types, so the new test uses a db-custom-* tier.

Release Note

sql: `google_sql_database_instance` now performs an in-place storage shrink when `disk_size` is reduced with `disk_autoresize` disabled, instead of forcing instance recreation

Reducing `disk_size` (with `disk_autoresize` disabled) previously forced
the instance to be recreated. Use the dedicated Instances.PerformDiskShrink
operation to shrink storage in place instead, with a pre-flight
GetDiskShrinkConfig check that returns a clear error when the requested
size is below the instance's minimum shrinkable size.
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Jul 19, 2026
@github-actions
github-actions Bot requested a review from shuyama1 July 19, 2026 02:24
@github-actions

Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@shuyama1, 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.

@modular-magician modular-magician added service/sqladmin-cp and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Jul 21, 2026
@modular-magician

modular-magician commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 2 files changed, 138 insertions(+), 19 deletions(-)
google-beta provider View Diff 2 files changed, 138 insertions(+), 19 deletions(-)

Test report

Analytics

Total Tests Passed Skipped Affected
163 132 30 1
Affected Service Packages
  • sql

Learn how VCR tests work


Step 1: Replaying Mode

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
  • TestAccSqlDatabaseInstance_storageShrink

View the replaying VCR build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
✅ Log TestAccSqlDatabaseInstance_storageShrink

🟢 All tests passed!

View the recording VCR build log or the debug logs folder for detailed results.

@DrFaust92, @shuyama1 VCR tests complete for ef335c3!

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.

2 participants