remove unused

This commit is contained in:
James Bardin 2020-11-30 17:42:08 -05:00
parent 11e5ab0376
commit 1b530b7d9d
11 changed files with 5 additions and 412 deletions

View File

@ -154,7 +154,7 @@ func evaluateForEachExpressionValue(expr hcl.Expression, ctx EvalContext, allowU
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid for_each set argument",
Detail: fmt.Sprintf(`The given "for_each" argument value is unsuitable: "for_each" sets must not contain null values.`),
Detail: `The given "for_each" argument value is unsuitable: "for_each" sets must not contain null values.`,
Subject: expr.Range().Ptr(),
Expression: expr,
EvalContext: hclCtx,

View File

@ -57,9 +57,6 @@ type evalReadData struct {
// determine if there are any changes that will force this data sources to
// be deferred to apply.
dependsOn []addrs.ConfigResource
// forceDependsOn indicates that resources may be missing from dependsOn,
// but the parent module may have depends_on configured.
forceDependsOn bool
}
// readDataSource handles everything needed to call ReadDataSource on the provider.

View File

@ -176,18 +176,6 @@ func UpdateStateHook(ctx EvalContext) error {
return err
}
// evalWriteEmptyState wraps EvalWriteState to specifically record an empty
// state for a particular object.
type evalWriteEmptyState struct {
EvalWriteState
}
func (n *evalWriteEmptyState) Eval(ctx EvalContext) tfdiags.Diagnostics {
var state *states.ResourceInstanceObject
n.State = &state
return n.EvalWriteState.Eval(ctx)
}
// EvalWriteState is an EvalNode implementation that saves the given object
// as the current object for the selected resource instance.
type EvalWriteState struct {

View File

@ -235,18 +235,6 @@ var connectionBlockSupersetSchema = &configschema.Block{
},
}
// connectionBlockSupersetSchema is a schema representing the superset of all
// possible arguments for "connection" blocks across all supported connection
// types.
//
// This currently lives here because we've not yet updated our communicator
// subsystem to be aware of schema itself. It's exported only for use in the
// configs/configupgrade package and should not be used from anywhere else.
// The caller may not modify any part of the returned schema data structure.
func ConnectionBlockSupersetSchema() *configschema.Block {
return connectionBlockSupersetSchema
}
// EvalValidateResource validates the configuration of a resource.
type EvalValidateResource struct {
Addr addrs.Resource

View File

@ -145,7 +145,7 @@ func (d *evaluationStateData) GetCountAttr(addr addrs.CountAttr, rng tfdiags.Sou
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `Reference to "count" in non-counted context`,
Detail: fmt.Sprintf(`The "count" object can only be used in "module", "resource", and "data" blocks, and only when the "count" argument is set.`),
Detail: `The "count" object can only be used in "module", "resource", and "data" blocks, and only when the "count" argument is set.`,
Subject: rng.ToHCL().Ptr(),
})
return cty.UnknownVal(cty.Number), diags
@ -177,7 +177,7 @@ func (d *evaluationStateData) GetForEachAttr(addr addrs.ForEachAttr, rng tfdiags
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `each.value cannot be used in this context`,
Detail: fmt.Sprintf(`A reference to "each.value" has been used in a context in which it unavailable, such as when the configuration no longer contains the value in its "for_each" expression. Remove this reference to each.value in your configuration to work around this error.`),
Detail: `A reference to "each.value" has been used in a context in which it unavailable, such as when the configuration no longer contains the value in its "for_each" expression. Remove this reference to each.value in your configuration to work around this error.`,
Subject: rng.ToHCL().Ptr(),
})
return cty.UnknownVal(cty.DynamicPseudoType), diags
@ -196,7 +196,7 @@ func (d *evaluationStateData) GetForEachAttr(addr addrs.ForEachAttr, rng tfdiags
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `Reference to "each" in context without for_each`,
Detail: fmt.Sprintf(`The "each" object can be used only in "module" or "resource" blocks, and only when the "for_each" argument is set.`),
Detail: `The "each" object can be used only in "module" or "resource" blocks, and only when the "for_each" argument is set.`,
Subject: rng.ToHCL().Ptr(),
})
return cty.UnknownVal(cty.DynamicPseudoType), diags

View File

@ -1,9 +1,7 @@
package terraform
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/internal/logging"
@ -40,12 +38,6 @@ func (b *BasicGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Di
}
log.Printf("[TRACE] Executing graph transform %T", step)
stepName := fmt.Sprintf("%T", step)
dot := strings.LastIndex(stepName, ".")
if dot >= 0 {
stepName = stepName[dot+1:]
}
err := step.Transform(g)
if thisStepStr := g.StringWithNodeTypes(); thisStepStr != lastStepStr {
log.Printf("[TRACE] Completed graph transform %T with new graph:\n%s ------", step, logging.Indent(thisStepStr))

View File

@ -1,9 +0,0 @@
package terraform
import "github.com/hashicorp/terraform/dag"
// GraphDot returns the dot formatting of a visual representation of
// the given Terraform graph.
func GraphDot(g *Graph, opts *dag.DotOpts) (string, error) {
return string(g.Dot(opts)), nil
}

View File

@ -1,313 +0,0 @@
package terraform
import (
"strings"
"testing"
"github.com/hashicorp/terraform/dag"
)
func TestGraphDot(t *testing.T) {
cases := []struct {
Name string
Graph testGraphFunc
Opts dag.DotOpts
Expect string
Error string
}{
{
Name: "empty",
Graph: func() *Graph { return &Graph{} },
Expect: `
digraph {
compound = "true"
newrank = "true"
subgraph "root" {
}
}`,
},
{
Name: "three-level",
Graph: func() *Graph {
var g Graph
root := &testDrawableOrigin{"root"}
g.Add(root)
levelOne := []interface{}{"foo", "bar"}
for i, s := range levelOne {
levelOne[i] = &testDrawable{
VertexName: s.(string),
}
v := levelOne[i]
g.Add(v)
g.Connect(dag.BasicEdge(v, root))
}
levelTwo := []string{"baz", "qux"}
for i, s := range levelTwo {
v := &testDrawable{
VertexName: s,
}
g.Add(v)
g.Connect(dag.BasicEdge(v, levelOne[i]))
}
return &g
},
Expect: `
digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] bar"
"[root] baz"
"[root] foo"
"[root] qux"
"[root] root"
"[root] bar" -> "[root] root"
"[root] baz" -> "[root] foo"
"[root] foo" -> "[root] root"
"[root] qux" -> "[root] bar"
}
}
`,
},
{
Name: "cycle",
Opts: dag.DotOpts{
DrawCycles: true,
},
Graph: func() *Graph {
var g Graph
root := &testDrawableOrigin{"root"}
g.Add(root)
vA := g.Add(&testDrawable{
VertexName: "A",
})
vB := g.Add(&testDrawable{
VertexName: "B",
})
vC := g.Add(&testDrawable{
VertexName: "C",
})
g.Connect(dag.BasicEdge(vA, root))
g.Connect(dag.BasicEdge(vA, vC))
g.Connect(dag.BasicEdge(vB, vA))
g.Connect(dag.BasicEdge(vC, vB))
return &g
},
Expect: `
digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] A"
"[root] B"
"[root] C"
"[root] root"
"[root] A" -> "[root] B" [color = "red", penwidth = "2.0"]
"[root] A" -> "[root] C"
"[root] A" -> "[root] root"
"[root] B" -> "[root] A"
"[root] B" -> "[root] C" [color = "red", penwidth = "2.0"]
"[root] C" -> "[root] A" [color = "red", penwidth = "2.0"]
"[root] C" -> "[root] B"
}
}
`,
},
{
Name: "subgraphs, no depth restriction",
Opts: dag.DotOpts{
MaxDepth: -1,
},
Graph: func() *Graph {
var g Graph
root := &testDrawableOrigin{"root"}
g.Add(root)
var sub Graph
vSubRoot := sub.Add(&testDrawableOrigin{"sub_root"})
var subsub Graph
subsub.Add(&testDrawableOrigin{"subsub_root"})
vSubV := sub.Add(&testDrawableSubgraph{
VertexName: "subsub",
SubgraphMock: &subsub,
})
vSub := g.Add(&testDrawableSubgraph{
VertexName: "sub",
SubgraphMock: &sub,
})
g.Connect(dag.BasicEdge(vSub, root))
sub.Connect(dag.BasicEdge(vSubV, vSubRoot))
return &g
},
Expect: `
digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] root"
"[root] sub"
"[root] sub" -> "[root] root"
}
subgraph "cluster_sub" {
label = "sub"
"[sub] sub_root"
"[sub] subsub"
"[sub] subsub" -> "[sub] sub_root"
}
subgraph "cluster_subsub" {
label = "subsub"
"[subsub] subsub_root"
}
}
`,
},
{
Name: "subgraphs, with depth restriction",
Opts: dag.DotOpts{
MaxDepth: 1,
},
Graph: func() *Graph {
var g Graph
root := &testDrawableOrigin{"root"}
g.Add(root)
var sub Graph
rootSub := sub.Add(&testDrawableOrigin{"sub_root"})
var subsub Graph
subsub.Add(&testDrawableOrigin{"subsub_root"})
subV := sub.Add(&testDrawableSubgraph{
VertexName: "subsub",
SubgraphMock: &subsub,
})
vSub := g.Add(&testDrawableSubgraph{
VertexName: "sub",
SubgraphMock: &sub,
})
g.Connect(dag.BasicEdge(vSub, root))
sub.Connect(dag.BasicEdge(subV, rootSub))
return &g
},
Expect: `
digraph {
compound = "true"
newrank = "true"
subgraph "root" {
"[root] root"
"[root] sub"
"[root] sub" -> "[root] root"
}
subgraph "cluster_sub" {
label = "sub"
"[sub] sub_root"
"[sub] subsub"
"[sub] subsub" -> "[sub] sub_root"
}
}
`,
},
}
for _, tc := range cases {
tn := tc.Name
t.Run(tn, func(t *testing.T) {
g := tc.Graph()
var err error
//actual, err := GraphDot(g, &tc.Opts)
actual := string(g.Dot(&tc.Opts))
if err == nil && tc.Error != "" {
t.Fatalf("%s: expected err: %s, got none", tn, tc.Error)
}
if err != nil && tc.Error == "" {
t.Fatalf("%s: unexpected err: %s", tn, err)
}
if err != nil && tc.Error != "" {
if !strings.Contains(err.Error(), tc.Error) {
t.Fatalf("%s: expected err: %s\nto contain: %s", tn, err, tc.Error)
}
return
}
expected := strings.TrimSpace(tc.Expect) + "\n"
if actual != expected {
t.Fatalf("%s:\n\nexpected:\n%s\n\ngot:\n%s", tn, expected, actual)
}
})
}
}
type testGraphFunc func() *Graph
type testDrawable struct {
VertexName string
DependentOnMock []string
}
func (node *testDrawable) Name() string {
return node.VertexName
}
func (node *testDrawable) DotNode(n string, opts *dag.DotOpts) *dag.DotNode {
return &dag.DotNode{Name: n, Attrs: map[string]string{}}
}
func (node *testDrawable) DependableName() []string {
return []string{node.VertexName}
}
func (node *testDrawable) DependentOn() []string {
return node.DependentOnMock
}
type testDrawableOrigin struct {
VertexName string
}
func (node *testDrawableOrigin) Name() string {
return node.VertexName
}
func (node *testDrawableOrigin) DotNode(n string, opts *dag.DotOpts) *dag.DotNode {
return &dag.DotNode{Name: n, Attrs: map[string]string{}}
}
func (node *testDrawableOrigin) DotOrigin() bool {
return true
}
func (node *testDrawableOrigin) DependableName() []string {
return []string{node.VertexName}
}
type testDrawableSubgraph struct {
VertexName string
SubgraphMock *Graph
DependentOnMock []string
}
func (node *testDrawableSubgraph) Name() string {
return node.VertexName
}
func (node *testDrawableSubgraph) Subgraph() dag.Grapher {
return node.SubgraphMock
}
func (node *testDrawableSubgraph) DotNode(n string, opts *dag.DotOpts) *dag.DotNode {
return &dag.DotNode{Name: n, Attrs: map[string]string{}}
}
func (node *testDrawableSubgraph) DependentOn() []string {
return node.DependentOnMock
}

View File

@ -68,37 +68,3 @@ func testGraphHappensBefore(t *testing.T, g *Graph, A, B string) {
"Expected %q before %q in:\n\n%s",
A, B, g.String())
}
type testGraphSubPath struct {
PathFn func() []string
}
func (v *testGraphSubPath) Path() []string { return v.PathFn() }
type testGraphDependable struct {
VertexName string
DependentOnMock []string
}
func (v *testGraphDependable) Name() string {
return v.VertexName
}
func (v *testGraphDependable) DependableName() []string {
return []string{v.VertexName}
}
func (v *testGraphDependable) DependentOn() []string {
return v.DependentOnMock
}
const testGraphAddStr = `
42
84
`
const testGraphConnectDepsStr = `
a
b
a
`

View File

@ -143,19 +143,3 @@ func (*NilHook) PostImportState(addr addrs.AbsResourceInstance, imported []provi
func (*NilHook) PostStateUpdate(new *states.State) (HookAction, error) {
return HookActionContinue, nil
}
// handleHook turns hook actions into panics. This lets you use the
// panic/recover mechanism in Go as a flow control mechanism for hook
// actions.
func handleHook(a HookAction, err error) {
if err != nil {
// TODO: handle errors
}
switch a {
case HookActionContinue:
return
case HookActionHalt:
panic(HookActionHalt)
}
}

View File

@ -62,7 +62,7 @@ func (n *NodeApplyableProvider) ValidateProvider(ctx EvalContext, provider provi
configSchema = &configschema.Block{}
}
configVal, configBody, evalDiags := ctx.EvaluateBlock(configBody, configSchema, nil, EvalDataForNoInstanceKey)
configVal, _, evalDiags := ctx.EvaluateBlock(configBody, configSchema, nil, EvalDataForNoInstanceKey)
diags = diags.Append(evalDiags)
if evalDiags.HasErrors() {
return diags