Skip to content
Latchkey

pulumi import: Usage & Common CI Errors

Bring existing cloud resources under Pulumi management.

pulumi import adopts a pre-existing resource into a stack’s state and generates the matching program code, so Pulumi manages it going forward instead of trying to create a duplicate.

What it does

pulumi import <type> <name> <id> reads the existing resource identified by <id>, records it in stack state under <name>, and prints the program code you should paste in. You can also import many resources at once from a JSON file with -f.

Common usage

Terminal
# Import a single resource, get generated code
pulumi import aws:s3/bucket:Bucket logs my-logs-bucket --stack acme/prod

# Bulk import from a file
pulumi import -f import.json --stack acme/prod

# Import without writing generated code to stdout
pulumi import aws:ec2/instance:Instance web i-0abc123 --generate-code=false

Common error in CI: resource id not found / code not added

import fails with "error: could not import resource ... resource does not exist" for a wrong ID/region, or a later pulumi up wants to recreate the resource because you imported state but never added the generated code to your program. Fix: pass the exact provider ID and ensure the runner’s provider config (region, project) matches; then copy the generated code into your program so up sees a match. Run pulumi preview after import and reconcile until it shows no changes.

Key options

OptionPurpose
<type> <name> <id>Import one resource
-f FILEBulk import from JSON
--generate-codeEmit program code (default true)
--protectMark imported resources protected
--stack NAMETarget stack

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →