From a28c93c3ce0f7067eb5f1f7dfb0721313308da87 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 2 May 2018 19:55:53 -0700 Subject: [PATCH] core: render variables, locals and outputs nicely in "terraform graph" --- terraform/node_local.go | 13 +++++++++++++ terraform/node_module_variable.go | 13 +++++++++++++ terraform/node_output.go | 24 ++++++++++++++++++++++++ terraform/node_root_variable.go | 13 +++++++++++++ 4 files changed, 63 insertions(+) diff --git a/terraform/node_local.go b/terraform/node_local.go index e59eeb339..de41fc5fc 100644 --- a/terraform/node_local.go +++ b/terraform/node_local.go @@ -3,6 +3,7 @@ package terraform import ( "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/configs" + "github.com/hashicorp/terraform/dag" "github.com/hashicorp/terraform/lang" ) @@ -21,6 +22,7 @@ var ( _ GraphNodeReferenceable = (*NodeLocal)(nil) _ GraphNodeReferencer = (*NodeLocal)(nil) _ GraphNodeEvalable = (*NodeLocal)(nil) + _ dag.GraphNodeDotter = (*NodeLocal)(nil) ) func (n *NodeLocal) Name() string { @@ -55,3 +57,14 @@ func (n *NodeLocal) EvalTree() EvalNode { Expr: n.Config.Expr, } } + +// dag.GraphNodeDotter impl. +func (n *NodeLocal) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { + return &dag.DotNode{ + Name: name, + Attrs: map[string]string{ + "label": n.Name(), + "shape": "note", + }, + } +} diff --git a/terraform/node_module_variable.go b/terraform/node_module_variable.go index a8013a976..02983d6a8 100644 --- a/terraform/node_module_variable.go +++ b/terraform/node_module_variable.go @@ -4,6 +4,7 @@ import ( "github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/configs" + "github.com/hashicorp/terraform/dag" "github.com/hashicorp/terraform/lang" "github.com/zclconf/go-cty/cty" ) @@ -25,6 +26,7 @@ var ( _ GraphNodeReferenceable = (*NodeApplyableModuleVariable)(nil) _ GraphNodeReferencer = (*NodeApplyableModuleVariable)(nil) _ GraphNodeEvalable = (*NodeApplyableModuleVariable)(nil) + _ dag.GraphNodeDotter = (*NodeApplyableModuleVariable)(nil) ) func (n *NodeApplyableModuleVariable) Name() string { @@ -138,3 +140,14 @@ func (n *NodeApplyableModuleVariable) EvalTree() EvalNode { }, } } + +// dag.GraphNodeDotter impl. +func (n *NodeApplyableModuleVariable) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { + return &dag.DotNode{ + Name: name, + Attrs: map[string]string{ + "label": n.Name(), + "shape": "note", + }, + } +} diff --git a/terraform/node_output.go b/terraform/node_output.go index df257b551..cd686a33a 100644 --- a/terraform/node_output.go +++ b/terraform/node_output.go @@ -24,6 +24,7 @@ var ( _ GraphNodeReferencer = (*NodeApplyableOutput)(nil) _ GraphNodeReferenceOutside = (*NodeApplyableOutput)(nil) _ GraphNodeEvalable = (*NodeApplyableOutput)(nil) + _ dag.GraphNodeDotter = (*NodeApplyableOutput)(nil) ) func (n *NodeApplyableOutput) Name() string { @@ -137,6 +138,17 @@ func (n *NodeApplyableOutput) EvalTree() EvalNode { } } +// dag.GraphNodeDotter impl. +func (n *NodeApplyableOutput) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { + return &dag.DotNode{ + Name: name, + Attrs: map[string]string{ + "label": n.Name(), + "shape": "note", + }, + } +} + // NodeDestroyableOutput represents an output that is "destroybale": // its application will remove the output from the state. type NodeDestroyableOutput struct { @@ -150,6 +162,7 @@ var ( _ GraphNodeTargetDownstream = (*NodeDestroyableOutput)(nil) _ GraphNodeReferencer = (*NodeDestroyableOutput)(nil) _ GraphNodeEvalable = (*NodeDestroyableOutput)(nil) + _ dag.GraphNodeDotter = (*NodeDestroyableOutput)(nil) ) func (n *NodeDestroyableOutput) Name() string { @@ -185,3 +198,14 @@ func (n *NodeDestroyableOutput) EvalTree() EvalNode { Addr: n.Addr.OutputValue, } } + +// dag.GraphNodeDotter impl. +func (n *NodeDestroyableOutput) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { + return &dag.DotNode{ + Name: name, + Attrs: map[string]string{ + "label": n.Name(), + "shape": "note", + }, + } +} diff --git a/terraform/node_root_variable.go b/terraform/node_root_variable.go index ba89135b5..1c302903d 100644 --- a/terraform/node_root_variable.go +++ b/terraform/node_root_variable.go @@ -3,6 +3,7 @@ package terraform import ( "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/configs" + "github.com/hashicorp/terraform/dag" ) // NodeRootVariable represents a root variable input. @@ -14,6 +15,7 @@ type NodeRootVariable struct { var ( _ GraphNodeSubPath = (*NodeRootVariable)(nil) _ GraphNodeReferenceable = (*NodeRootVariable)(nil) + _ dag.GraphNodeDotter = (*NodeApplyableModuleVariable)(nil) ) func (n *NodeRootVariable) Name() string { @@ -29,3 +31,14 @@ func (n *NodeRootVariable) Path() addrs.ModuleInstance { func (n *NodeRootVariable) ReferenceableAddrs() []addrs.Referenceable { return []addrs.Referenceable{n.Addr} } + +// dag.GraphNodeDotter impl. +func (n *NodeRootVariable) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { + return &dag.DotNode{ + Name: name, + Attrs: map[string]string{ + "label": n.Name(), + "shape": "note", + }, + } +}