Skip to content

Commit

Permalink
Don't use plans.Update for data sources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbardin committed May 13, 2020
1 parent 489d22e commit 0d93351
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions terraform/context_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5053,16 +5053,16 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) {
"computed": cty.StringVal("data_id"),
}), ric.After)
case "data.aws_vpc.bar[0]":
if res.Action != plans.Update {
t.Fatalf("resource %s should be update, got %s", ric.Addr, ric.Action)
if res.Action != plans.Read {
t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action)
}
checkVals(t, objectVal(t, schema, map[string]cty.Value{
"id": cty.StringVal("data_id"),
"foo": cty.StringVal("0"),
}), ric.After)
case "data.aws_vpc.bar[1]":
if res.Action != plans.Update {
t.Fatalf("resource %s should be update, got %s", ric.Addr, ric.Action)
if res.Action != plans.Read {
t.Fatalf("resource %s should be read, got %s", ric.Addr, ric.Action)
}
checkVals(t, objectVal(t, schema, map[string]cty.Value{
"id": cty.StringVal("data_id"),
Expand Down
8 changes: 4 additions & 4 deletions terraform/eval_read_data_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func (n *evalReadDataApply) Eval(ctx EvalContext) (interface{}, error) {
return nil, fmt.Errorf("provider schema not available for %s", n.Addr)
}

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

// we have a change and it is complete, which means we read the data
// We have a change and it is complete, which means we read the data
// source during plan and only need to store it in state.
if planned.Action == plans.Update {
if planned.After.IsWhollyKnown() {
if err := ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostApply(absAddr, states.CurrentGen, planned.After, nil)
}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion terraform/eval_read_data_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (n *evalReadDataPlan) Eval(ctx EvalContext) (interface{}, error) {
Addr: absAddr,
ProviderAddr: n.ProviderAddr,
Change: plans.Change{
Action: plans.Update,
Action: plans.Read,
Before: priorVal,
After: newVal,
},
Expand Down

0 comments on commit 0d93351

Please sign in to comment.