Skip to content

Commit ebec191

Browse files
committed
fix: 타벤더사도 동일한 동작하도록 변경
1 parent 8c40f21 commit ebec191

File tree

3 files changed

+86
-8
lines changed

3 files changed

+86
-8
lines changed

src/providers/azure/codeGenerator/terraformGenerator.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,59 @@ resource "azurerm_managed_disk" "${this.sanitizeResourceName(disk.id)}" {
290290
version: "latest"
291291
};
292292

293-
const subnetRef = subnets.length > 0 ?
294-
`azurerm_subnet.${this.sanitizeResourceName(subnets[0].id)}.id` :
295-
'"subnet-id"';
293+
// VM-Subnet 연결 찾기 (스태킹 관계)
294+
const subnetConnection = connections.find(conn =>
295+
(conn.fromBlockId === vm.id || conn.toBlockId === vm.id) &&
296+
conn.properties?.stackConnection === true &&
297+
subnets.some(s => s.id === conn.fromBlockId || s.id === conn.toBlockId)
298+
);
299+
300+
let subnetRef = '"subnet-id"';
301+
if (subnetConnection) {
302+
// 연결된 Subnet ID 찾기
303+
const connectedSubnetId = subnetConnection.fromBlockId === vm.id
304+
? subnetConnection.toBlockId
305+
: subnetConnection.fromBlockId;
306+
const connectedSubnet = subnets.find(s => s.id === connectedSubnetId);
307+
308+
if (connectedSubnet) {
309+
subnetRef = `azurerm_subnet.${this.sanitizeResourceName(connectedSubnet.id)}.id`;
310+
console.log(`[Azure CodeGen] VM ${vm.id.substring(0, 8)} → Subnet ${connectedSubnet.id.substring(0, 8)}`);
311+
}
312+
} else if (subnets.length > 0) {
313+
// 연결이 없으면 첫 번째 Subnet 사용 (fallback)
314+
subnetRef = `azurerm_subnet.${this.sanitizeResourceName(subnets[0].id)}.id`;
315+
console.warn(`[Azure CodeGen] No subnet connection found for VM ${vm.id.substring(0, 8)}, using first subnet`);
316+
}
296317

297318
// OS디스크 찾기 (스태킹된 Managed Disk)
319+
console.log(`[Azure CodeGen] VM ${vm.id.substring(0, 8)} - OS디스크 검색 중...`);
320+
console.log(`[Azure CodeGen] 전체 연결 수: ${connections.length}, Disk 수: ${managedDisks.length}`);
321+
298322
const osDisk = managedDisks.find((disk) => {
299323
const diskConnection = connections.find(conn =>
300324
(conn.fromBlockId === vm.id && conn.toBlockId === disk.id) ||
301325
(conn.fromBlockId === disk.id && conn.toBlockId === vm.id)
302326
);
327+
328+
if (diskConnection) {
329+
console.log(`[Azure CodeGen] Disk ${disk.id.substring(0, 8)} 연결 발견:`, {
330+
stackConnection: diskConnection.properties?.stackConnection,
331+
volumeType: diskConnection.properties?.volumeType,
332+
fromTo: `${diskConnection.fromBlockId.substring(0, 8)}${diskConnection.toBlockId.substring(0, 8)}`
333+
});
334+
}
335+
303336
return diskConnection?.properties?.stackConnection === true &&
304337
diskConnection?.properties?.volumeType === 'boot';
305338
});
306339

340+
if (osDisk) {
341+
console.log(`✅ [Azure CodeGen] OS디스크 찾음: ${osDisk.id.substring(0, 8)} (${osDisk.properties.name})`);
342+
} else {
343+
console.log(`❌ [Azure CodeGen] OS디스크 없음`);
344+
}
345+
307346
let code = `# Public IP for VM: ${name}
308347
resource "azurerm_public_ip" "${this.sanitizeResourceName(vm.id)}_pip" {
309348
name = "${name}-pip"

src/providers/gcp/codeGenerator/terraformGenerator.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,59 @@ resource "google_compute_disk" "${this.sanitizeResourceName(disk.id)}" {
269269
const zone = vm.properties.zone || "asia-northeast3-a";
270270
const networkTags = vm.properties.networkTags || [];
271271

272-
const subnetRef = subnets.length > 0 ?
273-
`google_compute_subnetwork.${this.sanitizeResourceName(subnets[0].id)}.id` :
274-
'"default"';
272+
// VM-Subnet 연결 찾기 (스태킹 관계)
273+
const subnetConnection = connections.find(conn =>
274+
(conn.fromBlockId === vm.id || conn.toBlockId === vm.id) &&
275+
conn.properties?.stackConnection === true &&
276+
subnets.some(s => s.id === conn.fromBlockId || s.id === conn.toBlockId)
277+
);
278+
279+
let subnetRef = '"default"';
280+
if (subnetConnection) {
281+
// 연결된 Subnet ID 찾기
282+
const connectedSubnetId = subnetConnection.fromBlockId === vm.id
283+
? subnetConnection.toBlockId
284+
: subnetConnection.fromBlockId;
285+
const connectedSubnet = subnets.find(s => s.id === connectedSubnetId);
286+
287+
if (connectedSubnet) {
288+
subnetRef = `google_compute_subnetwork.${this.sanitizeResourceName(connectedSubnet.id)}.id`;
289+
console.log(`[GCP CodeGen] VM ${vm.id.substring(0, 8)} → Subnet ${connectedSubnet.id.substring(0, 8)}`);
290+
}
291+
} else if (subnets.length > 0) {
292+
// 연결이 없으면 첫 번째 Subnet 사용 (fallback)
293+
subnetRef = `google_compute_subnetwork.${this.sanitizeResourceName(subnets[0].id)}.id`;
294+
console.warn(`[GCP CodeGen] No subnet connection found for VM ${vm.id.substring(0, 8)}, using first subnet`);
295+
}
275296

276297
// 부트디스크 찾기 (스태킹된 Persistent Disk)
298+
console.log(`[GCP CodeGen] VM ${vm.id.substring(0, 8)} - 부트디스크 검색 중...`);
299+
console.log(`[GCP CodeGen] 전체 연결 수: ${connections.length}, Disk 수: ${persistentDisks.length}`);
300+
277301
const bootDisk = persistentDisks.find((disk) => {
278302
const diskConnection = connections.find(conn =>
279303
(conn.fromBlockId === vm.id && conn.toBlockId === disk.id) ||
280304
(conn.fromBlockId === disk.id && conn.toBlockId === vm.id)
281305
);
306+
307+
if (diskConnection) {
308+
console.log(`[GCP CodeGen] Disk ${disk.id.substring(0, 8)} 연결 발견:`, {
309+
stackConnection: diskConnection.properties?.stackConnection,
310+
volumeType: diskConnection.properties?.volumeType,
311+
fromTo: `${diskConnection.fromBlockId.substring(0, 8)}${diskConnection.toBlockId.substring(0, 8)}`
312+
});
313+
}
314+
282315
return diskConnection?.properties?.stackConnection === true &&
283316
diskConnection?.properties?.volumeType === 'boot';
284317
});
285318

319+
if (bootDisk) {
320+
console.log(`✅ [GCP CodeGen] 부트디스크 찾음: ${bootDisk.id.substring(0, 8)} (${bootDisk.properties.name})`);
321+
} else {
322+
console.log(`❌ [GCP CodeGen] 부트디스크 없음`);
323+
}
324+
286325
let code = `# Compute Engine: ${name}
287326
resource "google_compute_instance" "${this.sanitizeResourceName(vm.id)}" {
288327
name = "${name}"

src/stores/stackingStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ export const useStackingStore = create<StackingStoreState>()(
299299

300300
// 기존 자식 블록 상태 가져오기
301301
const existingChildState = stackingStates.get(childId);
302-
302+
303303
// 자식 블록 스태킹 상태 업데이트 (여러 부모 지원)
304304
const childStackingState: StackingState = {
305305
isStacked: true,
306-
parentBlockIds: existingChildState
306+
parentBlockIds: existingChildState
307307
? [...new Set([...existingChildState.parentBlockIds, parentId])] // 중복 제거하며 추가
308308
: [parentId],
309309
childBlockIds: existingChildState?.childBlockIds || [],

0 commit comments

Comments
 (0)