terraform: an incredible number of failing tests!

This commit is contained in:
Mitchell Hashimoto 2016-09-13 14:34:15 -07:00
parent 3f090df26e
commit 77b9177bd5
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 42 additions and 5 deletions

View File

@ -353,8 +353,20 @@ func (c *Context) Apply() (*State, error) {
// Copy our own state // Copy our own state
c.state = c.state.DeepCopy() c.state = c.state.DeepCopy()
// Build the graph // Build the graph. If it is a destroy operation, we use the
graph, err := c.Graph(&ContextGraphOpts{Validate: true}) // standard graph builder. If it is an apply operation, we use
// our new graph builder.
var graph *Graph
var err error
if c.destroy {
graph, err = c.Graph(&ContextGraphOpts{Validate: true})
} else {
graph, err = (&ApplyGraphBuilder{
Diff: c.diff,
Providers: c.providersList(),
Provisioners: c.provisionersList(),
}).Build(RootModulePath)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -709,6 +721,24 @@ func (c *Context) walk(
return walker, realErr return walker, realErr
} }
func (c *Context) providersList() []string {
providers := make([]string, 0, len(c.providers))
for k, _ := range c.providers {
providers = append(providers, k)
}
return providers
}
func (c *Context) provisionersList() []string {
provisioners := make([]string, 0, len(c.provisioners))
for k, _ := range c.provisioners {
provisioners = append(provisioners, k)
}
return provisioners
}
// parseVariableAsHCL parses the value of a single variable as would have been specified // parseVariableAsHCL parses the value of a single variable as would have been specified
// on the command line via -var or in an environment variable named TF_VAR_x, where x is // on the command line via -var or in an environment variable named TF_VAR_x, where x is
// the name of the variable. In order to get around the restriction of HCL requiring a // the name of the variable. In order to get around the restriction of HCL requiring a

View File

@ -1751,7 +1751,7 @@ func TestContext2Apply_multiVar(t *testing.T) {
actual := state.RootModule().Outputs["output"] actual := state.RootModule().Outputs["output"]
expected := "bar0,bar1,bar2" expected := "bar0,bar1,bar2"
if actual.Value != expected { if actual == nil || actual.Value != expected {
t.Fatalf("bad: \n%s", actual) t.Fatalf("bad: \n%s", actual)
} }
@ -4483,8 +4483,8 @@ func TestContext2Apply_targetedModuleResource(t *testing.T) {
} }
mod := state.ModuleByPath([]string{"root", "child"}) mod := state.ModuleByPath([]string{"root", "child"})
if len(mod.Resources) != 1 { if mod == nil || len(mod.Resources) != 1 {
t.Fatalf("expected 1 resource, got: %#v", mod.Resources) t.Fatalf("expected 1 resource, got: %#v", mod)
} }
checkStateString(t, state, ` checkStateString(t, state, `

View File

@ -38,6 +38,9 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer {
steps := []GraphTransformer{ steps := []GraphTransformer{
// Creates all the nodes represented in the diff. // Creates all the nodes represented in the diff.
&DiffTransformer{Diff: b.Diff}, &DiffTransformer{Diff: b.Diff},
// Single root
&RootTransformer{},
} }
return steps return steps

View File

@ -72,6 +72,10 @@ type InstanceInfo struct {
// HumanId is a unique Id that is human-friendly and useful for UI elements. // HumanId is a unique Id that is human-friendly and useful for UI elements.
func (i *InstanceInfo) HumanId() string { func (i *InstanceInfo) HumanId() string {
if i == nil {
return "<nil>"
}
if len(i.ModulePath) <= 1 { if len(i.ModulePath) <= 1 {
return i.Id return i.Id
} }