diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index 6d2718462..a52814516 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -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()) + } +} diff --git a/terraform/transform_module_expansion.go b/terraform/transform_module_expansion.go index 090f1bfcc..4e688718f 100644 --- a/terraform/transform_module_expansion.go +++ b/terraform/transform_module_expansion.go @@ -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 }