Skip to content

Commit

Permalink
core: placeholder id for data resource instances
Browse files Browse the repository at this point in the history
The state.ID attribute doesn't really do anything useful for data resource
instances, because they get re-created from scratch on each read anyway.
Implementations may, if desired, set an id anyway... but if they don't,
we'll just provide a placeholder one to preserve the invariant without
requiring each implementation to run d.SetId("-") .
  • Loading branch information
apparentlymart committed May 8, 2016
1 parent 298853f commit be03d68
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions terraform/eval_read_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func (n *EvalReadData) Eval(ctx EvalContext) (interface{}, error) {
return nil, fmt.Errorf("%s: %s", n.Info.Id, err.Error())
}

// Instance id doesn't really do anything for data resources
// since we effectively re-create them on each read anyway, so
// if the implementation doesn't provide one we'll just set
// a placeholder to preserve the invariant that all resource
// instances must have a non-empty id.
if state.ID == "" {
state.ID = "-"
}

// Call post-refresh hook
err = ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostRefresh(n.Info, state)
Expand Down

0 comments on commit be03d68

Please sign in to comment.