Skip to content

Commit

Permalink
๐Ÿค– Refactor: ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํŒŒ์ผ ๊ฐ ๊ธฐ๋Šฅ์ด ๋ช…ํ™•ํ•˜๊ฒŒ ํŒŒ์ผ ๋ถ„๋ฆฌ
Browse files Browse the repository at this point in the history
  • Loading branch information
Gdm0714 committed Nov 22, 2024
1 parent df18552 commit 7b38f1c
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 91 deletions.
3 changes: 3 additions & 0 deletions apps/terraform/interface/FileOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FileOption {
log?: boolean;
}
114 changes: 23 additions & 91 deletions apps/terraform/main.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,35 @@
import { CloudCanvasNode } from './interface/CloudCanvasNode';
import { NCloudProvider } from './model/NCloudProvider';
import { TerraformConvertor } from './convertor/TerraformConvertor';
import { sampleNodes } from './sample/sampleData';
import { saveTerraformFiles } from './util/file';

const sampleNodes: CloudCanvasNode[] = [
{
id: "vpc1",
type: "VPC",
name: "my-vpc",
properties: {
cidrBlock: "172.16.0.0/16"
}
},
{
id: "nacl1",
type: "NetworkACL",
name: "my-nacl",
properties: {
}
},
{
id: "subnet1",
type: "Subnet",
name: "my-subnet",
properties: {
subnet: "172.16.10.0/24",
zone: "KR-2",
subnetType: "PUBLIC",
usageType: "GEN"
}
},
{
id: "acg1",
type: "ACG",
name: "my-acg",
properties: {
description: "My ACG"
}
},
{
id: "acgrule1",
type: "ACGRule",
name: "",
properties: {
protocol: "TCP",
ipBlock: "0.0.0.0/0",
portRange: "80",
description: "HTTP"
}
},
{
id: "loginkey1",
type: "LoginKey",
name: "my-key",
properties: {
}
},
{
id: "nic1",
type: "NetworkInterface",
name: "my-nic",
properties: {}
},
{
id: "server1",
type: "Server",
name: "my-server",
properties: {
serverImageProductCode: "SW.VSVR.OS.LNX64.CNTOS.0708.B050",
serverProductCode: "SVR.VSVR.HICPU.C002.M004.NET.HDD.B050.G002"
}
},
{
id: "publicip1",
type: "PublicIP",
name: "my-public-ip",
properties: {}
}
];
async function generateTerraformCode(): Promise<string> {
const provider = new NCloudProvider({
accessKey: "var.access_key",
secretKey: "var.secret_key",
region: "var.region",
site: "public"
});

async function main() {
try {
const provider = new NCloudProvider({
accessKey: "var.access_key",
secretKey: "var.secret_key",
region: "var.region",
site: "public"
});
const converter = new TerraformConvertor(provider);
converter.addResourceFromJson({ nodes: sampleNodes });

const convertor = new TerraformConvertor(provider);
return converter.generate();
}

convertor.addResourceFromJson({ nodes: sampleNodes });
await convertor.saveToFile('main.tf');
console.log('\nGenerated Terraform code:');
console.log('----------------------------------------');
console.log(convertor.generate());
console.log('----------------------------------------');
async function main() {
try {
const terraformCode = await generateTerraformCode();
await saveTerraformFiles(terraformCode, { log: true });

} catch (error) {
console.error('Error generating Terraform configuration:', error);
if (error instanceof Error) {
console.error('Error generating Terraform configuration:', error.message);
} else {
console.error('An unknown error occurred');
}
process.exit(1);
}
}

Expand Down
77 changes: 77 additions & 0 deletions apps/terraform/sample/sampleData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { CloudCanvasNode } from '../interface/CloudCanvasNode';

export const sampleNodes: CloudCanvasNode[] = [
{
id: "vpc1",
type: "VPC",
name: "my-vpc",
properties: {
cidrBlock: "172.16.0.0/16"
}
},
{
id: "nacl1",
type: "NetworkACL",
name: "my-nacl",
properties: {
}
},
{
id: "subnet1",
type: "Subnet",
name: "my-subnet",
properties: {
subnet: "172.16.10.0/24",
zone: "KR-2",
subnetType: "PUBLIC",
usageType: "GEN"
}
},
{
id: "acg1",
type: "ACG",
name: "my-acg",
properties: {
description: "My ACG"
}
},
{
id: "acgrule1",
type: "ACGRule",
name: "",
properties: {
protocol: "TCP",
ipBlock: "0.0.0.0/0",
portRange: "80",
description: "HTTP"
}
},
{
id: "loginkey1",
type: "LoginKey",
name: "my-key",
properties: {
}
},
{
id: "nic1",
type: "NetworkInterface",
name: "my-nic",
properties: {}
},
{
id: "server1",
type: "Server",
name: "my-server",
properties: {
serverImageProductCode: "SW.VSVR.OS.LNX64.CNTOS.0708.B050",
serverProductCode: "SVR.VSVR.HICPU.C002.M004.NET.HDD.B050.G002"
}
},
{
id: "publicip1",
type: "PublicIP",
name: "my-public-ip",
properties: {}
}
];

0 comments on commit 7b38f1c

Please sign in to comment.