Skip to content

Commit 1dd3931

Browse files
committed
feat: update cli and docs
1 parent ea2a50d commit 1dd3931

File tree

12 files changed

+1229
-541
lines changed

12 files changed

+1229
-541
lines changed

README.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
![Eco-Infra Logo](./logo.svg)
22

3-
**ecoinfra** is a powerful tool that helps you predict, asses, and reduce the environmental impact of your cloud
3+
**ecoinfra** is a powerful tool that helps you predict, assess, and reduce the environmental impact of your cloud
44
infrastructure.
5-
By integrating your existing or new IaC project you can harness predictive sustainability into your cloud operations.
5+
By analyzing Terraform plan outputs, you can harness predictive sustainability into your cloud operations.
66

77
Visit our website at [**Eco-Infra.com**](https://eco-infra.com) to learn more about how we're revolutionizing
88
eco-friendly cloud computing.
@@ -29,38 +29,52 @@ To start using the **ecoinfra** tool, follow these simple steps:
2929
### Step 3: Run the Tool
3030
Run the tool in a supported CI environment
3131

32-
[GitHub Actions](https://github.com/marketplace/actions/eco-infra-action)
32+
[GitHub Actions](https://github.com/marketplace/actions/eco-infra-action)
3333
```yaml
3434
- name: Eco-Infra
3535
uses: ecoinfra/ecoinfra-action@v1.1.2
3636
with:
3737
token: 'TOKEN'
3838
project-name: 'my-project'
39-
path: './terraform'
40-
apply: 'true'
39+
plan-file: './terraform'
4140
```
4241
43-
Or Run the tool from your command line interface (CLI) or terminal.
42+
Run the tool from your command line interface (CLI) or terminal.
4443
4544
```bash
46-
$ ecoinfra-PLATFORM --token {{Token}} --project-name {{Unique Project Name}} {{Project Directory}}
45+
$ ecoinfra-PLATFORM --token {{Token}} --project-name {{Unique Project Name}} --plan-file {{Plan JSON File}}
4746
```
4847

49-
An example:
48+
Example:
5049

5150
```bash
52-
$ ecoinfra-PLATFORM --token c3da55b6-b8a0-43ad-b513-a751e76553de --project-name "Production Account" ./prod
51+
# Generate the Terraform plan JSON file
52+
$ terraform plan -out=plan.out
53+
$ terraform show -json plan.out > plan.json
54+
55+
# Analyze with ecoinfra
56+
$ ecoinfra-PLATFORM --token c3dc55b6-78a0-43ad-2513-a751e76553de --project-name "Production Account" --plan-file plan.json
5357
```
5458
---
5559
## 📖 Documentation
5660

57-
The tool requires two arguments and a path to your IaC project (Where you run terraform form):
61+
### Required Parameters
5862

5963
- `--token` - Your unique API key.
6064
- `--project-name` - A unique name for your project.
61-
- `{{Project Directory}}` - The directory of your IaC project.
65+
- `--plan-file` - Path to the Terraform plan JSON file.
66+
67+
### Optional Parameters
68+
69+
- `--breakdown` - Show detailed resource breakdown.
70+
71+
### Generating the Plan File
6272

63-
You will be required you to run terraform init before running the tool.
73+
Generate the plan file using Terraform:
74+
```bash
75+
terraform plan -out=plan.out
76+
terraform show -json plan.out > plan.json
77+
```
6478

6579
## Supported Providers
6680

@@ -82,11 +96,17 @@ You will be required you to run terraform init before running the tool.
8296
4. Run the tool!
8397

8498
```bash
85-
git clone git@github.com:eco-infra/ecoinfra.git
99+
git clone git@github.com:eco-infra/ecoinfra.git
86100
npm i
87101
npm run package
88-
./build/ecoinfra-PLATFORM --token {{Token}} --project-name {{Unique Project Name}} {{Project Directory}}
102+
103+
# Generate the Terraform plan file
104+
terraform plan -out=plan.out
105+
terraform show -json plan.out > plan.json
106+
107+
# Run the tool
108+
./build/ecoinfra-PLATFORM --token {{Token}} --project-name {{Unique Project Name}} --plan-file plan.json
89109
```
90110

91111
# Contributing
92-
Please read the contribution guidelines before contributing to the project. [CONTRIBUTING.md](./CONTRIBUTING.md)
112+
Please read the contribution guidelines before contributing to the project. [CONTRIBUTING.md](./CONTRIBUTING.md)

app/cli/main.cli.ts

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,42 @@ import arg from 'arg';
33
export default class MainCli {
44
private token: string;
55

6-
private breakdown: boolean
7-
8-
private apply: boolean
9-
10-
private _project: string;
6+
private breakdown: boolean;
117

128
private projectName: string;
139

14-
public args: arg.Result<any>
10+
private planFile: string;
1511

16-
constructor(argResults: arg.Result<any>, project?: string) {
17-
this.args = argResults
12+
public args: arg.Result<any>;
1813

19-
if (!this.args['--token']) throw new Error('Specify token --token')
14+
constructor(argResults: arg.Result<any>) {
15+
this.args = argResults;
2016

21-
if (!this.args['--project-name']) throw new Error('Specify project name --project-name')
17+
if (!this.args['--token']) throw new Error('Specify token --token');
2218

23-
this.token = this.args['--token']
24-
this.breakdown = this.args['--breakdown'] ?? false
25-
this.apply = this.args['--apply'] ?? false
26-
this._project = this.setProjectPath(project)
27-
this.projectName = this.args['--project-name']
28-
}
19+
if (!this.args['--project-name']) throw new Error('Specify project name --project-name');
2920

30-
/**
31-
* @description Set the project path, making sure that the path ends with /
32-
*/
33-
setProjectPath(path?: string) {
34-
if (!path) return './'
21+
if (!this.args['--plan-file']) throw new Error('Specify plan file --plan-file <path>');
3522

36-
return path.endsWith('/') ? path : path.concat('/')
37-
}
38-
39-
get project(): string {
40-
return this._project;
23+
this.token = this.args['--token'];
24+
this.breakdown = this.args['--breakdown'] ?? false;
25+
this.planFile = this.args['--plan-file'];
26+
this.projectName = this.args['--project-name'];
4127
}
4228

4329
getToken(): string {
44-
return this.token
30+
return this.token;
4531
}
4632

4733
getProjectName(): string {
48-
return this.projectName
34+
return this.projectName;
4935
}
5036

51-
getApply(): boolean {
52-
return this.apply
37+
getBreakdown(): boolean {
38+
return this.breakdown;
5339
}
5440

55-
getBreakdown(): boolean {
56-
return this.breakdown
41+
getPlanFile(): string {
42+
return this.planFile;
5743
}
5844
}

0 commit comments

Comments
 (0)