core: don't advertise data source destroy via hooks

The fact that we clean up data source state by applying a "destroy" action
for them is an implementation detail, and so should not be visible to
outside callers or to the user.

Signalling these as real destroys creates confusion for users because
they see Terraform say things like:

    data.template_file.foo: Refreshing state..."

...which, to an understandably-nervous sysadmin, might make them suspect
that the underlying object was deleted, rather than just Terraform's
record of it.
This commit is contained in:
Martin Atkins 2017-08-23 17:23:33 -07:00
parent d4efc95191
commit 6712192724
1 changed files with 18 additions and 2 deletions

View File

@ -112,7 +112,7 @@ func (n *EvalApplyPre) Eval(ctx EvalContext) (interface{}, error) {
}
state.init()
{
if resourceHasUserVisibleApply(n.Info) {
// Call post-apply hook
err := ctx.Hook(func(h Hook) (HookAction, error) {
return h.PreApply(n.Info, state, diff)
@ -136,7 +136,7 @@ type EvalApplyPost struct {
func (n *EvalApplyPost) Eval(ctx EvalContext) (interface{}, error) {
state := *n.State
{
if resourceHasUserVisibleApply(n.Info) {
// Call post-apply hook
err := ctx.Hook(func(h Hook) (HookAction, error) {
return h.PostApply(n.Info, state, *n.Error)
@ -149,6 +149,22 @@ func (n *EvalApplyPost) Eval(ctx EvalContext) (interface{}, error) {
return nil, *n.Error
}
// resourceHasUserVisibleApply returns true if the given resource is one where
// apply actions should be exposed to the user.
//
// Certain resources do apply actions only as an implementation detail, so
// these should not be advertised to code outside of this package.
func resourceHasUserVisibleApply(info *InstanceInfo) bool {
addr := info.ResourceAddress()
// Only managed resources have user-visible apply actions.
// In particular, this excludes data resources since we "apply" these
// only as an implementation detail of removing them from state when
// they are destroyed. (When reading, they don't get here at all because
// we present them as "Refresh" actions.)
return addr.Mode == config.ManagedResourceMode
}
// EvalApplyProvisioners is an EvalNode implementation that executes
// the provisioners for a resource.
//