Hi everyone. I managed to create a bucket, then ch...
# general
h
Hi everyone. I managed to create a bucket, then changed it's name to empty string in code. After running
pulumi up
my previous bucket got deleted and the creation of new one failed.
pulumi up
doesn't help. How can I solve this?
b
Hey @helpful-processor-86468 - can you post your code and/or the error messaging you're receiving?
h
First version:
Copy code
import pulumi
from pulumi_gcp import storage

# Create a GCP resource (Storage Bucket)
bucket = storage.Bucket('pulumi_test', name='pulumi_test')

# Export the DNS name of the bucket
pulumi.export('pulumi_test',  bucket.url)
after this i did
pulumi up
- no errors Second version (i did this on purpose, wanted to see what will happen):
Copy code
import pulumi
from pulumi_gcp import storage

# Create a GCP resource (Storage Bucket)
bucket = storage.Bucket('pulumi_test', name='')

# Export the DNS name of the bucket
pulumi.export('pulumi_test',  bucket.url)
Error recieved:
Copy code
Type                   Name               Status                   Info
     pulumi:pulumi:Stack    quickstart-dev     **failed**               1 error
 +-  └─ gcp:storage:Bucket  pulumi_test  **replacing failed**     [diff: ~name]; 1 error

Diagnostics:
  pulumi:pulumi:Stack (quickstart-dev):
    error: update failed

  gcp:storage:Bucket (pulumi_test):
    error: googleapi: Error 400: Empty bucket name, invalid
Then I tried to fix this and provided a valid non taken bucket name through
name
parameter, performed
pulumi up
and got this error:
Copy code
error: deleting urn:pulumi:dev::quickstart::gcp:storage/bucket:Bucket::pulumi_test: googleapi: Error 404: Not Found, notFound
Pulumi started replacing the bucket, so it deleted the bucket and then tried to create a new one, but it got a runtime error because the name of the bucket was not valid.
And after I tried to fix it it by providing correct name cli wouldn't let me because it couln't perform replace procedure on buckets, because the old one was already deleted.
I managed to find a solution by going back to the previous version of the code and doing
pulumi up
and
pulumi refresh
after that it finally updated the pulumi state (the state was missing information about bucket deletion which happened during replacement).
My concern is what if there are some dependencies and the code will be more complicated. Is going back to previous version of the code and doing
pulumi up
and
pulumi refresh
going to fix my state every time? I'm trying to decide if we're going to start a new project with terraform or pulumi. I don't want to deal with corrupted state and spend hours trying to fix it manually.
a
had similar issues.
i am generally running
pulumi up --refresh
which takes longer
does more than it should
but it fails less often.
h
Less often? 🙂 That doesn't sound very reassuring.
a
so there are still things that it doesn’t figure out automatically.
for example changing an id to a different value
there i had to add aliases in the code
i haven’t found yet a good reference, if you want to do this change, you need to do these steps to make it work in all cases.
h
For the case I presented here going back to previous version of code and doing
pulumi up --refresh
doesnt work
I have to explicitly do
pulumi refresh
so it will actually catch that the bucket got deleted
a
oh. interesting. i didn’t know these are different ? 😅
h
Copy code
Refreshing (dev):
     Type                   Name               Status
     pulumi:pulumi:Stack    quickstart-dev
 -   └─ gcp:storage:Bucket  pulumi_test  deleted

Outputs:
    pulumi_test: "<gs://pulumi_test>"
This is what i get from
pulumi refresh
From
pulumi up --refresh
I get
2 unchanged resources
a
the docs say:
-r, --refresh                      Refresh the state of the stack's resources before this update
mmh
i guess you need a better pulumi knowledge holder than me 😄
g
This is happening because the provider is not validating the name. If it was, your code would break on preview as it should. You can bring the issue there, if I'm not mistaken this kind of validation is done on Google's Magic Modules
Because the provider says it is valid it's getting a runtime error when the API says it's invalid
But it should first create the new bucket, update everything that references it and then delete the old one For this corrupted state to happen it would need a
deleteBeforeReplace
somewhere in your code
h
It seems like the bucket has
deleteBeforeReplace
by default
Also my concern is not the error itself. I get why it fails here and I'm even okay with it. My concern is about a more complicated code with a lot of dependencies failing. Will simple commit revert,
pulumi up
and
pulumi refresh
fix my state every time? I'd rather not spend multiple hours trying to fix the state. I saw it happen in terraform multiple times I just want to know if eventually I will encounter this using pulumi.
👍 1