core: don't force data resource id diff to be empty

In an attempt to always show "id" as computed we were producing a
synthetic diff for it, but this causes problems when the id attribute for
a particular data source is actually settable in configuration, since it
masks the setting from the config and forces it to always be empty.

Instead, we'll set it conditionally so that a value provided in the config
can shine through when available.
This commit is contained in:
Martin Atkins 2016-05-22 07:55:39 -07:00
parent 7d2b51e6c5
commit ab29eca045
1 changed files with 10 additions and 7 deletions

View File

@ -47,14 +47,17 @@ func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
diff = new(InstanceDiff)
}
// id is always computed, because we're always "creating a new resource"
// if id isn't explicitly set then it's always computed, because we're
// always "creating a new resource".
diff.init()
diff.SetAttribute("id", &ResourceAttrDiff{
Old: "",
NewComputed: true,
RequiresNew: true,
Type: DiffAttrOutput,
})
if _, ok := diff.Attributes["id"]; !ok {
diff.SetAttribute("id", &ResourceAttrDiff{
Old: "",
NewComputed: true,
RequiresNew: true,
Type: DiffAttrOutput,
})
}
}
err = ctx.Hook(func(h Hook) (HookAction, error) {