Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeDestroyResource needs to be referencable #23822

Merged
merged 2 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions terraform/node_resource_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,43 @@ func (n *NodeDestroyResourceInstance) EvalTree() EvalNode {
// leaving skeleton resource objects in state after their instances have
// all been destroyed.
type NodeDestroyResource struct {
NodeAbstractResource *NodeAbstractResource
*NodeAbstractResource
}

var (
_ GraphNodeEvalable = (*NodeDestroyResource)(nil)
_ GraphNodeResource = (*NodeDestroyResource)(nil)
_ GraphNodeReferenceable = (*NodeDestroyResource)(nil)
_ GraphNodeReferencer = (*NodeDestroyResource)(nil)
_ GraphNodeEvalable = (*NodeDestroyResource)(nil)

// FIXME: this is here to document that this node is both
// GraphNodeProviderConsumer by virtue of the embedded
// NodeAbstractResource, but that behavior is not desired and we skip it by
// checking for GraphNodeNoProvider.
_ GraphNodeProviderConsumer = (*NodeDestroyResource)(nil)
_ GraphNodeNoProvider = (*NodeDestroyResource)(nil)
)

func (n *NodeDestroyResource) Name() string {
return n.NodeAbstractResource.ResourceAddr().String() + " (clean up state)"
return n.ResourceAddr().String() + " (clean up state)"
}

// GraphNodeReferenceable, overriding NodeAbstractResource
func (n *NodeDestroyResource) ReferenceableAddrs() []addrs.Referenceable {
// NodeDestroyResource doesn't participate in references: the graph
// builder that created it should ensure directly that it already depends
// on every other node related to its resource, without relying on
// references.
return nil
}

// GraphNodeReferencer, overriding NodeAbstractResource
func (n *NodeDestroyResource) References() []*addrs.Reference {
// NodeDestroyResource doesn't participate in references: the graph
// builder that created it should ensure directly that it already depends
// on every other node related to its resource, without relying on
// references.
return nil
}

// GraphNodeEvalable
Expand All @@ -295,6 +323,26 @@ func (n *NodeDestroyResource) EvalTree() EvalNode {
// leftover husk of a resource in state after all of the child instances
// and their objects were destroyed.
return &EvalForgetResourceState{
Addr: n.NodeAbstractResource.ResourceAddr().Resource,
Addr: n.ResourceAddr().Resource,
}
}

// GraphNodeResource
func (n *NodeDestroyResource) ResourceAddr() addrs.AbsResource {
return n.NodeAbstractResource.ResourceAddr()
}

// GraphNodeSubpath
func (n *NodeDestroyResource) Path() addrs.ModuleInstance {
return n.NodeAbstractResource.Path()
}

// GraphNodeNoProvider
// FIXME: this should be removed once the node can be separated from the
// Internal NodeAbstractResource behavior.
func (n *NodeDestroyResource) NoProvider() {
}

type GraphNodeNoProvider interface {
NoProvider()
}
14 changes: 14 additions & 0 deletions terraform/transform_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func (t *ProviderTransformer) Transform(g *Graph) error {
needConfigured := map[string]addrs.AbsProviderConfig{}
for _, v := range g.Vertices() {

// FIXME: fix the type that implements this, so it's not a
// GraphNodeProviderConsumer.
// check if we want to skip connecting this to a provider
if _, ok := v.(GraphNodeNoProvider); ok {
continue
}

// Does the vertex _directly_ use a provider?
if pv, ok := v.(GraphNodeProviderConsumer); ok {
requested[v] = make(map[string]ProviderRequest)
Expand Down Expand Up @@ -275,6 +282,13 @@ func (t *MissingProviderTransformer) Transform(g *Graph) error {
var err error
m := providerVertexMap(g)
for _, v := range g.Vertices() {
// FIXME: fix the type that implements this, so it's not a
// GraphNodeProviderConsumer.
// check if we want to skip connecting this to a provider
if _, ok := v.(GraphNodeNoProvider); ok {
continue
}

pv, ok := v.(GraphNodeProviderConsumer)
if !ok {
continue
Expand Down