terraform: only include variables in graph if count of a resource
depends
This commit is contained in:
parent
6b2e0b938d
commit
6752ccfe10
|
@ -62,7 +62,7 @@ func (n *GraphNodeConfigOutput) Proxy() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GraphNodeDestroyEdgeInclude impl.
|
// GraphNodeDestroyEdgeInclude impl.
|
||||||
func (n *GraphNodeConfigOutput) DestroyEdgeInclude(bool) bool {
|
func (n *GraphNodeConfigOutput) DestroyEdgeInclude(dag.Vertex) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,12 @@ import (
|
||||||
"github.com/hashicorp/terraform/dot"
|
"github.com/hashicorp/terraform/dot"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GraphNodeCountDependent is implemented by resources for giving only
|
||||||
|
// the dependencies they have from the "count" field.
|
||||||
|
type GraphNodeCountDependent interface {
|
||||||
|
CountDependentOn() []string
|
||||||
|
}
|
||||||
|
|
||||||
// GraphNodeConfigResource represents a resource within the config graph.
|
// GraphNodeConfigResource represents a resource within the config graph.
|
||||||
type GraphNodeConfigResource struct {
|
type GraphNodeConfigResource struct {
|
||||||
Resource *config.Resource
|
Resource *config.Resource
|
||||||
|
@ -31,6 +37,18 @@ func (n *GraphNodeConfigResource) DependableName() []string {
|
||||||
return []string{n.Resource.Id()}
|
return []string{n.Resource.Id()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GraphNodeCountDependent impl.
|
||||||
|
func (n *GraphNodeConfigResource) CountDependentOn() []string {
|
||||||
|
result := make([]string, 0, len(n.Resource.RawCount.Variables))
|
||||||
|
for _, v := range n.Resource.RawCount.Variables {
|
||||||
|
if vn := varNameForVar(v); vn != "" {
|
||||||
|
result = append(result, vn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// GraphNodeDependent impl.
|
// GraphNodeDependent impl.
|
||||||
func (n *GraphNodeConfigResource) DependentOn() []string {
|
func (n *GraphNodeConfigResource) DependentOn() []string {
|
||||||
result := make([]string, len(n.Resource.DependsOn),
|
result := make([]string, len(n.Resource.DependsOn),
|
||||||
|
|
|
@ -56,14 +56,23 @@ func (n *GraphNodeConfigVariable) VariableName() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GraphNodeDestroyEdgeInclude impl.
|
// GraphNodeDestroyEdgeInclude impl.
|
||||||
func (n *GraphNodeConfigVariable) DestroyEdgeInclude(full bool) bool {
|
func (n *GraphNodeConfigVariable) DestroyEdgeInclude(v dag.Vertex) bool {
|
||||||
// Don't include variables as dependencies in destroy nodes.
|
// Only include this variable in a destroy edge if the source vertex
|
||||||
// Destroy nodes don't interpolate anyways and this has a possibility
|
// "v" has a count dependency on this variable.
|
||||||
// to create cycles. See GH-1835
|
cv, ok := v.(GraphNodeCountDependent)
|
||||||
//
|
if !ok {
|
||||||
// We include the variable on non-full destroys because it might
|
return false
|
||||||
// be used for count interpolation.
|
}
|
||||||
return !full
|
|
||||||
|
for _, d := range cv.CountDependentOn() {
|
||||||
|
for _, d2 := range n.DependableName() {
|
||||||
|
if d == d2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GraphNodeProxy impl.
|
// GraphNodeProxy impl.
|
||||||
|
|
|
@ -49,7 +49,7 @@ type GraphNodeDestroyPrunable interface {
|
||||||
// as an edge within the destroy graph. This is usually done because it
|
// as an edge within the destroy graph. This is usually done because it
|
||||||
// might cause unnecessary cycles.
|
// might cause unnecessary cycles.
|
||||||
type GraphNodeDestroyEdgeInclude interface {
|
type GraphNodeDestroyEdgeInclude interface {
|
||||||
DestroyEdgeInclude(bool) bool
|
DestroyEdgeInclude(dag.Vertex) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DestroyTransformer is a GraphTransformer that creates the destruction
|
// DestroyTransformer is a GraphTransformer that creates the destruction
|
||||||
|
@ -114,7 +114,7 @@ func (t *DestroyTransformer) transform(
|
||||||
// If this thing specifically requests to not be depended on
|
// If this thing specifically requests to not be depended on
|
||||||
// by destroy nodes, then don't.
|
// by destroy nodes, then don't.
|
||||||
if i, ok := edgeRaw.(GraphNodeDestroyEdgeInclude); ok &&
|
if i, ok := edgeRaw.(GraphNodeDestroyEdgeInclude); ok &&
|
||||||
!i.DestroyEdgeInclude(t.FullDestroy) {
|
!i.DestroyEdgeInclude(v) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue