From 3994fa8c2298faeaee94c6d8730774b3c5c9064c Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Thu, 10 Dec 2020 13:31:45 +0000 Subject: [PATCH] Prevent panic when using `pulumi import` with local backend (#5906) Fixes: #5876 --- CHANGELOG.md | 3 +++ pkg/resource/deploy/import.go | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fbcdfe13..fce190e46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ CHANGELOG - Re-apply fix for running multiple `pulumi` processes concurrently. [#5893](https://github.com/pulumi/pulumi/issues/5893) + +- [cli] Prevent a panic when using `pulumi import` with local filesystems + [#5906](https://github.com/pulumi/pulumi/issues/5906) ## 2.15.4 (2020-12-08) diff --git a/pkg/resource/deploy/import.go b/pkg/resource/deploy/import.go index bcecf324b..47b0b8cdd 100644 --- a/pkg/resource/deploy/import.go +++ b/pkg/resource/deploy/import.go @@ -129,17 +129,19 @@ func (i *importer) wait(ctx context.Context, token completionToken) bool { } func (i *importer) registerExistingResources(ctx context.Context) bool { - // Issue same steps per existing resource to make sure that they are recorded in the snapshot. - // We issue these steps serially s.t. the resources remain in the order in which they appear in the state. - for _, r := range i.deployment.prev.Resources { - if r.Delete { - continue - } + if i != nil && i.deployment != nil && i.deployment.prev != nil { + // Issue same steps per existing resource to make sure that they are recorded in the snapshot. + // We issue these steps serially s.t. the resources remain in the order in which they appear in the state. + for _, r := range i.deployment.prev.Resources { + if r.Delete { + continue + } - new := *r - new.ID = "" - if !i.executeSerial(ctx, NewSameStep(i.deployment, noopEvent(0), r, &new)) { - return false + new := *r + new.ID = "" + if !i.executeSerial(ctx, NewSameStep(i.deployment, noopEvent(0), r, &new)) { + return false + } } } return true