11

I don't see any options in the documentation on how to delete imported resources from my stack. If I try to remove the resource's reference from my code I get the following error when running pulumi up:
error: Preview failed: refusing to delete protected resource 'urn:pulumi:dev::my-cloud-infrastructure::aws:iam/instanceProfile:InstanceProfile::EC2CodeDeploy'

Jonas
  • 121,568
  • 97
  • 310
  • 388
Teodoro
  • 1,194
  • 8
  • 22

2 Answers2

25

As answered in the Pulumi Slack community channel, one can use the command:
pulumi state delete <urn>

This will remove the reference from your state file but not from aws.

Also, if the resource is protected you'll first have to unprotect it or run the above command with the flag --force.

Teodoro
  • 1,194
  • 8
  • 22
10

For "bulkier" operations, you can export the stack as a JSON, delete the resources and import it back in (docs):

# Get the current stack as json:
pulumi stack export --file stack.json

# Delete what you don't want from your stack file and then:
pulumi stack import --file stack.json
GregK
  • 571
  • 6
  • 15