From 67121927240da830c12e366a0e1bd13bc65f3acb Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 23 Aug 2017 17:23:33 -0700 Subject: [PATCH] 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. --- terraform/eval_apply.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 2f6a4973e..36c98458e 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -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. //