https://pulumi.com logo
#general
Title
# general
h

helpful-processor-86468

03/31/2020, 1:50 PM
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

billowy-army-68599

03/31/2020, 2:02 PM
Hey @helpful-processor-86468 - can you post your code and/or the error messaging you're receiving?
h

helpful-processor-86468

03/31/2020, 2:07 PM
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

adorable-action-51248

03/31/2020, 2:18 PM
had similar issues.
i am generally running
pulumi up --refresh
which takes longer
does more than it should
but it fails less often.
h

helpful-processor-86468

03/31/2020, 2:19 PM
Less often? 🙂 That doesn't sound very reassuring.
a

adorable-action-51248

03/31/2020, 2:20 PM
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

helpful-processor-86468

03/31/2020, 2:23 PM
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

adorable-action-51248

03/31/2020, 2:25 PM
oh. interesting. i didn’t know these are different ? 😅
h

helpful-processor-86468

03/31/2020, 2:26 PM
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

adorable-action-51248

03/31/2020, 2:26 PM
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

green-school-95910

03/31/2020, 2:55 PM
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

helpful-processor-86468

03/31/2020, 3:02 PM
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