(root: string)
| 1200 | }); |
| 1201 | |
| 1202 | function writeMultiModuleRepo(root: string) { |
| 1203 | fs.mkdirSync(path.join(root, 'modules/vpc'), { recursive: true }); |
| 1204 | fs.mkdirSync(path.join(root, 'modules/other'), { recursive: true }); |
| 1205 | fs.mkdirSync(path.join(root, 'envs'), { recursive: true }); |
| 1206 | fs.writeFileSync( |
| 1207 | path.join(root, 'main.tf'), |
| 1208 | 'variable "vpc_cidr" {\n type = string\n}\n\n' + |
| 1209 | 'module "vpc" {\n source = "./modules/vpc"\n cidr = var.vpc_cidr\n}\n\n' + |
| 1210 | 'module "registry_thing" {\n source = "terraform-aws-modules/s3-bucket/aws"\n bucket = "x"\n}\n\n' + |
| 1211 | 'output "vpc_id" {\n value = module.vpc.vpc_id\n}\n' |
| 1212 | ); |
| 1213 | fs.writeFileSync( |
| 1214 | path.join(root, 'modules/vpc/variables.tf'), |
| 1215 | 'variable "cidr" {\n type = string\n}\n' |
| 1216 | ); |
| 1217 | fs.writeFileSync( |
| 1218 | path.join(root, 'modules/vpc/main.tf'), |
| 1219 | 'resource "aws_vpc" "this" {\n cidr_block = var.cidr\n}\n' |
| 1220 | ); |
| 1221 | fs.writeFileSync( |
| 1222 | path.join(root, 'modules/vpc/outputs.tf'), |
| 1223 | 'output "vpc_id" {\n value = aws_vpc.this.id\n}\n' |
| 1224 | ); |
| 1225 | // Same-named variable in an UNRELATED module — must never receive edges |
| 1226 | // from outside its own directory. |
| 1227 | fs.writeFileSync( |
| 1228 | path.join(root, 'modules/other/variables.tf'), |
| 1229 | 'variable "cidr" {\n type = string\n}\nvariable "orphan_ref_target" {}\n' |
| 1230 | ); |
| 1231 | // References a variable that has no same-dir declaration: must stay unlinked. |
| 1232 | fs.writeFileSync( |
| 1233 | path.join(root, 'modules/other/main.tf'), |
| 1234 | 'resource "aws_eip" "e" {\n tags = { Name = var.undeclared_here_elsewhere_yes }\n}\n' |
| 1235 | ); |
| 1236 | fs.writeFileSync(path.join(root, 'envs/prod.tfvars'), 'vpc_cidr = "10.0.0.0/16"\n'); |
| 1237 | } |
| 1238 | |
| 1239 | it('bridges module inputs/outputs/source and enforces directory scoping', async () => { |
| 1240 | tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-terraform-')); |
no test coverage detected