(root: string)
| 1092 | }); |
| 1093 | |
| 1094 | function writeMultiModuleRepo(root: string) { |
| 1095 | fs.mkdirSync(path.join(root, 'modules/vpc'), { recursive: true }); |
| 1096 | fs.mkdirSync(path.join(root, 'modules/other'), { recursive: true }); |
| 1097 | fs.mkdirSync(path.join(root, 'envs'), { recursive: true }); |
| 1098 | fs.writeFileSync( |
| 1099 | path.join(root, 'main.tf'), |
| 1100 | 'variable "vpc_cidr" {\n type = string\n}\n\n' + |
| 1101 | 'module "vpc" {\n source = "./modules/vpc"\n cidr = var.vpc_cidr\n}\n\n' + |
| 1102 | 'module "registry_thing" {\n source = "terraform-aws-modules/s3-bucket/aws"\n bucket = "x"\n}\n\n' + |
| 1103 | 'output "vpc_id" {\n value = module.vpc.vpc_id\n}\n' |
| 1104 | ); |
| 1105 | fs.writeFileSync( |
| 1106 | path.join(root, 'modules/vpc/variables.tf'), |
| 1107 | 'variable "cidr" {\n type = string\n}\n' |
| 1108 | ); |
| 1109 | fs.writeFileSync( |
| 1110 | path.join(root, 'modules/vpc/main.tf'), |
| 1111 | 'resource "aws_vpc" "this" {\n cidr_block = var.cidr\n}\n' |
| 1112 | ); |
| 1113 | fs.writeFileSync( |
| 1114 | path.join(root, 'modules/vpc/outputs.tf'), |
| 1115 | 'output "vpc_id" {\n value = aws_vpc.this.id\n}\n' |
| 1116 | ); |
| 1117 | // Same-named variable in an UNRELATED module — must never receive edges |
| 1118 | // from outside its own directory. |
| 1119 | fs.writeFileSync( |
| 1120 | path.join(root, 'modules/other/variables.tf'), |
| 1121 | 'variable "cidr" {\n type = string\n}\nvariable "orphan_ref_target" {}\n' |
| 1122 | ); |
| 1123 | // References a variable that has no same-dir declaration: must stay unlinked. |
| 1124 | fs.writeFileSync( |
| 1125 | path.join(root, 'modules/other/main.tf'), |
| 1126 | 'resource "aws_eip" "e" {\n tags = { Name = var.undeclared_here_elsewhere_yes }\n}\n' |
| 1127 | ); |
| 1128 | fs.writeFileSync(path.join(root, 'envs/prod.tfvars'), 'vpc_cidr = "10.0.0.0/16"\n'); |
| 1129 | } |
| 1130 | |
| 1131 | it('bridges module inputs/outputs/source and enforces directory scoping', async () => { |
| 1132 | tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-terraform-')); |
no test coverage detected