https://pulumi.com logo
#python
Title
# python
s

sticky-bear-14421

11/10/2021, 2:49 PM
Maybe not Python specific, but I've got a question about importing a resource into the state. My particular problem is, I have two AWS accounts and my code uses a provider to configure resources in the second account. I cannot delete and recreate them easily, thus I have to import these, but how do I import resources located in a second account?
p

prehistoric-activity-61023

11/10/2021, 2:50 PM
you can specify the provider while importing the resources
s

sticky-bear-14421

11/10/2021, 2:50 PM
Do you have an example for this?
p

prehistoric-activity-61023

11/10/2021, 2:51 PM
do you already have a provider defined in the state for the second account?
s

sticky-bear-14421

11/10/2021, 2:53 PM
I thought yes, but my pulumi run said it will create it
But I can create a resource and remove it so the provider will be persisted in the state
p

prehistoric-activity-61023

11/10/2021, 2:54 PM
Create it then. You will need an existing provider instance if you want to easily import the resource.
you can create the provider itself, you don’t have to create any resources linked to it
Once you have a configured provider in the state, get its URN (you can find it using e.g.
pulumi stack --show-urns
). Once you have it, use
--provider
flag available in
pulumi import
command.
Example:
Copy code
pulumi import --provider my_provider_name='<PROVIDER>' github:index/repository:Repository just-a-test just-a-test
my_provider_name
can be anything AFAIK - it will just be used in generate code template (you can reuse the variable name you used for provider so the snippet will be adjusted to it out of the box)
make sure you provide
PROVIDER
within single quotes (URNs usually contain dollar signs and it breaks the shell substitution)
s

sticky-bear-14421

11/10/2021, 3:12 PM
Ok, thanks
Will give it a try
Will report later, got pulled into a meeting
@prehistoric-activity-61023 And of course I forgot to report back .. it did work 😁
🙌 1