@@ -2010,6 +2010,61 @@ variable "baz" {}
2010
2010
assert .Contains (t , buf .String (), "variables=\" foo\" " )
2011
2011
}
2012
2012
2013
+ func TestLoadChildModulesFromLocalCache (t * testing.T ) {
2014
+ var buf bytes.Buffer
2015
+ slog .SetDefault (slog .New (log .NewHandler (& buf , & log.Options {Level : log .LevelDebug })))
2016
+
2017
+ fsys := fstest.MapFS {
2018
+ "main.tf" : & fstest.MapFile {Data : []byte (`module "level_1" {
2019
+ source = "./modules/level_1"
2020
+ }` )},
2021
+ "modules/level_1/main.tf" : & fstest.MapFile {Data : []byte (`module "level_2" {
2022
+ source = "../level_2"
2023
+ }` )},
2024
+ "modules/level_2/main.tf" : & fstest.MapFile {Data : []byte (`module "level_3" {
2025
+ count = 2
2026
+ source = "../level_3"
2027
+ }` )},
2028
+ "modules/level_3/main.tf" : & fstest.MapFile {Data : []byte (`resource "foo" "bar" {}` )},
2029
+ ".terraform/modules/modules.json" : & fstest.MapFile {Data : []byte (`{
2030
+ "Modules": [
2031
+ { "Key": "", "Source": "", "Dir": "." },
2032
+ {
2033
+ "Key": "level_1",
2034
+ "Source": "./modules/level_1",
2035
+ "Dir": "modules/level_1"
2036
+ },
2037
+ {
2038
+ "Key": "level_1.level_2",
2039
+ "Source": "../level_2",
2040
+ "Dir": "modules/level_2"
2041
+ },
2042
+ {
2043
+ "Key": "level_1.level_2.level_3",
2044
+ "Source": "../level_3",
2045
+ "Dir": "modules/level_3"
2046
+ }
2047
+ ]
2048
+ }` )},
2049
+ }
2050
+
2051
+ parser := New (
2052
+ fsys , "" ,
2053
+ OptionStopOnHCLError (true ),
2054
+ )
2055
+ require .NoError (t , parser .ParseFS (context .TODO (), "." ))
2056
+
2057
+ modules , _ , err := parser .EvaluateAll (context .TODO ())
2058
+ require .NoError (t , err )
2059
+
2060
+ assert .Len (t , modules , 5 )
2061
+
2062
+ assert .Contains (t , buf .String (), "Using module from Terraform cache .terraform/modules\t source=\" ./modules/level_1\" " )
2063
+ assert .Contains (t , buf .String (), "Using module from Terraform cache .terraform/modules\t source=\" ../level_2\" " )
2064
+ assert .Contains (t , buf .String (), "Using module from Terraform cache .terraform/modules\t source=\" ../level_3\" " )
2065
+ assert .Contains (t , buf .String (), "Using module from Terraform cache .terraform/modules\t source=\" ../level_3\" " )
2066
+ }
2067
+
2013
2068
func TestLogParseErrors (t * testing.T ) {
2014
2069
var buf bytes.Buffer
2015
2070
slog .SetDefault (slog .New (log .NewHandler (& buf , nil )))
0 commit comments