pulumi: Add "how to fix" instructions for "already exists" errors

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we’ll work with you on design, scheduling, etc.)

Issue details

When running pulumi up and getting an “already exists” error. It would be useful to also provide additional helpful messages for how to resolve such error. An example message may be:

To resolve this error, you can:

1. Change the name of your locally declared resource.
2. Import the resource.
3. Manually delete the external resource from the provider and rerun.

To Import, run this (though the variables here should actually be filled out, as pulumi already knows exactly what values should exist):

pulumi import [type] [name] [id] --parent [parent] --provider [provider]


### Affected area/feature

CLI

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 14
  • Comments: 15 (6 by maintainers)

Most upvoted comments

This is the worst thing about pulumi. When i am developing infra and something fails in a odd way (as often happens when developing) pulumi cannot recover automatically from the situation and the commands to fix things are baroque. Or maybe they are very easy but there is no documentation.

I am a long time user of terraform and in this regard pulumi is very much worse

Concrete example. We can work around this to a degree by doing the following:

var resourceGroup = new ResourceGroup("ResourceGroup", new()
{
    ResourceGroupName = resourceGroupName,
    Location = location
}, new()
{
    ImportId = importing
        ? (await GetResourceGroup.InvokeAsync(new() { ResourceGroupName = resourceGroupName })).Id
        : null
});

But this requires telling pulumi when you are importing and is a one off. It would be nice to do something like:

var resourceGroup = new ResourceGroup("ResourceGroup", new()
{
    ResourceGroupName = resourceGroupName,
    Location = location
}, new()
{
    AutoImportWhenNotInStackButDoesExist = true
});

Or even just be able to set that globally.

I have the same issue for some resource such as create cloud flare record and create ecr user resources.

If two developers are working separately with Pulumi in local mode, and one of them has already created a resource such as a Cloudflare record or an ECR user, the other developer may encounter this error when running Pulumi up. This error occurs because the resource already exists and cannot be created again.

I think this error occurs because the second developer does not have that resource in their state.

I would like the Pulumi refresh command to synchronize the stack and update the state in order to prevent this error from occurring.

Diagnostics:
  pulumi:pulumi:Stack (devops-dev):
    error: update failed
    error: Resource monitor has terminated, shutting down

  aws:iam:User (ecr-user):
    error: 1 error occurred:
    	* creating IAM User (ecr-user): EntityAlreadyExists: User with name ecr-user already exists.
    	status code: 409, request id: ***

#3388

this 409 issue is exactly why i’m switching back to terraform.

Again, I’m confused because as I understand it Terraform is exactly the same in this regard!?

Both systems will error if you try to create something that already exists, you can’t create a new S3 bucket called “foo”, if that bucket already exists. In fact if anything Pulumi should be better here because by default we suffix names with random characters to avoid name collisions.

So what is Terraform doing here that’s better than us? I don’t think it’s the idea in the first post on this issue, although I do think that’s a good idea.

I mean when running Pulumi up, specifying a resource, with a name, or ID, etc that already exists. Pulumi will fail to create the resource because of the conflict. Leading me to usually either import or change the name of the locally declared resource.