Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Upgrade Resource State #272

Closed
mortaelth opened this issue Feb 24, 2023 · 7 comments · Fixed by #287
Closed

Unable to Upgrade Resource State #272

mortaelth opened this issue Feb 24, 2023 · 7 comments · Fixed by #287
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@mortaelth
Copy link

What happened?

I am receiving error when upgrading pulumi/random from 4.10.0 to 4.11.2
using this code:

new random.RandomString(
    "adminUserName",
    { length: 16, special: false, number: false },
    { parent: this }
).result;

received error:

random:index:RandomString (adminUserName):
    error: Unable to Upgrade Resource State: This resource was implemented with an UpgradeState() method, however Terraform was expecting an implementation for version 0 upgrade.
    
    This is always an issue with the Terraform Provider and should be reported to the provider developer.

note: we cannot upgrade from 4.10.0 to 4.11.1 either due to pulumi/pulumi-terraform-bridge#810

Expected Behavior

no change of the output during upgrade / no error

Steps to reproduce

use the code above in 4.10.0 and upgrade to 4.11.2

Output of pulumi about

Version 3.51.1
Go Version go1.19.4
Go Compiler gc

Plugins
NAME VERSION
azure 5.35.0
azure-native 1.95.0
azuread 4.3.0
command 0.7.1
grafana 0.0.5
kubernetes 3.24.1
nodejs unknown
random 4.11.2

@types/node 8.10.66
typescript 4.9.5

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).

@mortaelth mortaelth added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Feb 24, 2023
@t0yv0
Copy link
Member

t0yv0 commented Feb 27, 2023

Hi @mortaelth thank you for reporting this issue!

Unfortunately I cannot reproduce this problem by (1) creating a stack on 4.10.0 (2) upgrading to 4.11.2 (3) running pulumi up - I get an empty update.

I'm trying this code since this is left unspecified:

new random.RandomString(
    "adminUserName",
    { length: 16, special: false, number: false },
    // { parent: this }
).result;

When I provision this stack with 4.10.0 I observe this entry in the state (pulumi stack export to confirm). Note "__meta": "{\"schema_version\":\"1\"}",

            {
                "urn": "urn:pulumi:repro::simple-random::random:index/randomString:RandomString::adminUserName",
                "custom": true,
                "id": "EKVDgufZlWbbzbSQ",
                "type": "random:index/randomString:RandomString",
                "inputs": {
                    "__defaults": [
                        "lower",
                        "minLower",
                        "minNumeric",
                        "minSpecial",
                        "minUpper",
                        "upper"
                    ],
                    "length": 16,
                    "lower": true,
                    "minLower": 0,
                    "minNumeric": 0,
                    "minSpecial": 0,
                    "minUpper": 0,
                    "number": false,
                    "special": false,
                    "upper": true
                },
                "outputs": {
                    "__meta": "{\"schema_version\":\"1\"}",
                    "id": "EKVDgufZlWbbzbSQ",
                    "length": 16,
                    "lower": true,
                    "minLower": 0,
                    "minNumeric": 0,
                    "minSpecial": 0,
                    "minUpper": 0,
                    "number": false,
                    "result": "EKVDgufZlWbbzbSQ",
                    "special": false,
                    "upper": true
                },
                "parent": "urn:pulumi:repro::simple-random::pulumi:pulumi:Stack::simple-random-repro",
                "provider": "urn:pulumi:repro::simple-random::pulumi:providers:random::default_4_10_0::025ad5d4-73ab-483c-a876-3a51418c3c0f",
                "propertyDependencies": {
                    "length": null,
                    "number": null,
                    "special": null
                }
            },

I'm wondering if your state is missing __meta or has schema_version 0 instead of "{\"schema_version\":\"1\" would it be possible to confirm?

@t0yv0 t0yv0 removed the needs-triage Needs attention from the triage team label Feb 27, 2023
@mortaelth
Copy link
Author

Hello @t0yv0, thank you for analysis. The __meta is truly missing in the state:

{
                "urn": "urn:pulumi:aks-test3::aks-test3::piq-core:mysql$random:index/randomString:RandomString::adminUserName",
                "custom": true,
                "id": "xxx",
                "type": "random:index/randomString:RandomString",
                "inputs": {
                    "__defaults": [
                        "lower",
                        "minLower",
                        "minNumeric",
                        "minSpecial",
                        "minUpper",
                        "upper"
                    ],
                    "length": 16,
                    "lower": true,
                    "minLower": 0,
                    "minNumeric": 0,
                    "minSpecial": 0,
                    "minUpper": 0,
                    "number": false,
                    "special": false,
                    "upper": true
                },
                "outputs": {
                    "id": "xxx",
                    "length": 16,
                    "lower": true,
                    "minLower": 0,
                    "minNumeric": 0,
                    "minSpecial": 0,
                    "minUpper": 0,
                    "number": false,
                    "numeric": false,
                    "result": "xxx",
                    "special": false,
                    "upper": true
                },
                "parent": "urn:pulumi:aks-test3::aks-test3::piq-core:mysql::mysql-server",
                "provider": "urn:pulumi:aks-test3::aks-test3::pulumi:providers:random::default_4_10_0::a4906b93-3dd6-4e3a-b1a9-176f7ddd39bf",
                "propertyDependencies": {
                    "length": null,
                    "number": null,
                    "special": null
                }
            },

Not sure why is that so. I know we were downgrading from 4.11.1 due to the other issue mentioned above, but otherwise I think we were not doing anything unordinary.

@t0yv0
Copy link
Member

t0yv0 commented Feb 28, 2023

As a workaround if you inject the __meta declaration in the state and do a pulumi stack import this might fix the problem for your stack.

I suspect this is because of the #258 bug and possibly using the affected provider version to provision the resource and write the state.

I will need to look into adding state upgrade hooks so we could code some auto-correcting logic to fix this up for affected stacks as part of normal Pulumi operation.

@mortaelth
Copy link
Author

Thank you, we would rather wait for the autocorrect mechanism, as we have quite a lot of stacks managed by several teams, so it seems safer for now.

t0yv0 added a commit that referenced this issue Mar 7, 2023
t0yv0 added a commit that referenced this issue Mar 7, 2023
@t0yv0 t0yv0 mentioned this issue Mar 7, 2023
@t0yv0 t0yv0 closed this as completed in #287 Mar 7, 2023
t0yv0 added a commit that referenced this issue Mar 7, 2023
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Mar 7, 2023
@t0yv0
Copy link
Member

t0yv0 commented Mar 8, 2023

@mortaelth please try v4.11.3 I think this should fix the problem, if it doesn't please reopen with a repro I'd love to get this all working right for your teams.

@mortaelth
Copy link
Author

mortaelth commented Mar 8, 2023 via email

@t0yv0
Copy link
Member

t0yv0 commented Mar 8, 2023

Yes that's expected - unfortunately the current "migrate on read" code does not write it back to state. It will add __meta next time it needs to write state, that is on next update/replace. I think RandomString never updates, so that'd be a replace.

@AaronFriel AaronFriel added this to the 0.85 milestone Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants