@stacksjs/ts-cloud 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +321 -0
  3. package/bin/cli.ts +133 -0
  4. package/bin/commands/analytics.ts +328 -0
  5. package/bin/commands/api.ts +379 -0
  6. package/bin/commands/assets.ts +221 -0
  7. package/bin/commands/audit.ts +501 -0
  8. package/bin/commands/backup.ts +682 -0
  9. package/bin/commands/cache.ts +294 -0
  10. package/bin/commands/cdn.ts +281 -0
  11. package/bin/commands/config.ts +202 -0
  12. package/bin/commands/container.ts +105 -0
  13. package/bin/commands/cost.ts +208 -0
  14. package/bin/commands/database.ts +401 -0
  15. package/bin/commands/deploy.ts +674 -0
  16. package/bin/commands/domain.ts +397 -0
  17. package/bin/commands/email.ts +423 -0
  18. package/bin/commands/environment.ts +285 -0
  19. package/bin/commands/events.ts +424 -0
  20. package/bin/commands/firewall.ts +145 -0
  21. package/bin/commands/function.ts +116 -0
  22. package/bin/commands/generate.ts +280 -0
  23. package/bin/commands/git.ts +139 -0
  24. package/bin/commands/iam.ts +464 -0
  25. package/bin/commands/index.ts +48 -0
  26. package/bin/commands/init.ts +120 -0
  27. package/bin/commands/logs.ts +148 -0
  28. package/bin/commands/network.ts +579 -0
  29. package/bin/commands/notify.ts +489 -0
  30. package/bin/commands/queue.ts +407 -0
  31. package/bin/commands/scheduler.ts +370 -0
  32. package/bin/commands/secrets.ts +54 -0
  33. package/bin/commands/server.ts +629 -0
  34. package/bin/commands/shared.ts +97 -0
  35. package/bin/commands/ssl.ts +138 -0
  36. package/bin/commands/stack.ts +325 -0
  37. package/bin/commands/status.ts +385 -0
  38. package/bin/commands/storage.ts +450 -0
  39. package/bin/commands/team.ts +96 -0
  40. package/bin/commands/tunnel.ts +489 -0
  41. package/bin/commands/utils.ts +202 -0
  42. package/build.ts +15 -0
  43. package/cloud +2 -0
  44. package/package.json +99 -0
  45. package/src/aws/acm.ts +768 -0
  46. package/src/aws/application-autoscaling.ts +845 -0
  47. package/src/aws/bedrock.ts +4074 -0
  48. package/src/aws/client.ts +878 -0
  49. package/src/aws/cloudformation.ts +896 -0
  50. package/src/aws/cloudfront.ts +1531 -0
  51. package/src/aws/cloudwatch-logs.ts +154 -0
  52. package/src/aws/comprehend.ts +839 -0
  53. package/src/aws/connect.ts +1056 -0
  54. package/src/aws/deploy-imap.ts +384 -0
  55. package/src/aws/dynamodb.ts +340 -0
  56. package/src/aws/ec2.ts +1385 -0
  57. package/src/aws/ecr.ts +621 -0
  58. package/src/aws/ecs.ts +615 -0
  59. package/src/aws/elasticache.ts +301 -0
  60. package/src/aws/elbv2.ts +942 -0
  61. package/src/aws/email.ts +928 -0
  62. package/src/aws/eventbridge.ts +248 -0
  63. package/src/aws/iam.ts +1689 -0
  64. package/src/aws/imap-server.ts +2100 -0
  65. package/src/aws/index.ts +213 -0
  66. package/src/aws/kendra.ts +1097 -0
  67. package/src/aws/lambda.ts +786 -0
  68. package/src/aws/opensearch.ts +158 -0
  69. package/src/aws/personalize.ts +977 -0
  70. package/src/aws/polly.ts +559 -0
  71. package/src/aws/rds.ts +888 -0
  72. package/src/aws/rekognition.ts +846 -0
  73. package/src/aws/route53-domains.ts +359 -0
  74. package/src/aws/route53.ts +1046 -0
  75. package/src/aws/s3.ts +2318 -0
  76. package/src/aws/scheduler.ts +571 -0
  77. package/src/aws/secrets-manager.ts +769 -0
  78. package/src/aws/ses.ts +1081 -0
  79. package/src/aws/setup-phone.ts +104 -0
  80. package/src/aws/setup-sms.ts +580 -0
  81. package/src/aws/sms.ts +1735 -0
  82. package/src/aws/smtp-server.ts +531 -0
  83. package/src/aws/sns.ts +758 -0
  84. package/src/aws/sqs.ts +382 -0
  85. package/src/aws/ssm.ts +807 -0
  86. package/src/aws/sts.ts +92 -0
  87. package/src/aws/support.ts +391 -0
  88. package/src/aws/test-imap.ts +86 -0
  89. package/src/aws/textract.ts +780 -0
  90. package/src/aws/transcribe.ts +108 -0
  91. package/src/aws/translate.ts +641 -0
  92. package/src/aws/voice.ts +1379 -0
  93. package/src/config.ts +35 -0
  94. package/src/deploy/index.ts +7 -0
  95. package/src/deploy/static-site-external-dns.ts +906 -0
  96. package/src/deploy/static-site.ts +1125 -0
  97. package/src/dns/godaddy.ts +412 -0
  98. package/src/dns/index.ts +183 -0
  99. package/src/dns/porkbun.ts +362 -0
  100. package/src/dns/route53-adapter.ts +414 -0
  101. package/src/dns/types.ts +114 -0
  102. package/src/dns/validator.ts +369 -0
  103. package/src/generators/index.ts +5 -0
  104. package/src/generators/infrastructure.ts +1660 -0
  105. package/src/index.ts +163 -0
  106. package/src/push/apns.ts +452 -0
  107. package/src/push/fcm.ts +506 -0
  108. package/src/push/index.ts +58 -0
  109. package/src/ssl/acme-client.ts +478 -0
  110. package/src/ssl/index.ts +7 -0
  111. package/src/ssl/letsencrypt.ts +747 -0
  112. package/src/types.ts +2 -0
  113. package/src/utils/cli.ts +398 -0
  114. package/src/validation/index.ts +5 -0
  115. package/src/validation/template.ts +405 -0
  116. package/test/index.test.ts +128 -0
  117. package/tsconfig.json +18 -0
@@ -0,0 +1,579 @@
1
+ import type { CLI } from '@stacksjs/clapp'
2
+ import * as cli from '../../src/utils/cli'
3
+ import { EC2Client } from '../../src/aws/ec2'
4
+ import { loadValidatedConfig } from './shared'
5
+
6
+ export function registerNetworkCommands(app: CLI): void {
7
+ app
8
+ .command('network:list', 'List all VPCs')
9
+ .option('--region <region>', 'AWS region')
10
+ .action(async (options: { region?: string }) => {
11
+ cli.header('VPCs')
12
+
13
+ try {
14
+ const config = await loadValidatedConfig()
15
+ const region = options.region || config.project.region || 'us-east-1'
16
+ const ec2 = new EC2Client(region)
17
+
18
+ const spinner = new cli.Spinner('Fetching VPCs...')
19
+ spinner.start()
20
+
21
+ const result = await ec2.describeVpcs()
22
+ const vpcs = result.Vpcs || []
23
+
24
+ spinner.succeed(`Found ${vpcs.length} VPC(s)`)
25
+
26
+ if (vpcs.length === 0) {
27
+ cli.info('No VPCs found')
28
+ return
29
+ }
30
+
31
+ cli.table(
32
+ ['VPC ID', 'Name', 'CIDR', 'State', 'Default'],
33
+ vpcs.map(vpc => [
34
+ vpc.VpcId || 'N/A',
35
+ vpc.Tags?.find(t => t.Key === 'Name')?.Value || '-',
36
+ vpc.CidrBlock || 'N/A',
37
+ vpc.State || 'N/A',
38
+ vpc.IsDefault ? 'Yes' : 'No',
39
+ ]),
40
+ )
41
+ }
42
+ catch (error: any) {
43
+ cli.error(`Failed to list VPCs: ${error.message}`)
44
+ process.exit(1)
45
+ }
46
+ })
47
+
48
+ app
49
+ .command('network:subnets', 'List all subnets')
50
+ .option('--region <region>', 'AWS region')
51
+ .option('--vpc <vpcId>', 'Filter by VPC ID')
52
+ .action(async (options: { region?: string; vpc?: string }) => {
53
+ cli.header('Subnets')
54
+
55
+ try {
56
+ const config = await loadValidatedConfig()
57
+ const region = options.region || config.project.region || 'us-east-1'
58
+ const ec2 = new EC2Client(region)
59
+
60
+ const spinner = new cli.Spinner('Fetching subnets...')
61
+ spinner.start()
62
+
63
+ const filters = options.vpc ? [{ Name: 'vpc-id', Values: [options.vpc] }] : undefined
64
+ const result = await ec2.describeSubnets({ Filters: filters })
65
+ const subnets = result.Subnets || []
66
+
67
+ spinner.succeed(`Found ${subnets.length} subnet(s)`)
68
+
69
+ if (subnets.length === 0) {
70
+ cli.info('No subnets found')
71
+ return
72
+ }
73
+
74
+ cli.table(
75
+ ['Subnet ID', 'Name', 'VPC', 'CIDR', 'AZ', 'IPs Available', 'Public'],
76
+ subnets.map(subnet => [
77
+ subnet.SubnetId || 'N/A',
78
+ subnet.Tags?.find(t => t.Key === 'Name')?.Value || '-',
79
+ subnet.VpcId || 'N/A',
80
+ subnet.CidrBlock || 'N/A',
81
+ subnet.AvailabilityZone || 'N/A',
82
+ (subnet.AvailableIpAddressCount || 0).toString(),
83
+ subnet.MapPublicIpOnLaunch ? 'Yes' : 'No',
84
+ ]),
85
+ )
86
+ }
87
+ catch (error: any) {
88
+ cli.error(`Failed to list subnets: ${error.message}`)
89
+ process.exit(1)
90
+ }
91
+ })
92
+
93
+ app
94
+ .command('network:security-groups', 'List all security groups')
95
+ .option('--region <region>', 'AWS region')
96
+ .option('--vpc <vpcId>', 'Filter by VPC ID')
97
+ .action(async (options: { region?: string; vpc?: string }) => {
98
+ cli.header('Security Groups')
99
+
100
+ try {
101
+ const config = await loadValidatedConfig()
102
+ const region = options.region || config.project.region || 'us-east-1'
103
+ const ec2 = new EC2Client(region)
104
+
105
+ const spinner = new cli.Spinner('Fetching security groups...')
106
+ spinner.start()
107
+
108
+ const filters = options.vpc ? [{ Name: 'vpc-id', Values: [options.vpc] }] : undefined
109
+ const result = await ec2.describeSecurityGroups({ Filters: filters })
110
+ const groups = result.SecurityGroups || []
111
+
112
+ spinner.succeed(`Found ${groups.length} security group(s)`)
113
+
114
+ if (groups.length === 0) {
115
+ cli.info('No security groups found')
116
+ return
117
+ }
118
+
119
+ cli.table(
120
+ ['Group ID', 'Name', 'VPC', 'Description', 'Inbound Rules', 'Outbound Rules'],
121
+ groups.map(sg => [
122
+ sg.GroupId || 'N/A',
123
+ sg.GroupName || 'N/A',
124
+ sg.VpcId || 'N/A',
125
+ (sg.Description || '').substring(0, 30),
126
+ (sg.IpPermissions?.length || 0).toString(),
127
+ (sg.IpPermissionsEgress?.length || 0).toString(),
128
+ ]),
129
+ )
130
+ }
131
+ catch (error: any) {
132
+ cli.error(`Failed to list security groups: ${error.message}`)
133
+ process.exit(1)
134
+ }
135
+ })
136
+
137
+ app
138
+ .command('network:security-group <groupId>', 'Show security group details')
139
+ .option('--region <region>', 'AWS region')
140
+ .action(async (groupId: string, options: { region?: string }) => {
141
+ cli.header(`Security Group: ${groupId}`)
142
+
143
+ try {
144
+ const config = await loadValidatedConfig()
145
+ const region = options.region || config.project.region || 'us-east-1'
146
+ const ec2 = new EC2Client(region)
147
+
148
+ const spinner = new cli.Spinner('Fetching security group...')
149
+ spinner.start()
150
+
151
+ const result = await ec2.describeSecurityGroups({
152
+ GroupIds: [groupId],
153
+ })
154
+
155
+ const sg = result.SecurityGroups?.[0]
156
+
157
+ if (!sg) {
158
+ spinner.fail('Security group not found')
159
+ return
160
+ }
161
+
162
+ spinner.succeed('Security group loaded')
163
+
164
+ cli.info('\nGeneral Information:')
165
+ cli.info(` Group ID: ${sg.GroupId}`)
166
+ cli.info(` Name: ${sg.GroupName}`)
167
+ cli.info(` VPC: ${sg.VpcId}`)
168
+ cli.info(` Description: ${sg.Description}`)
169
+
170
+ if (sg.IpPermissions && sg.IpPermissions.length > 0) {
171
+ cli.info('\nInbound Rules:')
172
+ for (const rule of sg.IpPermissions) {
173
+ const protocol = rule.IpProtocol === '-1' ? 'All' : rule.IpProtocol?.toUpperCase()
174
+ const ports = rule.FromPort === rule.ToPort
175
+ ? rule.FromPort?.toString() || 'All'
176
+ : `${rule.FromPort}-${rule.ToPort}`
177
+
178
+ for (const range of rule.IpRanges || []) {
179
+ cli.info(` - ${protocol} ${ports} from ${range.CidrIp}${range.Description ? ` (${range.Description})` : ''}`)
180
+ }
181
+
182
+ for (const group of rule.UserIdGroupPairs || []) {
183
+ cli.info(` - ${protocol} ${ports} from ${group.GroupId}${group.Description ? ` (${group.Description})` : ''}`)
184
+ }
185
+ }
186
+ }
187
+ else {
188
+ cli.info('\nNo inbound rules configured.')
189
+ }
190
+
191
+ if (sg.IpPermissionsEgress && sg.IpPermissionsEgress.length > 0) {
192
+ cli.info('\nOutbound Rules:')
193
+ for (const rule of sg.IpPermissionsEgress) {
194
+ const protocol = rule.IpProtocol === '-1' ? 'All' : rule.IpProtocol?.toUpperCase()
195
+ const ports = rule.FromPort === rule.ToPort
196
+ ? rule.FromPort?.toString() || 'All'
197
+ : `${rule.FromPort}-${rule.ToPort}`
198
+
199
+ for (const range of rule.IpRanges || []) {
200
+ cli.info(` - ${protocol} ${ports} to ${range.CidrIp}${range.Description ? ` (${range.Description})` : ''}`)
201
+ }
202
+
203
+ for (const group of rule.UserIdGroupPairs || []) {
204
+ cli.info(` - ${protocol} ${ports} to ${group.GroupId}${group.Description ? ` (${group.Description})` : ''}`)
205
+ }
206
+ }
207
+ }
208
+ else {
209
+ cli.info('\nNo outbound rules configured.')
210
+ }
211
+
212
+ if (sg.Tags && sg.Tags.length > 0) {
213
+ cli.info('\nTags:')
214
+ for (const tag of sg.Tags) {
215
+ cli.info(` ${tag.Key}: ${tag.Value}`)
216
+ }
217
+ }
218
+ }
219
+ catch (error: any) {
220
+ cli.error(`Failed to get security group: ${error.message}`)
221
+ process.exit(1)
222
+ }
223
+ })
224
+
225
+ app
226
+ .command('network:create-vpc <cidr>', 'Create a new VPC')
227
+ .option('--region <region>', 'AWS region', { default: 'us-east-1' })
228
+ .option('--name <name>', 'VPC name tag')
229
+ .option('--tenancy <tenancy>', 'Instance tenancy (default or dedicated)', { default: 'default' })
230
+ .action(async (cidr: string, options: { region: string; name?: string; tenancy: string }) => {
231
+ cli.header('Create VPC')
232
+
233
+ try {
234
+ const ec2 = new EC2Client(options.region)
235
+
236
+ cli.info(`CIDR Block: ${cidr}`)
237
+ cli.info(`Region: ${options.region}`)
238
+ cli.info(`Tenancy: ${options.tenancy}`)
239
+ if (options.name) {
240
+ cli.info(`Name: ${options.name}`)
241
+ }
242
+
243
+ const confirmed = await cli.confirm('\nCreate this VPC?', true)
244
+ if (!confirmed) {
245
+ cli.info('Operation cancelled')
246
+ return
247
+ }
248
+
249
+ const spinner = new cli.Spinner('Creating VPC...')
250
+ spinner.start()
251
+
252
+ const result = await ec2.createVpc({
253
+ CidrBlock: cidr,
254
+ InstanceTenancy: options.tenancy,
255
+ TagSpecifications: options.name ? [{
256
+ ResourceType: 'vpc',
257
+ Tags: [{ Key: 'Name', Value: options.name }],
258
+ }] : undefined,
259
+ })
260
+
261
+ spinner.succeed('VPC created')
262
+
263
+ cli.success(`\nVPC ID: ${result.Vpc?.VpcId}`)
264
+ cli.info(`CIDR: ${result.Vpc?.CidrBlock}`)
265
+ cli.info(`State: ${result.Vpc?.State}`)
266
+ }
267
+ catch (error: any) {
268
+ cli.error(`Failed to create VPC: ${error.message}`)
269
+ process.exit(1)
270
+ }
271
+ })
272
+
273
+ app
274
+ .command('network:create-subnet <vpcId> <cidr>', 'Create a new subnet')
275
+ .option('--region <region>', 'AWS region', { default: 'us-east-1' })
276
+ .option('--name <name>', 'Subnet name tag')
277
+ .option('--az <zone>', 'Availability zone')
278
+ .option('--public', 'Auto-assign public IPs')
279
+ .action(async (vpcId: string, cidr: string, options: { region: string; name?: string; az?: string; public?: boolean }) => {
280
+ cli.header('Create Subnet')
281
+
282
+ try {
283
+ const ec2 = new EC2Client(options.region)
284
+
285
+ cli.info(`VPC: ${vpcId}`)
286
+ cli.info(`CIDR Block: ${cidr}`)
287
+ if (options.az) {
288
+ cli.info(`Availability Zone: ${options.az}`)
289
+ }
290
+ if (options.name) {
291
+ cli.info(`Name: ${options.name}`)
292
+ }
293
+ cli.info(`Auto-assign Public IP: ${options.public ? 'Yes' : 'No'}`)
294
+
295
+ const confirmed = await cli.confirm('\nCreate this subnet?', true)
296
+ if (!confirmed) {
297
+ cli.info('Operation cancelled')
298
+ return
299
+ }
300
+
301
+ const spinner = new cli.Spinner('Creating subnet...')
302
+ spinner.start()
303
+
304
+ const result = await ec2.createSubnet({
305
+ VpcId: vpcId,
306
+ CidrBlock: cidr,
307
+ AvailabilityZone: options.az,
308
+ TagSpecifications: options.name ? [{
309
+ ResourceType: 'subnet',
310
+ Tags: [{ Key: 'Name', Value: options.name }],
311
+ }] : undefined,
312
+ })
313
+
314
+ if (options.public && result.Subnet?.SubnetId) {
315
+ spinner.text = 'Enabling auto-assign public IP...'
316
+ await ec2.modifySubnetAttribute({
317
+ SubnetId: result.Subnet.SubnetId,
318
+ MapPublicIpOnLaunch: { Value: true },
319
+ })
320
+ }
321
+
322
+ spinner.succeed('Subnet created')
323
+
324
+ cli.success(`\nSubnet ID: ${result.Subnet?.SubnetId}`)
325
+ cli.info(`CIDR: ${result.Subnet?.CidrBlock}`)
326
+ cli.info(`Availability Zone: ${result.Subnet?.AvailabilityZone}`)
327
+ }
328
+ catch (error: any) {
329
+ cli.error(`Failed to create subnet: ${error.message}`)
330
+ process.exit(1)
331
+ }
332
+ })
333
+
334
+ app
335
+ .command('network:create-sg <vpcId> <name>', 'Create a new security group')
336
+ .option('--region <region>', 'AWS region', { default: 'us-east-1' })
337
+ .option('--description <desc>', 'Security group description')
338
+ .action(async (vpcId: string, name: string, options: { region: string; description?: string }) => {
339
+ cli.header('Create Security Group')
340
+
341
+ try {
342
+ const ec2 = new EC2Client(options.region)
343
+
344
+ const description = options.description || `Security group for ${name}`
345
+
346
+ cli.info(`VPC: ${vpcId}`)
347
+ cli.info(`Name: ${name}`)
348
+ cli.info(`Description: ${description}`)
349
+
350
+ const confirmed = await cli.confirm('\nCreate this security group?', true)
351
+ if (!confirmed) {
352
+ cli.info('Operation cancelled')
353
+ return
354
+ }
355
+
356
+ const spinner = new cli.Spinner('Creating security group...')
357
+ spinner.start()
358
+
359
+ const result = await ec2.createSecurityGroup({
360
+ GroupName: name,
361
+ Description: description,
362
+ VpcId: vpcId,
363
+ TagSpecifications: [{
364
+ ResourceType: 'security-group',
365
+ Tags: [{ Key: 'Name', Value: name }],
366
+ }],
367
+ })
368
+
369
+ spinner.succeed('Security group created')
370
+
371
+ cli.success(`\nGroup ID: ${result.GroupId}`)
372
+ cli.info('\nTo add rules:')
373
+ cli.info(` cloud network:sg-rule ${result.GroupId} --inbound --port 443 --cidr 0.0.0.0/0`)
374
+ }
375
+ catch (error: any) {
376
+ cli.error(`Failed to create security group: ${error.message}`)
377
+ process.exit(1)
378
+ }
379
+ })
380
+
381
+ app
382
+ .command('network:sg-rule <groupId>', 'Add a rule to a security group')
383
+ .option('--region <region>', 'AWS region', { default: 'us-east-1' })
384
+ .option('--inbound', 'Add inbound rule')
385
+ .option('--outbound', 'Add outbound rule')
386
+ .option('--protocol <protocol>', 'Protocol (tcp, udp, icmp, or -1 for all)', { default: 'tcp' })
387
+ .option('--port <port>', 'Port number or range (e.g., 80 or 80-443)')
388
+ .option('--cidr <cidr>', 'CIDR block (e.g., 0.0.0.0/0)')
389
+ .option('--source-group <groupId>', 'Source security group')
390
+ .option('--description <desc>', 'Rule description')
391
+ .action(async (groupId: string, options: {
392
+ region: string
393
+ inbound?: boolean
394
+ outbound?: boolean
395
+ protocol: string
396
+ port?: string
397
+ cidr?: string
398
+ sourceGroup?: string
399
+ description?: string
400
+ }) => {
401
+ cli.header('Add Security Group Rule')
402
+
403
+ try {
404
+ const ec2 = new EC2Client(options.region)
405
+
406
+ if (!options.inbound && !options.outbound) {
407
+ cli.error('Specify --inbound or --outbound')
408
+ return
409
+ }
410
+
411
+ if (!options.cidr && !options.sourceGroup) {
412
+ cli.error('Specify --cidr or --source-group')
413
+ return
414
+ }
415
+
416
+ // Parse port range
417
+ let fromPort: number | undefined
418
+ let toPort: number | undefined
419
+
420
+ if (options.port) {
421
+ if (options.port.includes('-')) {
422
+ const [from, to] = options.port.split('-')
423
+ fromPort = Number.parseInt(from)
424
+ toPort = Number.parseInt(to)
425
+ }
426
+ else {
427
+ fromPort = Number.parseInt(options.port)
428
+ toPort = fromPort
429
+ }
430
+ }
431
+ else if (options.protocol !== '-1') {
432
+ cli.error('Port is required for TCP/UDP protocols')
433
+ return
434
+ }
435
+
436
+ const direction = options.inbound ? 'Inbound' : 'Outbound'
437
+ const portStr = options.protocol === '-1' ? 'All' : (fromPort === toPort ? fromPort : `${fromPort}-${toPort}`)
438
+
439
+ cli.info(`Security Group: ${groupId}`)
440
+ cli.info(`Direction: ${direction}`)
441
+ cli.info(`Protocol: ${options.protocol}`)
442
+ cli.info(`Port(s): ${portStr}`)
443
+ cli.info(`Source: ${options.cidr || options.sourceGroup}`)
444
+
445
+ const confirmed = await cli.confirm('\nAdd this rule?', true)
446
+ if (!confirmed) {
447
+ cli.info('Operation cancelled')
448
+ return
449
+ }
450
+
451
+ const spinner = new cli.Spinner('Adding rule...')
452
+ spinner.start()
453
+
454
+ const ipPermission: any = {
455
+ IpProtocol: options.protocol,
456
+ FromPort: fromPort,
457
+ ToPort: toPort,
458
+ }
459
+
460
+ if (options.cidr) {
461
+ ipPermission.IpRanges = [{
462
+ CidrIp: options.cidr,
463
+ Description: options.description,
464
+ }]
465
+ }
466
+
467
+ if (options.sourceGroup) {
468
+ ipPermission.UserIdGroupPairs = [{
469
+ GroupId: options.sourceGroup,
470
+ Description: options.description,
471
+ }]
472
+ }
473
+
474
+ if (options.inbound) {
475
+ await ec2.authorizeSecurityGroupIngress({
476
+ GroupId: groupId,
477
+ IpPermissions: [ipPermission],
478
+ })
479
+ }
480
+ else {
481
+ await ec2.authorizeSecurityGroupEgress({
482
+ GroupId: groupId,
483
+ IpPermissions: [ipPermission],
484
+ })
485
+ }
486
+
487
+ spinner.succeed('Rule added')
488
+ }
489
+ catch (error: any) {
490
+ cli.error(`Failed to add rule: ${error.message}`)
491
+ process.exit(1)
492
+ }
493
+ })
494
+
495
+ app
496
+ .command('network:elastic-ips', 'List Elastic IP addresses')
497
+ .option('--region <region>', 'AWS region')
498
+ .action(async (options: { region?: string }) => {
499
+ cli.header('Elastic IP Addresses')
500
+
501
+ try {
502
+ const config = await loadValidatedConfig()
503
+ const region = options.region || config.project.region || 'us-east-1'
504
+ const ec2 = new EC2Client(region)
505
+
506
+ const spinner = new cli.Spinner('Fetching Elastic IPs...')
507
+ spinner.start()
508
+
509
+ const result = await ec2.describeAddresses()
510
+ const addresses = result.Addresses || []
511
+
512
+ spinner.succeed(`Found ${addresses.length} Elastic IP(s)`)
513
+
514
+ if (addresses.length === 0) {
515
+ cli.info('No Elastic IPs found')
516
+ return
517
+ }
518
+
519
+ cli.table(
520
+ ['Public IP', 'Allocation ID', 'Association ID', 'Instance', 'Name'],
521
+ addresses.map(addr => [
522
+ addr.PublicIp || 'N/A',
523
+ addr.AllocationId || 'N/A',
524
+ addr.AssociationId || '-',
525
+ addr.InstanceId || '-',
526
+ addr.Tags?.find(t => t.Key === 'Name')?.Value || '-',
527
+ ]),
528
+ )
529
+ }
530
+ catch (error: any) {
531
+ cli.error(`Failed to list Elastic IPs: ${error.message}`)
532
+ process.exit(1)
533
+ }
534
+ })
535
+
536
+ app
537
+ .command('network:route-tables', 'List route tables')
538
+ .option('--region <region>', 'AWS region')
539
+ .option('--vpc <vpcId>', 'Filter by VPC ID')
540
+ .action(async (options: { region?: string; vpc?: string }) => {
541
+ cli.header('Route Tables')
542
+
543
+ try {
544
+ const config = await loadValidatedConfig()
545
+ const region = options.region || config.project.region || 'us-east-1'
546
+ const ec2 = new EC2Client(region)
547
+
548
+ const spinner = new cli.Spinner('Fetching route tables...')
549
+ spinner.start()
550
+
551
+ const filters = options.vpc ? [{ Name: 'vpc-id', Values: [options.vpc] }] : undefined
552
+ const result = await ec2.describeRouteTables({ Filters: filters })
553
+ const tables = result.RouteTables || []
554
+
555
+ spinner.succeed(`Found ${tables.length} route table(s)`)
556
+
557
+ if (tables.length === 0) {
558
+ cli.info('No route tables found')
559
+ return
560
+ }
561
+
562
+ cli.table(
563
+ ['Route Table ID', 'VPC', 'Name', 'Main', 'Associations', 'Routes'],
564
+ tables.map(rt => [
565
+ rt.RouteTableId || 'N/A',
566
+ rt.VpcId || 'N/A',
567
+ rt.Tags?.find(t => t.Key === 'Name')?.Value || '-',
568
+ rt.Associations?.some(a => a.Main) ? 'Yes' : 'No',
569
+ (rt.Associations?.length || 0).toString(),
570
+ (rt.Routes?.length || 0).toString(),
571
+ ]),
572
+ )
573
+ }
574
+ catch (error: any) {
575
+ cli.error(`Failed to list route tables: ${error.message}`)
576
+ process.exit(1)
577
+ }
578
+ })
579
+ }