Skip to content

Commit 834e583

Browse files
authored
Revert "Propagate inputs to outputs during preview. (pulumi#3245)" (pulumi#3324)
This reverts commit 80504bf.
1 parent 5e1c4d3 commit 834e583

30 files changed

+152
-752
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ CHANGELOG
33

44
## HEAD (Unreleased)
55

6+
- Revert "propagate resource inputs to resource state during preview". These changes had a critical issue that needs
7+
further investigation.
8+
69
## 1.3.0 (2019-10-09)
710

811
- Propagate resource inputs to resource state during preview, including first-class unknown values. This allows the

pkg/engine/lifecycle_test.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,69 +4563,3 @@ func updateSpecificTargets(t *testing.T, targets []string) {
45634563

45644564
p.Run(t, old)
45654565
}
4566-
4567-
func TestPreviewInputPropagation(t *testing.T) {
4568-
loaders := []*deploytest.ProviderLoader{
4569-
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
4570-
return &deploytest.Provider{
4571-
CreateF: func(urn resource.URN,
4572-
news resource.PropertyMap, timeout float64) (resource.ID, resource.PropertyMap, resource.Status, error) {
4573-
4574-
return "created-id", news, resource.StatusOK, nil
4575-
},
4576-
}, nil
4577-
}),
4578-
}
4579-
4580-
preview := true
4581-
program := deploytest.NewLanguageRuntime(func(_ plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
4582-
computed := interface{}(resource.Computed{Element: resource.NewStringProperty("")})
4583-
if !preview {
4584-
computed = "alpha"
4585-
}
4586-
4587-
ins := resource.NewPropertyMapFromMap(map[string]interface{}{
4588-
"foo": "bar",
4589-
"baz": map[string]interface{}{
4590-
"a": 42,
4591-
"b": computed,
4592-
},
4593-
"qux": []interface{}{
4594-
computed,
4595-
24,
4596-
},
4597-
"zed": computed,
4598-
})
4599-
4600-
_, _, state, err := monitor.RegisterResource("pkgA:m:typA", "resA", true, deploytest.ResourceOptions{
4601-
Inputs: ins,
4602-
})
4603-
assert.NoError(t, err)
4604-
4605-
assert.True(t, state.DeepEquals(ins))
4606-
4607-
return nil
4608-
})
4609-
host := deploytest.NewPluginHost(nil, nil, program, loaders...)
4610-
4611-
p := &TestPlan{
4612-
Options: UpdateOptions{host: host},
4613-
}
4614-
4615-
project := p.GetProject()
4616-
4617-
// Run a preview. The inputs should be propagated to the outputs during the create.
4618-
preview = true
4619-
_, res := TestOp(Update).Run(project, p.GetTarget(nil), p.Options, preview, p.BackendClient, nil)
4620-
assert.Nil(t, res)
4621-
4622-
// Run an update.
4623-
preview = false
4624-
snap, res := TestOp(Update).Run(project, p.GetTarget(nil), p.Options, preview, p.BackendClient, nil)
4625-
assert.Nil(t, res)
4626-
4627-
// Run another preview. The inputs should be propagated to the outputs during the update.
4628-
preview = true
4629-
_, res = TestOp(Update).Run(project, p.GetTarget(snap), p.Options, preview, p.BackendClient, nil)
4630-
assert.Nil(t, res)
4631-
}

pkg/resource/deploy/deploytest/resourcemonitor.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ type ResourceMonitor struct {
2929
}
3030

3131
type ResourceOptions struct {
32-
Parent resource.URN
33-
Protect bool
34-
Dependencies []resource.URN
35-
Provider string
36-
Inputs resource.PropertyMap
37-
PropertyDeps map[resource.PropertyKey][]resource.URN
38-
DeleteBeforeReplace *bool
39-
Version string
40-
IgnoreChanges []string
41-
Aliases []resource.URN
42-
ImportID resource.ID
43-
CustomTimeouts *resource.CustomTimeouts
44-
SupportsPartialValues *bool
32+
Parent resource.URN
33+
Protect bool
34+
Dependencies []resource.URN
35+
Provider string
36+
Inputs resource.PropertyMap
37+
PropertyDeps map[resource.PropertyKey][]resource.URN
38+
DeleteBeforeReplace *bool
39+
Version string
40+
IgnoreChanges []string
41+
Aliases []resource.URN
42+
ImportID resource.ID
43+
CustomTimeouts *resource.CustomTimeouts
4544
}
4645

4746
func (rm *ResourceMonitor) RegisterResource(t tokens.Type, name string, custom bool,
@@ -95,10 +94,6 @@ func (rm *ResourceMonitor) RegisterResource(t tokens.Type, name string, custom b
9594
if opts.DeleteBeforeReplace != nil {
9695
deleteBeforeReplace = *opts.DeleteBeforeReplace
9796
}
98-
supportsPartialValues := true
99-
if opts.SupportsPartialValues != nil {
100-
supportsPartialValues = *opts.SupportsPartialValues
101-
}
10297
requestInput := &pulumirpc.RegisterResourceRequest{
10398
Type: string(t),
10499
Name: name,
@@ -116,7 +111,6 @@ func (rm *ResourceMonitor) RegisterResource(t tokens.Type, name string, custom b
116111
Aliases: aliasStrings,
117112
ImportId: string(opts.ImportID),
118113
CustomTimeouts: &timeouts,
119-
SupportsPartialValues: supportsPartialValues,
120114
}
121115

122116
// submit request

pkg/resource/deploy/source.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ type RegisterResourceEvent interface {
8888

8989
// RegisterResult is the state of the resource after it has been registered.
9090
type RegisterResult struct {
91-
State *resource.State // the resource state.
91+
State *resource.State // the resource state.
92+
Stable bool // if true, the resource state is stable and may be trusted.
93+
Stables []resource.PropertyKey // an optional list of specific resource properties that are stable.
9294
}
9395

9496
// RegisterResourceOutputsEvent is an event that asks the engine to complete the provisioning of a resource.

pkg/resource/deploy/source_eval.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -810,26 +810,19 @@ func (rm *resmon) RegisterResource(ctx context.Context,
810810
return nil, rpcerror.New(codes.Unavailable, "resource monitor shut down while waiting on step's done channel")
811811
}
812812

813-
// Filter out partially-known values if the requestor does not support them.
814-
state, outputs := result.State, result.State.Outputs
815-
if !req.GetSupportsPartialValues() {
816-
logging.V(5).Infof("stripping unknowns from RegisterResource response for urn %v", state.URN)
817-
filtered := resource.PropertyMap{}
818-
for k, v := range outputs {
819-
if !v.ContainsUnknowns() {
820-
filtered[k] = v
821-
}
822-
}
823-
outputs = filtered
813+
state := result.State
814+
stable := result.Stable
815+
var stables []string
816+
for _, sta := range result.Stables {
817+
stables = append(stables, string(sta))
824818
}
825-
826819
logging.V(5).Infof(
827-
"ResourceMonitor.RegisterResource operation finished: t=%v, urn=%v, #outs=%v",
828-
state.Type, state.URN, len(outputs))
820+
"ResourceMonitor.RegisterResource operation finished: t=%v, urn=%v, stable=%v, #stables=%v #outs=%v",
821+
state.Type, state.URN, stable, len(stables), len(state.Outputs))
829822

830823
// Finally, unpack the response into properties that we can return to the language runtime. This mostly includes
831824
// an ID, URN, and defaults and output properties that will all be blitted back onto the runtime object.
832-
obj, err := plugin.MarshalProperties(outputs, plugin.MarshalOptions{
825+
obj, err := plugin.MarshalProperties(state.Outputs, plugin.MarshalOptions{
833826
Label: label,
834827
KeepUnknowns: true,
835828
KeepSecrets: req.GetAcceptSecrets(),
@@ -838,9 +831,11 @@ func (rm *resmon) RegisterResource(ctx context.Context,
838831
return nil, err
839832
}
840833
return &pulumirpc.RegisterResourceResponse{
841-
Urn: string(state.URN),
842-
Id: string(state.ID),
843-
Object: obj,
834+
Urn: string(state.URN),
835+
Id: string(state.ID),
836+
Object: obj,
837+
Stable: stable,
838+
Stables: stables,
844839
}, nil
845840
}
846841

pkg/resource/deploy/step.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (s *SameStep) Apply(preview bool) (resource.Status, StepCompleteFunc, error
9898
// Retain the ID, and outputs:
9999
s.new.ID = s.old.ID
100100
s.new.Outputs = s.old.Outputs
101-
complete := func() { s.reg.Done(&RegisterResult{State: s.new}) }
101+
complete := func() { s.reg.Done(&RegisterResult{State: s.new, Stable: true}) }
102102
return resource.StatusOK, complete, nil
103103
}
104104

@@ -208,8 +208,6 @@ func (s *CreateStep) Apply(preview bool) (resource.Status, StepCompleteFunc, err
208208
s.new.ID = id
209209
s.new.Outputs = outs
210210
}
211-
} else {
212-
s.new.Outputs = s.new.Inputs
213211
}
214212

215213
// Mark the old resource as pending deletion if necessary.
@@ -435,12 +433,10 @@ func (s *UpdateStep) Apply(preview bool) (resource.Status, StepCompleteFunc, err
435433
// Now copy any output state back in case the update triggered cascading updates to other properties.
436434
s.new.Outputs = outs
437435
}
438-
} else {
439-
s.new.Outputs = s.new.Inputs
440436
}
441437

442438
// Finally, mark this operation as complete.
443-
complete := func() { s.reg.Done(&RegisterResult{State: s.new}) }
439+
complete := func() { s.reg.Done(&RegisterResult{State: s.new, Stables: s.stables}) }
444440
if resourceError == nil {
445441
return resourceStatus, complete, nil
446442
}

0 commit comments

Comments
 (0)