From 605f0584bdf5a51a0d254045999435ea4d269b4b Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 1 Aug 2025 06:18:03 +0200 Subject: [PATCH] feat(pulumi): add manual method for importing components and their children --- knowledge base/pulumi.md | 50 +++++++++++++++++++++++++++++++---- snippets/pulumi/commands.fish | 3 +++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/knowledge base/pulumi.md b/knowledge base/pulumi.md index c46c536..383c048 100644 --- a/knowledge base/pulumi.md +++ b/knowledge base/pulumi.md @@ -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'`.
+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. - -
+
1. Write some code that would create the components: @@ -1307,6 +1306,47 @@ Simplify the process by leveraging the [`preview`][pulumi preview] command.
+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 …`. + +
+ +```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' + ``` + +
+ ## Troubleshooting ### A project with the same name already exists diff --git a/snippets/pulumi/commands.fish b/snippets/pulumi/commands.fish index a55ae54..c8ae3ca 100644 --- a/snippets/pulumi/commands.fish +++ b/snippets/pulumi/commands.fish @@ -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