Skip to content

Commit 39b27c0

Browse files
feat: Improve Terraform and OpenTofu support (#102)
* feat: Improve Terraform and OpenTofu support * feat: Improve Terraform and add OpenTofu support * Improve error log * Improve logs
1 parent ecceb77 commit 39b27c0

28 files changed

+957
-46
lines changed

.github/workflows/common-test.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ jobs:
571571
role-to-assume: ${{ secrets.AWS_ROLE }}
572572
role-session-name: GitHubActions
573573
- name: Setup Terraform
574-
uses: hashicorp/setup-terraform@v1
574+
uses: hashicorp/setup-terraform@v3
575575
- name: Terraform Init
576576
run: |
577577
./create_bucket.sh lld-terraform-basic
@@ -588,3 +588,59 @@ jobs:
588588
run: npx vitest --retry 1 test/terraform-basic.test.ts
589589
- name: Test - observability mode
590590
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/terraform-basic.test.ts
591+
592+
test-opentofu-basic:
593+
runs-on: ubuntu-latest
594+
concurrency:
595+
group: test-opentofu-basic
596+
steps:
597+
- uses: actions/checkout@v4
598+
- name: Use Node.js
599+
uses: actions/setup-node@v4
600+
with:
601+
node-version: ${{ env.node_version }}
602+
registry-url: 'https://registry.npmjs.org'
603+
- name: Install dependencies
604+
run: |
605+
node prepareForTest.js opentofu-basic
606+
npm i
607+
- name: Download build artifact
608+
uses: actions/download-artifact@v4
609+
if: ${{ inputs.mode == 'build' }}
610+
with:
611+
name: dist
612+
path: dist
613+
- name: Install lambda-live-debugger globally
614+
if: ${{ inputs.mode == 'global' }}
615+
run: |
616+
npm i lambda-live-debugger -g
617+
working-directory: test
618+
- name: Install lambda-live-debugger locally
619+
if: ${{ inputs.mode == 'local' }}
620+
run: |
621+
npm i lambda-live-debugger
622+
working-directory: test
623+
- name: Configure AWS Credentials
624+
uses: aws-actions/configure-aws-credentials@v4
625+
with:
626+
aws-region: eu-west-1
627+
role-to-assume: ${{ secrets.AWS_ROLE }}
628+
role-session-name: GitHubActions
629+
- name: Setup OpenTofu
630+
uses: opentofu/setup-opentofu@v1
631+
- name: OpenTofu Init
632+
run: |
633+
./create_bucket.sh lld-opentofu-basic
634+
tofu init -backend-config="bucket=lld-opentofu-basic"
635+
working-directory: test/opentofu-basic
636+
- name: Destroy
637+
run: npm run destroy
638+
working-directory: test/opentofu-basic
639+
continue-on-error: true
640+
- name: Deploy
641+
run: npm run deploy
642+
working-directory: test/opentofu-basic
643+
- name: Test
644+
run: npx vitest --retry 1 test/opentofu-basic.test.ts
645+
- name: Test - observability mode
646+
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/opentofu-basic.test.ts

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@
261261
"type": "node",
262262
"cwd": "${workspaceRoot}/test/terraform-basic"
263263
},
264+
{
265+
"name": "LLDebugger - OpenTofu basic",
266+
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
267+
"args": ["../../src/lldebugger.ts", "--config-env=test"],
268+
"request": "launch",
269+
"skipFiles": ["<node_internals>/**"],
270+
"console": "integratedTerminal",
271+
"type": "node",
272+
"cwd": "${workspaceRoot}/test/opentofu-basic"
273+
},
274+
{
275+
"name": "LLDebugger - OpenTofu basic - observability",
276+
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
277+
"args": ["../../src/lldebugger.ts", "--config-env=test", "-o"],
278+
"request": "launch",
279+
"skipFiles": ["<node_internals>/**"],
280+
"console": "integratedTerminal",
281+
"type": "node",
282+
"cwd": "${workspaceRoot}/test/opentofu-basic"
283+
},
264284
{
265285
"name": "LLDebugger - CDK config",
266286
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It supports the following frameworks:
99
- AWS CDK v2
1010
- Serverless Framework v3 (SLS) and [`osls` fork](https://github.com/oss-serverless/serverless)
1111
- AWS Serverless Application Model (SAM)
12-
- Terraform
12+
- Terraform and OpenTofu
1313
- Any other framework or setup by implementing a simple function in TypeScript
1414
- ... (Need support for another framework? Let me know!)
1515

@@ -211,11 +211,13 @@ Use the `stage` parameter to pass the stage/environment name.
211211

212212
Use the `config-env` parameter to pass the stage/environment name.
213213

214-
### Terraform
214+
### Terraform and OpenTofu
215215

216-
Only the basic setup is supported. Check the [test case](https://github.com/ServerlessLife/lambda-live-debugger/tree/main/test/terraform-basic).
216+
Multiple configurations are supported, including [serverless.tf](https://serverless.tf/) framework. You can explore [relevant test cases here](https://github.com/ServerlessLife/lambda-live-debugger/tree/main/test/terraform-basic).
217217

218-
I am not a Terraform developer, so I only know the basics. Please provide a sample project so I can build better support.
218+
If you use TypeScript, Lambda Live Debugger should automatically locate source files, even when they are transpiled to JavaScript.
219+
220+
If you encounter an unsupported configuration, please open a [GitHub Issue](https://github.com/ServerlessLife/lambda-live-debugger/issues).
219221

220222
### Custom Setup
221223

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"test-sam-alt-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-alt.test.ts",
7373
"test-terraform-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/terraform-basic.test.ts",
7474
"test-terraform-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/terraform-basic.test.ts",
75+
"test-opentofu-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/opentofu-basic.test.ts",
76+
"test-opentofu-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/opentofu-basic.test.ts",
7577
"docs:dev": "vitepress dev",
7678
"docs:build": "vitepress build",
7779
"docs:preview": "vitepress preview"
@@ -154,6 +156,7 @@
154156
"test/osls-esbuild-cjs",
155157
"test/sam-basic",
156158
"test/sam-alt",
157-
"test/terraform-basic"
159+
"test/terraform-basic",
160+
"test/opentofu-basic"
158161
]
159162
}

src/frameworks/openTofuFramework.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { exec } from 'child_process';
2+
import { promisify } from 'util';
3+
import { TerraformFramework } from './terraformFramework.js';
4+
5+
export const execAsync = promisify(exec);
6+
7+
/**
8+
* Support for Terraform framework
9+
*/
10+
export class OpenTofuFramework extends TerraformFramework {
11+
/**
12+
* Framework name
13+
*/
14+
public get name(): string {
15+
return 'opentofu';
16+
}
17+
18+
/**
19+
* Name of the framework in logs
20+
*/
21+
protected get logName(): string {
22+
return 'OpenTofu';
23+
}
24+
25+
/**
26+
* Get OpenTofu state CI command
27+
*/
28+
protected get stateCommand(): string {
29+
return 'tofu show --json';
30+
}
31+
32+
/**
33+
*
34+
* @returns Get command to check if OpenTodu is installed
35+
*/
36+
protected get checkInstalledCommand(): string {
37+
return 'tofu --version';
38+
}
39+
}
40+
41+
export const openTofuFramework = new OpenTofuFramework();

0 commit comments

Comments
 (0)