modules expansion validate test

This commit is contained in:
James Bardin 2020-04-05 11:17:28 -04:00
parent 73492fd2d5
commit e23aa02560
2 changed files with 59 additions and 1 deletions

View File

@ -1518,3 +1518,58 @@ variable "test" {
t.Fatalf("unexpected error\ngot: %s", diags.Err().Error())
}
}
func TestContext2Validate_expandModules(t *testing.T) {
m := testModuleInline(t, map[string]string{
"main.tf": `
module "mod1" {
for_each = toset(["a", "b"])
source = "./mod"
}
module "mod2" {
for_each = module.mod1
source = "./mod"
}
module "mod3" {
count = len(module.mod2)
source = "./mod"
}
`,
"mod/main.tf": `
resource "aws_instance" "foo" {
}
module "nested" {
count = 2
source = "./nested"
input = 2
}
`,
"mod/nested/main.tf": `
variable "input" {
}
resource "aws_instance" "foo" {
count = var.input
}
`,
})
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Config: m,
ProviderResolver: providers.ResolverFixed(
map[addrs.Provider]providers.Factory{
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
},
),
})
diags := ctx.Validate()
if diags.HasErrors() {
t.Fatal(diags.ErrWithWarnings())
}
}

View File

@ -16,7 +16,10 @@ import (
// This transform must be applied only after all nodes representing objects
// that can be contained within modules have already been added.
type ModuleExpansionTransformer struct {
Config *configs.Config
Config *configs.Config
// Concrete allows injection of a wrapped module node by the graph builder
// to alter the evaluation behavior.
Concrete ConcreteModuleNodeFunc
}