remove unused

This commit is contained in:
James Bardin 2020-11-30 17:34:44 -05:00
parent 729c9b6f10
commit 810ab0386f
11 changed files with 0 additions and 426 deletions

View File

@ -43,10 +43,7 @@ func (n *nodeExpandApplyableResource) DynamicExpand(ctx EvalContext) (*Graph, er
expander := ctx.InstanceExpander() expander := ctx.InstanceExpander()
moduleInstances := expander.ExpandModule(n.Addr.Module) moduleInstances := expander.ExpandModule(n.Addr.Module)
var resources []addrs.AbsResource
for _, module := range moduleInstances { for _, module := range moduleInstances {
resAddr := n.Addr.Resource.Absolute(module)
resources = append(resources, resAddr)
g.Add(&NodeApplyableResource{ g.Add(&NodeApplyableResource{
NodeAbstractResource: n.NodeAbstractResource, NodeAbstractResource: n.NodeAbstractResource,
Addr: n.Addr.Resource.Absolute(module), Addr: n.Addr.Resource.Absolute(module),

View File

@ -73,13 +73,11 @@ func (n *nodeExpandPlannableResource) DynamicExpand(ctx EvalContext) (*Graph, er
var g Graph var g Graph
expander := ctx.InstanceExpander() expander := ctx.InstanceExpander()
var resources []addrs.AbsResource
moduleInstances := expander.ExpandModule(n.Addr.Module) moduleInstances := expander.ExpandModule(n.Addr.Module)
// Add the current expanded resource to the graph // Add the current expanded resource to the graph
for _, module := range moduleInstances { for _, module := range moduleInstances {
resAddr := n.Addr.Resource.Absolute(module) resAddr := n.Addr.Resource.Absolute(module)
resources = append(resources, resAddr)
g.Add(&NodePlannableResource{ g.Add(&NodePlannableResource{
NodeAbstractResource: n.NodeAbstractResource, NodeAbstractResource: n.NodeAbstractResource,
Addr: resAddr, Addr: resAddr,
@ -172,11 +170,6 @@ func (n *NodePlannableResource) Name() string {
return n.Addr.String() return n.Addr.String()
} }
// GraphNodeModuleInstance
func (n *NodePlannableResource) ModuleInstance() addrs.ModuleInstance {
return n.Addr.Module
}
// GraphNodeExecutable // GraphNodeExecutable
func (n *NodePlannableResource) Execute(ctx EvalContext, op walkOperation) tfdiags.Diagnostics { func (n *NodePlannableResource) Execute(ctx EvalContext, op walkOperation) tfdiags.Diagnostics {
if n.Config == nil { if n.Config == nil {

View File

@ -1,22 +1,10 @@
package terraform package terraform
import ( import (
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/providers"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
) )
// testProviderComponentFactory creates a componentFactory that contains only
// a single given.
func testProviderComponentFactory(name string, provider providers.Interface) *basicComponentFactory {
return &basicComponentFactory{
providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider(name): providers.FactoryFixed(provider),
},
}
}
// mockProviderWithConfigSchema is a test helper to concisely create a mock // mockProviderWithConfigSchema is a test helper to concisely create a mock
// provider with the given schema for its own configuration. // provider with the given schema for its own configuration.
func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider { func mockProviderWithConfigSchema(schema *configschema.Block) *MockProvider {

View File

@ -274,10 +274,3 @@ func (ps *ProviderSchema) SchemaForResourceType(mode addrs.ResourceMode, typeNam
func (ps *ProviderSchema) SchemaForResourceAddr(addr addrs.Resource) (schema *configschema.Block, version uint64) { func (ps *ProviderSchema) SchemaForResourceAddr(addr addrs.Resource) (schema *configschema.Block, version uint64) {
return ps.SchemaForResourceType(addr.Mode, addr.Type) return ps.SchemaForResourceType(addr.Mode, addr.Type)
} }
// ProviderSchemaRequest is used to describe to a ResourceProvider which
// aspects of schema are required, when calling the GetSchema method.
type ProviderSchemaRequest struct {
ResourceTypes []string
DataSources []string
}

View File

@ -12,7 +12,6 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/convert"
"github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs" "github.com/hashicorp/terraform/configs"
@ -55,37 +54,6 @@ func TestMain(m *testing.M) {
os.Exit(m.Run()) os.Exit(m.Run())
} }
func tempDir(t *testing.T) string {
t.Helper()
dir, err := ioutil.TempDir("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("err: %s", err)
}
return dir
}
// tempEnv lets you temporarily set an environment variable. It returns
// a function to defer to reset the old value.
// the old value that should be set via a defer.
func tempEnv(t *testing.T, k string, v string) func() {
t.Helper()
old, oldOk := os.LookupEnv(k)
os.Setenv(k, v)
return func() {
if !oldOk {
os.Unsetenv(k)
} else {
os.Setenv(k, old)
}
}
}
func testModule(t *testing.T, name string) *configs.Config { func testModule(t *testing.T, name string) *configs.Config {
t.Helper() t.Helper()
c, _ := testModuleWithSnapshot(t, name) c, _ := testModuleWithSnapshot(t, name)
@ -208,20 +176,6 @@ func testSetResourceInstanceTainted(module *states.Module, resource, attrsJson,
) )
} }
// testSetResourceInstanceDeposed is a helper function for tests that sets a
// Deposed resource instance for the given module.
func testSetResourceInstanceDeposed(module *states.Module, resource, attrsJson, provider string, key states.DeposedKey) {
module.SetResourceInstanceDeposed(
mustResourceInstanceAddr(resource).Resource,
key,
&states.ResourceInstanceObjectSrc{
Status: states.ObjectTainted,
AttrsJSON: []byte(attrsJson),
},
mustProviderConfig(provider),
)
}
func testProviderFuncFixed(rp providers.Interface) providers.Factory { func testProviderFuncFixed(rp providers.Interface) providers.Factory {
return func() (providers.Interface, error) { return func() (providers.Interface, error) {
return rp, nil return rp, nil
@ -266,22 +220,6 @@ func mustProviderConfig(s string) addrs.AbsProviderConfig {
return p return p
} }
func instanceObjectIdForTests(obj *states.ResourceInstanceObject) string {
v := obj.Value
if v.IsNull() || !v.IsKnown() {
return ""
}
idVal := v.GetAttr("id")
if idVal.IsNull() || !idVal.IsKnown() {
return ""
}
idVal, err := convert.Convert(idVal, cty.String)
if err != nil {
return "<invalid>" // placeholder value
}
return idVal.AsString()
}
// HookRecordApplyOrder is a test hook that records the order of applies // HookRecordApplyOrder is a test hook that records the order of applies
// by recording the PreApply event. // by recording the PreApply event.
type HookRecordApplyOrder struct { type HookRecordApplyOrder struct {
@ -320,21 +258,6 @@ func (h *HookRecordApplyOrder) PreApply(addr addrs.AbsResourceInstance, gen stat
// Below are all the constant strings that are the expected output for // Below are all the constant strings that are the expected output for
// various tests. // various tests.
const testTerraformInputProviderStr = `
aws_instance.bar:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
bar = override
foo = us-east-1
type = aws_instance
aws_instance.foo:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
bar = baz
num = 2
type = aws_instance
`
const testTerraformInputProviderOnlyStr = ` const testTerraformInputProviderOnlyStr = `
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo
@ -343,38 +266,6 @@ aws_instance.foo:
type = aws_instance type = aws_instance
` `
const testTerraformInputVarOnlyStr = `
aws_instance.foo:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
foo = us-east-1
type = aws_instance
`
const testTerraformInputVarOnlyUnsetStr = `
aws_instance.foo:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
bar = baz
foo = foovalue
type = aws_instance
`
const testTerraformInputVarsStr = `
aws_instance.bar:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
bar = override
foo = us-east-1
type = aws_instance
aws_instance.foo:
ID = foo
provider = provider["registry.terraform.io/hashicorp/aws"]
bar = baz
num = 2
type = aws_instance
`
const testTerraformApplyStr = ` const testTerraformApplyStr = `
aws_instance.bar: aws_instance.bar:
ID = foo ID = foo
@ -1171,199 +1062,6 @@ aws_instance.bar:
type = aws_instance type = aws_instance
` `
const testTerraformPlanStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => "2"
type: "" => "aws_instance"
CREATE: aws_instance.foo
num: "" => "2"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanComputedIdStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => "<computed>"
type: "" => "aws_instance"
CREATE: aws_instance.foo
foo: "" => "<computed>"
num: "" => "2"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanCountIndexZeroStr = `
DIFF:
CREATE: aws_instance.foo
foo: "" => "0"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanEmptyStr = `
DIFF:
CREATE: aws_instance.bar
CREATE: aws_instance.foo
STATE:
<no state>
`
const testTerraformPlanEscapedVarStr = `
DIFF:
CREATE: aws_instance.foo
foo: "" => "bar-${baz}"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanModulesStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => "2"
type: "" => "aws_instance"
CREATE: aws_instance.foo
num: "" => "2"
type: "" => "aws_instance"
module.child:
CREATE: aws_instance.foo
num: "" => "2"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanModuleCycleStr = `
DIFF:
CREATE: aws_instance.b
CREATE: aws_instance.c
some_input: "" => "<computed>"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanModuleInputStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => "2"
type: "" => "aws_instance"
module.child:
CREATE: aws_instance.foo
foo: "" => "42"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanModuleInputComputedStr = `
DIFF:
CREATE: aws_instance.bar
compute: "" => "foo"
compute_value: "" => "<computed>"
foo: "" => "<computed>"
type: "" => "aws_instance"
module.child:
CREATE: aws_instance.foo
foo: "" => "<computed>"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanModuleVarIntStr = `
DIFF:
module.child:
CREATE: aws_instance.foo
num: "" => "2"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanMultipleTaintStr = `
DIFF:
DESTROY/CREATE: aws_instance.bar
foo: "" => "2"
type: "" => "aws_instance"
STATE:
aws_instance.bar: (2 tainted)
ID = <not created>
Tainted ID 1 = baz
Tainted ID 2 = zip
aws_instance.foo:
ID = bar
num = 2
`
const testTerraformPlanVarMultiCountOneStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => "2"
type: "" => "aws_instance"
CREATE: aws_instance.foo
num: "" => "2"
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformInputHCL = `
hcl_instance.hcltest:
ID = foo
provider = provider["registry.terraform.io/hashicorp/hcl"]
bar.w = z
bar.x = y
foo.# = 2
foo.0 = a
foo.1 = b
type = hcl_instance
`
const testTerraformRefreshDataRefDataStr = ` const testTerraformRefreshDataRefDataStr = `
data.null_data_source.bar: data.null_data_source.bar:
ID = foo ID = foo

View File

@ -23,17 +23,6 @@ type GraphVertexTransformer interface {
Transform(dag.Vertex) (dag.Vertex, error) Transform(dag.Vertex) (dag.Vertex, error)
} }
// GraphTransformIf is a helper function that conditionally returns a
// GraphTransformer given. This is useful for calling inline a sequence
// of transforms without having to split it up into multiple append() calls.
func GraphTransformIf(f func() bool, then GraphTransformer) GraphTransformer {
if f() {
return then
}
return nil
}
type graphTransformerMulti struct { type graphTransformerMulti struct {
Transforms []GraphTransformer Transforms []GraphTransformer
} }

View File

@ -274,14 +274,6 @@ test_object.A (destroy)
test_object.B (destroy) test_object.B (destroy)
` `
const testTransformDestroyEdgeCreatorStr = `
test_object.A
test_object.A (destroy)
test_object.A (destroy)
test_object.B (destroy)
test_object.B (destroy)
`
const testTransformDestroyEdgeMultiStr = ` const testTransformDestroyEdgeMultiStr = `
test_object.A (destroy) test_object.A (destroy)
test_object.B (destroy) test_object.B (destroy)

View File

@ -225,7 +225,6 @@ func (t *ProviderTransformer) Transform(g *Graph) error {
if p, ok := target.(*graphNodeProxyProvider); ok { if p, ok := target.(*graphNodeProxyProvider); ok {
g.Remove(p) g.Remove(p)
target = p.Target() target = p.Target()
key = target.(GraphNodeProvider).ProviderAddr().String()
} }
log.Printf("[DEBUG] ProviderTransformer: %q (%T) needs %s", dag.VertexName(v), v, dag.VertexName(target)) log.Printf("[DEBUG] ProviderTransformer: %q (%T) needs %s", dag.VertexName(v), v, dag.VertexName(target))
@ -431,18 +430,6 @@ func providerVertexMap(g *Graph) map[string]GraphNodeProvider {
return m return m
} }
func closeProviderVertexMap(g *Graph) map[string]GraphNodeCloseProvider {
m := make(map[string]GraphNodeCloseProvider)
for _, v := range g.Vertices() {
if pv, ok := v.(GraphNodeCloseProvider); ok {
addr := pv.CloseProviderAddr()
m[addr.String()] = pv
}
}
return m
}
type graphNodeCloseProvider struct { type graphNodeCloseProvider struct {
Addr addrs.AbsProviderConfig Addr addrs.AbsProviderConfig
} }
@ -466,11 +453,6 @@ func (n *graphNodeCloseProvider) Execute(ctx EvalContext, op walkOperation) (dia
return diags.Append(ctx.CloseProvider(n.Addr)) return diags.Append(ctx.CloseProvider(n.Addr))
} }
// GraphNodeDependable impl.
func (n *graphNodeCloseProvider) DependableName() []string {
return []string{n.Name()}
}
func (n *graphNodeCloseProvider) CloseProviderAddr() addrs.AbsProviderConfig { func (n *graphNodeCloseProvider) CloseProviderAddr() addrs.AbsProviderConfig {
return n.Addr return n.Addr
} }

View File

@ -545,31 +545,6 @@ provider["registry.terraform.io/hashicorp/foo"] (close)
provider["registry.terraform.io/hashicorp/foo"] provider["registry.terraform.io/hashicorp/foo"]
` `
const testTransformDisableProviderBasicStr = `
module.child
provider["registry.terraform.io/hashicorp/aws"] (disabled)
var.foo
provider["registry.terraform.io/hashicorp/aws"] (close)
module.child
provider["registry.terraform.io/hashicorp/aws"] (disabled)
provider["registry.terraform.io/hashicorp/aws"] (disabled)
var.foo
`
const testTransformDisableProviderKeepStr = `
aws_instance.foo
provider["registry.terraform.io/hashicorp/aws"]
module.child
provider["registry.terraform.io/hashicorp/aws"]
var.foo
provider["registry.terraform.io/hashicorp/aws"]
provider["registry.terraform.io/hashicorp/aws"] (close)
aws_instance.foo
module.child
provider["registry.terraform.io/hashicorp/aws"]
var.foo
`
const testTransformModuleProviderConfigStr = ` const testTransformModuleProviderConfigStr = `
module.child.aws_instance.thing module.child.aws_instance.thing
provider["registry.terraform.io/hashicorp/aws"].foo provider["registry.terraform.io/hashicorp/aws"].foo

View File

@ -538,17 +538,3 @@ func ReferencesFromConfig(body hcl.Body, schema *configschema.Block) []*addrs.Re
refs, _ := lang.ReferencesInBlock(body, schema) refs, _ := lang.ReferencesInBlock(body, schema)
return refs return refs
} }
func modulePrefixStr(p addrs.ModuleInstance) string {
return p.String()
}
func modulePrefixList(result []string, prefix string) []string {
if prefix != "" {
for i, v := range result {
result[i] = fmt.Sprintf("%s.%s", prefix, v)
}
}
return result
}

View File

@ -309,25 +309,6 @@ B
A A
` `
const testTransformRefBackupStr = `
A
B
A
`
const testTransformRefBackupPrimaryStr = `
A
B
C
C
`
const testTransformRefModulePathStr = `
A
B
A
`
const testTransformRefPathStr = ` const testTransformRefPathStr = `
A A
B B