I ran into an interesting issue yesterday while im...
# general
b
I ran into an interesting issue yesterday while importing a resource, and wanted to see if it was expected. Our stack uses an explicit AWS provider (so not the default one, which we’ve disabled since 3.23.0), and I need to import an RDS cluster. I ran the following command:
Copy code
pulumi import "aws:rds/cluster:Cluster" my-rds-cluster "rds-cluster-name"
and I got an error saying the RDS cluster did not exist. After a while, I figured out it was just using the implicit AWS credentials I have on my machine, which are going to our main account (which doesn’t have this resource in it), as opposed to our prod account. So I created a profile to our prod account (with assume role) and did:
Copy code
AWS_PROFILE=prod-account pulumi import "aws:rds/cluster:Cluster" my-rds-cluster "rds-cluster-name"
and then it “successfully” found and imported the cluster. I put it in quotes because it basically imported it under a new provider (I think the default one), which then conflicted with what I had in code so it wanted to re-create it. I manually exported the stack JSON, edited the provider reference, re-imported it and it was happy. With that in mind, my questions: 1. Is it expected that I would need to do something like the
AWS_PROFILE=prod-account
above? Should it not select the provider I have defined in my stack (or ask me which one I want to use)? 2. Is it expected that it imported it into the stack state with a brand new provider that didn’t exist before?
l
I consider all this to be expected, which is why I don't use
pulumi import
(we also use only non-default providers). I always write the code manually and use the
importId
opt when importing a resource.
IMO,
pulumi import
is a great shortcut but doesn't save that much time for experienced users. It's often just as fast to write the code by hand and import it. And if the resource is nested inside a component resource (which for me, it always is), then it's faster to do it manually, since I don't have to move the resource and alias it after importing.
b
@little-cartoon-10569 tell me more about
importId
😄
l
It's the original way imports were managed: it allows you to import an existing resource during normal
pulumi up
. It's an opt, whose value documented at the bottom of every resource doc page, and which you add during your import run of
pulumi up
, then remove immediately afterwards (so Pulumi doesn't try to import it again).
b
OMG this would have saved me a lot of time. 🤦
c
@fresh-librarian-41835 @freezing-flag-53289 ^^