Pulumi Import Resource Not Managed After Import
In this tutorial, you'll learn about Pulumi Import Resource Not Managed After Import. We cover key concepts, practical examples, and best practices.
A pulumi import command completes but the resource is not managed in the target stack.
Wrong ❌
# Wrong: importing without specifying the full resource name
pulumi import aws:ec2/instance:Instance my-server i-abc123def456
# But the code defines a different logical name
Wrong Output
error: could not find resource 'my-server' in the Pulumi program
Resource 'my-server' does not exist in the current stack.
To import, the resource must already exist in the Pulumi program with the same logical name.
Right ✅
# Step 1: Add the resource to your Pulumi program
const server = new aws.ec2.Instance("my-server", {
instanceType: "t3.micro",
ami: "ami-0c55b159cbfafe1f0",
// Other properties as needed
});
# Step 2: Import the existing resource
pulumi import aws:ec2/instance:Instance my-server i-abc123def456
# Step 3: Run pulumi up to reconcile
pulumi up
# Step 4: Verify the state
pulumi stack export | grep -A5 '"urn":.*my-server'
Right Output
Importing (dev):
aws:ec2/instance:Instance (my-server):
id: i-abc123def456
urn: urn:pulumi:dev::my-project::aws:ec2/instance:Instance::my-server
Status: imported
Updating (dev):
aws:ec2/instance:Instance (my-server):
Status: unchanged
Prevention
- Always define the resource in your Pulumi program before running pulumi import.
- Match the logical resource name in code with the one used in the import command.
- Run pulumi preview after import to see if any properties will be updated.
- Use pulumi state show to verify the imported resource state.
- For bulk imports, use the --import flag on individual resources in the Pulumi program itself.
DodaTech applies similar defensive patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro infrastructure for production reliability.
Common Mistakes with import resource
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world PULUMI code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
This quick fix is part of the DodaTech infrastructure engineering series. Learn more at DodaTech tutorials.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro