From a193836682aabd2f2fc7dca323b9da794efe6ff1 Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Tue, 8 Dec 2020 19:21:58 -0800 Subject: [PATCH] Fix new resource recording. (#5897) Record new resources after their operations have been run rather than before in order to ensure that all state is available and appropriately marked as secret. Fixes #5803. --- pkg/resource/deploy/builtins.go | 4 ---- pkg/resource/deploy/step_executor.go | 8 +++++++- pkg/resource/deploy/step_generator.go | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/resource/deploy/builtins.go b/pkg/resource/deploy/builtins.go index 0b25b64b6..856177cd4 100644 --- a/pkg/resource/deploy/builtins.go +++ b/pkg/resource/deploy/builtins.go @@ -272,10 +272,6 @@ func (p *builtinProvider) getResource(inputs resource.PropertyMap) (resource.Pro contract.Assert(ok) contract.Assert(urn.IsString()) - // #5803: track secret outputs in the resource map. This is necessary to ensure that the - // `additionalSecretOutputs` option that was provided when the resource was registered is properly respected by - // `getResource`. - state, ok := p.resources.get(resource.URN(urn.StringValue())) if !ok { return nil, errors.Errorf("unknown resource %v", urn.StringValue()) diff --git a/pkg/resource/deploy/step_executor.go b/pkg/resource/deploy/step_executor.go index 578a9ad92..2d1c96b66 100644 --- a/pkg/resource/deploy/step_executor.go +++ b/pkg/resource/deploy/step_executor.go @@ -282,7 +282,8 @@ func (se *stepExecutor) executeStep(workerID int, step Step) error { } } - // Ensure that any secrets properties in the output are marked as such. + // Ensure that any secrets properties in the output are marked as such and that the resource is tracked in the set + // of registered resources. if step.New() != nil { newState := step.New() for _, k := range newState.AdditionalSecretOutputs { @@ -290,6 +291,11 @@ func (se *stepExecutor) executeStep(workerID int, step Step) error { newState.Outputs[k] = resource.MakeSecret(v) } } + + // If this is not a resource that is managed by Pulumi, then we can ignore it. + if !newState.External && se.deployment.news != nil { + se.deployment.news.set(newState.URN, newState) + } } if events != nil { diff --git a/pkg/resource/deploy/step_generator.go b/pkg/resource/deploy/step_generator.go index 1d7f30f11..55cefceaf 100644 --- a/pkg/resource/deploy/step_generator.go +++ b/pkg/resource/deploy/step_generator.go @@ -254,7 +254,6 @@ func (sg *stepGenerator) generateSteps(event RegisterResourceEvent) ([]Step, res // Mark the URN/resource as having been seen. So we can run analyzers on all resources seen, as well as // lookup providers for calculating replacement of resources that use the provider. sg.resourceGoals[urn] = goal - sg.deployment.news.set(urn, new) if providers.IsProviderType(goal.Type) { sg.providers[urn] = new }