pulumi / pulumi-gcp

A Google Cloud Platform (GCP) Pulumi resource package, providing multi-language access to GCP
Apache License 2.0
183 stars 53 forks source link

CloudSQL instances with auto disk resizing fail to update on the first try but succeed on retrying #2307

Open parth-da opened 3 months ago

parth-da commented 3 months ago

Describe what happened

CloudSQL for Postgres instances created with diskAutoresize: true always fail if the size of the database has changed since the last time they were updated via pulumi with:

    error: 1 error occurred:
        * updating urn:pulumi:cluster.scratchc::cluster::gcp:sql/databaseInstance:DatabaseInstance::test-pg: 1 error occurred:
        * Error, failed to update instance settings for : googleapi: Error 400: Invalid request: The disk size cannot decrease. Current size: 31 GB, requested: 10 GB.., invalid

Re-running pulumi up however succeeds.

It looks like pulumi caches the old disk size (not sure where since I couldn't find it in the output of pulumi stack export) and sends it to GCP which then rejects the request. The first run updates this cache allowing subsequent attempts to succeed.

This is very similar to https://github.com/pulumi/pulumi-gcp/issues/549 except for the ignoreChanges part.

Sample program

Do the same steps as in https://github.com/pulumi/pulumi-gcp/issues/549#issuecomment-810492088 (removing the ignoreChanges lines).

Then re-run pulumi up after making some small change to the script. I was trying to set a database flag.

       databaseVersion: "POSTGRES_13",
+      databaseFlags: [{"temp_file_limit", 500000}],
       settings: {

Log output

    error: 1 error occurred:
        * updating urn:pulumi:cluster.scratchc::cluster::gcp:sql/databaseInstance:DatabaseInstance::test-pg: 1 error occurred:
        * Error, failed to update instance settings for : googleapi: Error 400: Invalid request: The disk size cannot decrease. Current size: 31 GB, requested: 10 GB.., invalid

Affected Resource(s)

CloudSQL for Postgres instances

Output of pulumi about

CLI
Version      3.112.0
Go Version   go1.22.1
Go Compiler  gc

Plugins
NAME    VERSION
nodejs  unknown

Host
OS       darwin
Version  14.6.1
Arch     arm64

This project is written in nodejs: executable='/nix/store/9zli090ri6wlhjla6bb51dg326ann92x-nodejs-20.12.2/bin/node' version='v20.12.2'

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

iwahbe commented 3 months ago

Hi @parth-da. Thanks for reporting an issue. I suspect that you can work around this issue by running pulumi up --refresh instead of pulumi up. That will fetch the current size from gcp before running the pulumi up.

parth-da commented 3 months ago

Yes we can but is there a way to avoid refreshing the entire stack when running pulumi up? That is, is there a way to specify a particular resource to always be refreshed when changes are applied? (I was unable to find one). For now, configuring retries in automated deployments works for us but is not ideal.

iwahbe commented 3 months ago

It's not idea, but you can use a targeted refresh:

pulumi refresh --target urn:pulumi:cluster.scratchc::cluster::gcp:sql/databaseInstance:DatabaseInstance::test-pg

(replacing the URN with your actual URN)

It's definitely a bug in the resource. There is no "in-code" resource option to specify a refresh before an update.