Skip to content

fix: GCP data disk snapshot never refreshed after first stop cycle#389

Open
arnaud-robin wants to merge 1 commit into
PierreBeucher:masterfrom
arnaud-robin:gcp-datasnapshot-fix
Open

fix: GCP data disk snapshot never refreshed after first stop cycle#389
arnaud-robin wants to merge 1 commit into
PierreBeucher:masterfrom
arnaud-robin:gcp-datasnapshot-fix

Conversation

@arnaud-robin

@arnaud-robin arnaud-robin commented Jun 10, 2026

Copy link
Copy Markdown

GCP data disk snapshot was only created on the first instance stop and
never updated afterwards, causing any data written after the first
stop/start cycle to be lost on restart

The snapshot stack relied on replaceOnChanges: ["sourceDisk"] to take a
fresh snapshot on each stop, a pattern inherited from AWS where a volume
restored from snapshot gets a brand new random ID (vol-xxx), naturally
triggering replacement. On GCP however the disk is identified by its
name (-data) which stays identical across delete/restore
cycles: Pulumi saw no diff on subsequent stops and silently kept the
stale snapshot.

Since GCP provides no naturally-changing input, introduce a synthetic
one: provisioner now passes a unique snapshotVersion (timestamp) on
every data snapshot provision, included in the snapshot name. GCP
snapshot names are immutable so the name change forces Pulumi to
replace the snapshot on every stop cycle.

Fix #388

@PierreBeucher

Copy link
Copy Markdown
Owner

Thanks for this PR! Have you tested the fix yourself?

@arnaud-robin

Copy link
Copy Markdown
Author

Yes I just tested it and the fix is working as intended. A new snapshot is created after each stop cycle and the data is restored as intended.

@PierreBeucher

PierreBeucher commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Tested, reproduced the issue and it works with the fix. Thanks! Will merge soon after review comments are processed :)

* Unique version identifier for the snapshot. A new value forces creation
* of a fresh snapshot replacing the previous one.
*/
snapshotVersion?: string

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be required, not optional, given the behavior identified. It will also avoid having checks for undefined in code - being cleaner

const config = new pulumi.Config()
const volumeId = config.get("volumeId")
const additionalTags = config.getObject<string[]>("additionalTags") || []
const snapshotVersion = config.get("snapshotVersion")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const snapshotVersion = config.get("snapshotVersion")
const snapshotVersion = config.require("snapshotVersion")

// and force replacement of snapshot if volumeId changes
deleteBeforeReplace: true,
replaceOnChanges: ["sourceDisk"],
replaceOnChanges: ["sourceDisk", "name"],

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed to replaceOnChanges name, changing name already causes a replacement: https://www.pulumi.com/registry/packages/gcp/api-docs/compute/snapshot/#inputs

/**
* Unique version identifier forcing snapshot replacement when it changes.
*/
snapshotVersion?: pulumi.Input<string>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in other comment: should be required

@PierreBeucher PierreBeucher added the review comments waiting MR reviewed with comments. Awaiting fix or answer from contributor. label Jun 13, 2026
GCP data disk snapshot was only created on the first instance stop and
never updated afterwards, causing any data written after the first
stop/start cycle to be lost on restart (PierreBeucher#388).

The snapshot stack relied on replaceOnChanges: ["sourceDisk"] to take a
fresh snapshot on each stop, a pattern inherited from AWS where a volume
restored from snapshot gets a brand new random ID (vol-xxx), naturally
triggering replacement. On GCP however the disk is identified by its
name (<instance>-data) which stays identical across delete/restore
cycles: Pulumi saw no diff on subsequent stops and silently kept the
stale snapshot.

Since GCP provides no naturally-changing input, introduce a synthetic
one: provisioner now passes a unique snapshotVersion (timestamp) on
every data snapshot provision, included in the snapshot name. GCP
snapshot names are immutable so the name change forces Pulumi to
replace the snapshot on every stop cycle.
@arnaud-robin
arnaud-robin force-pushed the gcp-datasnapshot-fix branch from ee03c77 to 1a4979f Compare June 14, 2026 20:16
@arnaud-robin

Copy link
Copy Markdown
Author

Updated thanks to your comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review comments waiting MR reviewed with comments. Awaiting fix or answer from contributor.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GCP: data disk snapshot is never refreshed after the first stop cycle, causing data loss on restart

2 participants