feat(pulumi): add manual method for importing components and their children

This commit is contained in:
Michele Cereda
2025-08-01 06:18:03 +02:00
parent dc73960ebc
commit 605f0584bd
2 changed files with 48 additions and 5 deletions

View File

@@ -1216,12 +1216,11 @@ The two approaches work in slightly different ways, and are suited to slightly d
### Import components and their children
Create an import file for the resources that would be created, then import them using `pulumi import --file
'import.json'`.
The best and usually easier solution is to create an import file for the resources that would be created, then import
them in block using `pulumi import --file 'import.json'`.<br/>
Simplify the process by leveraging the `--import-file` option of the [`preview`][pulumi preview] command.
Simplify the process by leveraging the [`preview`][pulumi preview] command.
<details style="padding-left: 1em">
<details style='padding: 0 0 1rem 1rem'>
1. Write some code that would create the components:
@@ -1307,6 +1306,47 @@ Simplify the process by leveraging the [`preview`][pulumi preview] command.
</details>
A manual alternative is to create the parent component, then import each child in the order they would be created by
using `pulumi import --parent …`.
<details style='padding: 0 0 1rem 1rem'>
```sh
$ pulumi preview
Previewing update (dev):
Type Name Plan Info
pulumi:pulumi:Stack someProj-dev 1 message
+ └─ someOrg:StandardSnowflakeServiceAccount n8n create
+ └─ snowflake:index:ServiceUser n8n create
+ └─ snowflake:index:UserProgrammaticAccessToken n8n create
Resources:
+ 3 to create
```
1. Create only the component resource:
```sh
pulumi up --suppress-outputs --target 'urn:pulumi:dev::someProj::someOrg:SnowflakeServiceAccount::n8n'
```
1. Import the component's direct children:
```sh
pulumi import 'snowflake:index/serviceUser:ServiceUser' 'n8n' 'N8N' \
--parent 'urn:pulumi:dev::someProj::someOrg:SnowflakeServiceAccount::n8n'
```
1. Import children of lower order:
```sh
pulumi import 'snowflake:index/userProgrammaticAccessToken:UserProgrammaticAccessToken' \
'n8n' 'N8N_SERVICE_USER|N8N_SERVICE_PAT' \
--parent 'urn:pulumi:dev::someProj::someOrg:SnowflakeServiceAccount$snowflake:index/serviceUser:ServiceUser::n8n'
```
</details>
## Troubleshooting
### A project with the same name already exists

View File

@@ -60,6 +60,9 @@ pulumi state unprotect 'urn:pulumi:dev::custom-images::aws:imagebuilder/infrastr
pulumi state delete 'urn:pulumi:dev::custom-images::aws:imagebuilder/infrastructureConfiguration:InfrastructureConfiguration::server-baseline'
pulumi state rename -y 'urn:pulumi:dev::custom-images::aws:imagebuilder/imageRecipe:ImageRecipe::baselineServerImage-1.0.8' 'serverBaseline-1.0.8'
pulumi state edit
EDITOR='vim' pulumi state edit
find '.' -type f -name 'Pulumi.yaml' -not -path "*/node_modules/*" -print -exec yq '.backend.url' {} '+'
find '.' -type f -name 'Pulumi.yaml' -not -path "*/node_modules/*" -exec dirname {} + | xargs -pn '1' pulumi install --cwd