Skip to content

Commit 291110f

Browse files
committed
Don't use plans.Update for data sources
The new data source planning logic no longer needs a separate action, and the apply status can be determined from whether the After value is complete or not.
1 parent 8850d78 commit 291110f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

terraform/context_plan_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,16 +5053,16 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
50535053
"computed": cty.StringVal("data_id"),
50545054
}), ric.After)
50555055
case "data.aws_vpc.bar[0]":
5056-
if res.Action != plans.Update {
5057-
t.Fatalf("resource %s should be update, got %s", ric.Addr, ric.Action)
5056+
if res.Action != plans.Read {
5057+
t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action)
50585058
}
50595059
checkVals(t, objectVal(t, schema, map[string]cty.Value{
50605060
"id": cty.StringVal("data_id"),
50615061
"foo": cty.StringVal("0"),
50625062
}), ric.After)
50635063
case "data.aws_vpc.bar[1]":
5064-
if res.Action != plans.Update {
5065-
t.Fatalf("resource %s should be update, got %s", ric.Addr, ric.Action)
5064+
if res.Action != plans.Read {
5065+
t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action)
50665066
}
50675067
checkVals(t, objectVal(t, schema, map[string]cty.Value{
50685068
"id": cty.StringVal("data_id"),

terraform/eval_read_data_apply.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func (n *evalReadDataApply) Eval(ctx EvalContext) (interface{}, error) {
2929
return nil, fmt.Errorf("provider schema not available for %s", n.Addr)
3030
}
3131

32-
if planned != nil && !(planned.Action == plans.Read || planned.Action == plans.Update) {
32+
if planned != nil && planned.Action != plans.Read {
3333
// If any other action gets in here then that's always a bug; this
3434
// EvalNode only deals with reading.
3535
return nil, fmt.Errorf(
36-
"invalid action %s for %s: only Read or Update is supported (this is a bug in Terraform; please report it!)",
36+
"invalid action %s for %s: only Read is supported (this is a bug in Terraform; please report it!)",
3737
planned.Action, absAddr,
3838
)
3939
}
@@ -44,9 +44,9 @@ func (n *evalReadDataApply) Eval(ctx EvalContext) (interface{}, error) {
4444
return nil, err
4545
}
4646

47-
// we have a change and it is complete, which means we read the data
47+
// We have a change and it is complete, which means we read the data
4848
// source during plan and only need to store it in state.
49-
if planned.Action == plans.Update {
49+
if planned.After.IsWhollyKnown() {
5050
if err := ctx.Hook(func(h Hook) (HookAction, error) {
5151
return h.PostApply(absAddr, states.CurrentGen, planned.After, nil)
5252
}); err != nil {

terraform/eval_read_data_plan.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func (n *evalReadDataPlan) Eval(ctx EvalContext) (interface{}, error) {
8181
return nil, diags.ErrWithWarnings()
8282
}
8383

84+
// Apply detects that the data source will need to be read by the After
85+
// value containing unknowns from PlanDataResourceObject.
8486
*n.OutputChange = &plans.ResourceInstanceChange{
8587
Addr: absAddr,
8688
ProviderAddr: n.ProviderAddr,
@@ -124,12 +126,15 @@ func (n *evalReadDataPlan) Eval(ctx EvalContext) (interface{}, error) {
124126
return nil, diags.ErrWithWarnings()
125127
}
126128

127-
// Produce a change regardless of the outcome.
129+
// The returned value from ReadDataSource must be non-nil and known,
130+
// which we store in the change. Apply will use the fact that the After
131+
// value is wholly kown to save the state directly, rather than reading the
132+
// data source again.
128133
*n.OutputChange = &plans.ResourceInstanceChange{
129134
Addr: absAddr,
130135
ProviderAddr: n.ProviderAddr,
131136
Change: plans.Change{
132-
Action: plans.Update,
137+
Action: plans.Read,
133138
Before: priorVal,
134139
After: newVal,
135140
},

0 commit comments

Comments
 (0)