Upgrading to `gcp-pulumi@v9` gives me: ``` err...
# google-cloud
m
Upgrading to
gcp-pulumi@v9
gives me:
Copy code
error:   sdk-v2/provider2.go:572: sdk.helper_schema: retention_period in state has unexpected type string: provider=google-beta@9.1.0
Shouldn’t pulumi run state upgrades of the underlying terraform provider? https://github.com/GoogleCloudPlatform/magic-modules/pull/15000/files
Copy code
ResourceStorageBucketStateUpgradeV3
m
Hey @millions-train-91139 It looks like it is calling the upgrade and the upgrade is failing and returning the error you linked to on line 1581
If you export the state to a file, what is the value?
m
Hi @modern-spring-15520 Seems like it’s an integer (and therefore json.Number should work?) Not sure how Go casting works in this case - does every number becomes json.Numer Also the error is a bit weird “retention_period in state has unexpected type string” - it’s literally not string in the state
🤔 1
m
Let me ask around for best path forward
m
What version of the provider are you migrating from?
m
v8 The schema version is 3 (newest is 4)
v8***
m
it may help to first upgrade to the last version in the 8.x train and then run the upgrade to v9
We added additional metadata to the state files in some of the later versions of v8 that helps avoid some of these type errors in the migrators.
m
Will check The problem in this approach (like with db migrations) is that it muat be done on all problematic stacks (2 step upgrade) because if you squash the upgrade commits, and some stacks didnt get the lastest 8.x - they will fail the same way
(we have 10's of these stacks)
m
Oh, just to double check: are you using
pulumi up --refresh --run-program
to perform the update? If not, it's possible that might be enough to coerce the state. (We plan to make both of those flags enabled by default for version upgrades in the future.)
m
Will check
Same error, even with
pulumi up --refresh --run-program
(Even if it would have worked, we don’t run --refresh in our production workflows)
Was using
v8.32.1
before
(Pulumi 3.190.0)
(Same in Pulumi 3.199.0)
In `-v=9`:
Copy code
I1003 14:40:43.886103   15736 eventsink.go:59] [DEBUG] Attributes before migration: map[string]interface {}{"autoclass":[]interface {}{}, "cors":[]interface {}{}, "custom_placement_config":[]interface {}{}, "default_event_based_hold":false, "effective_labels":map[string]interface {}{}, "enable_object_retention":false, "encryption":[]interface {}{}, "force_destroy":false, "hierarchical_namespace":[]interface {}{map[string]interface {}{"enabled":false}}, "id":"READCTED", "ip_filter":[]interface {}{}, "labels":map[string]interface {}{}, "lifecycle_rule":[]interface {}{}, "location":"REDACTED", "logging":[]interface {}{}, "name":"REDACTED", "project":"REDACTED", "project_number":"REDACTED", "public_access_prevention":"inherited", "requester_pays":false, "retention_policy":[]interface {}{map[string]interface {}{"is_locked":true, "retention_period":"315360000"}}, "rpo":interface {}(nil), "self_link":"<https://www.googleapis.com/storage/v1/b/REDACTED>", "soft_delete_policy":[]interface {}{map[string]interface {}{"effective_time":"2024-03-01T08:00:00.000Z", "retention_duration_seconds":"604800"}}, "storage_class":"STANDARD", "terraform_labels":map[string]interface {}{}, "time_created":"2023-01-11T11:43:36.161Z", "timeouts":interface {}(nil), "uniform_bucket_level_access":true, "updated":"2024-05-26T07:42:28.024Z", "url":"<gs://REDACTED>", "versioning":[]interface {}{map[string]interface {}{"enabled":false}}, "website": []interface {}{}}
Notice:
Copy code
"retention_period":"315360000"
Is a string before migration 🤔
Seems like it should be a json.Number: https://go.dev/play/p/-vUhXnqVvrY
Actually I think I understand where the string type is coming from - the new type after the change in my Go code, since I now need to:
Copy code
policy = &storage.BucketRetentionPolicyArgs{
			IsLocked: pulumi.BoolPtr(true),
			RetentionPeriod: pulumi.Sprintf("%d", 60*60*24*365*10),
		}
But that’s weird, I would assume it should only upgrade the state
c
Not sure if this is helpful, but I'm seeing the same issue driving with TypeScript after the upgrade
If I'm reading this part of the patch correctly, it looks like the upgrade transform is assuming the retention period is always a number and needs to be converted to a string. That would unfortunately disallow us from passing strings, but fine if TypeScript (and I assume Go) allowed us to pass an integer as that retention period which is not possible because it was switched to a string in the type definitions. In other words, the upgrade and type definitions are out of alignment. Does that sound like a reasonable diagnosis? If so, it seems like checking if the value is a string and just leaving it alone in the upgrader would work? https://github.com/GoogleCloudPlatform/magic-modules/pull/15000/files#diff-79c9f7a54630f5a6a6b43bb88a5699b2[…]3d3df216ca7eef820663617bcddR1575-R1582
m
Which is weird because the variable name is called rawState. I wonder why the fact that its a string in the configuration is problematic. I think the correct way to solve this is first to understand whether it’s actually a bug in terraform which is then mirrored into Pulumi, or something specific in how Pulumi handles state upgrades. Would appreciate help here
c
It's probably time to file a bug at https://github.com/pulumi/pulumi-gcp. I started, but it's asking for a reproducible pulumi program, which I would need a bit more time to produce as I've only worked in an existing pulumi project that I didn't set up before. If anyone else on this thread is able to do that more quickly, that would be appreciated, otherwise I'll try to do that a little later.
I tried recreating this issue with a simple pulumi program, but was not able to do so in isolation. My process was to create a bucket with an integer retention period under gcp v8, upgrade to v9, switch the retention period to the string representation, then re-up. Under v9, pulumi reported no changes to be made. This is what I'd hope would happen in my actual program, but I continue to get the error above about an unexpected string in v9. If anyone else has any ideas here, I'd appreciate the help.
m
I actually do have a reproduction for this on a clean env
Two full go projects pointing to the same stack
c
Thanks for doing that! My TypeScript equivalent looks very similar but I couldn't get it to fail.
m
I noticed that when I upgrade from
8.41.1
it works
But from
8.32.1
it doesn’t
c
oh, interesting - i'll give that a try - thanks for the tip!
m
That’s what @miniature-twilight-47355 wrote to be honest
But I am not sure how this is “acceptable” for real world use cases
c
ah, I see - I think I skimmed that too quickly
m
Need to upgrade all stacks in two steps
Actually allow me to correct myself Two step upgrade does not work
8.32.1
->
8.41.1
->
v9
I assume it has something to do with
__pulumi_raw_state_delta
object in the state? It is only available if the object was initially created with
8.41.1
but does not appear when upgrading from
8.32.1
to
8.41.1
. So still broken @miniature-twilight-47355
c
ah, shoot - that's a shame 😕 i might retry my TypeScript example with this in mind to see if it helps motivate the ticket a bit more
m
Seems like
pulumi refresh
solves it in version
8.41.1
before continuing on to
v9
This is all too “brittle” I wonder if there could just be a fix in next versions that would solve it backwards, this seems like something that affects every terraform provider schema upgrade
@enough-garden-22763 hope its okay to tag you here
c
Just for completeness, I did do the upgrade from
8.32.1
to
8.41.1
and the attempted going to
9.3.0
but got the same error
e
Hi @millions-train-91139 I've moved teams since https://github.com/pulumi/pulumi-terraform-bridge/pull/2945 but I can have quick look. I think first and foremost we need your case logged in the tracker in https://github.com/pulumi/pulumi-gcp/ with a repro that will really help get maintainers attention! Brief overview of how 2945 issue, 2945 attempts to make progress on a complicated legacy issue where Pulumi did run TF state upgraders but ended up passing distorted data into these upgraders, because Pulumi state files encoded the TF state in a lossy manner. The aim of 2945 was to make the encoding lossless without balooning the storage requirements so it added a notion of a "delta" to encode the missing information.
This fix unfortunately does not help users that have states produced by an older version of the provider without the information encoded, which may be affecting you here, but again a repro would be appreciated so we chase this down formally! Thanks for your patience.
m
Hi, thanks for answering Take a look above in this thread, I have opened https://github.com/pulumi/pulumi-gcp/issues/3432 with a repro attached.
👀 1
e
Sorry I must have missed this. Thank you!
🙌 2