Merge pull request #10719 from hashicorp/b-module-var-ref

terraform: add module vars after providers to see references
This commit is contained in:
Mitchell Hashimoto 2016-12-14 13:50:16 -08:00 committed by GitHub
commit 9520b24679
6 changed files with 59 additions and 12 deletions

View File

@ -657,6 +657,29 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) {
}
}
func TestContext2Plan_moduleProviderVar(t *testing.T) {
m := testModule(t, "plan-module-provider-var")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
plan, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanModuleProviderVarStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContext2Plan_moduleVar(t *testing.T) {
m := testModule(t, "plan-module-var")
p := testProvider("aws")

View File

@ -92,6 +92,13 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
// Add root variables
&RootVariableTransformer{Module: b.Module},
// Create all the providers
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: b.Module},
// Add module variables
&ModuleVariableTransformer{Module: b.Module},
@ -102,17 +109,6 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer {
// Target
&TargetsTransformer{Targets: b.Targets},
// Create all the providers
&MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider},
&ProviderTransformer{},
&DisableProviderTransformer{},
&ParentProviderTransformer{},
&AttachProviderConfigTransformer{Module: b.Module},
// Connect references again to connect the providers, module variables,
// etc. This is idempotent.
&ReferenceTransformer{},
// Single root
&RootTransformer{},
}

View File

@ -1381,6 +1381,19 @@ module.child:
ID = baz
`
const testTerraformPlanModuleProviderVarStr = `
DIFF:
module.child:
CREATE: aws_instance.test
type: "" => "aws_instance"
value: "" => "hello"
STATE:
<no state>
`
const testTerraformPlanModuleVarStr = `
DIFF:

View File

@ -0,0 +1,9 @@
variable "foo" {}
provider "aws" {
value = "${var.foo}"
}
resource "aws_instance" "test" {
value = "hello"
}

View File

@ -0,0 +1,6 @@
variable "foo" { default = "bar" }
module "child" {
source = "./child"
foo = "${var.foo}"
}

View File

@ -11,7 +11,7 @@ import (
// ModuleVariableTransformer is a GraphTransformer that adds all the variables
// in the configuration to the graph.
//
// This only adds variables that are referenced by other thigns in the graph.
// This only adds variables that are referenced by other things in the graph.
// If a module variable is not referenced, it won't be added to the graph.
type ModuleVariableTransformer struct {
Module *module.Tree