Skip to content

Commit 669fd7f

Browse files
Merge branch 'improve-terraform-opentofu-support' into alpha
2 parents d23891e + d10da0d commit 669fd7f

28 files changed

+958
-46
lines changed

.github/workflows/common-test.yml

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

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

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

215-
### Terraform
215+
### Terraform and OpenTofu
216216

217-
Only the basic setup is supported. Check the [test case](https://github.com/ServerlessLife/lambda-live-debugger/tree/main/test/terraform-basic).
217+
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).
218218

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

221223
### Custom Setup
222224

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)