Skip to content

feat: Improve Terraform and OpenTofu support #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion .github/workflows/common-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ jobs:
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubActions
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
uses: hashicorp/setup-terraform@v3
- name: Terraform Init
run: |
./create_bucket.sh lld-terraform-basic
Expand All @@ -584,3 +584,59 @@ jobs:
run: npx vitest --retry 1 test/terraform-basic.test.ts
- name: Test - observability mode
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/terraform-basic.test.ts

test-opentofu-basic:
runs-on: ubuntu-latest
concurrency:
group: test-opentofu-basic
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: |
node prepareForTest.js opentofu-basic
npm i
- name: Download build artifact
uses: actions/download-artifact@v4
if: ${{ inputs.mode == 'build' }}
with:
name: dist
path: dist
- name: Install lambda-live-debugger globally
if: ${{ inputs.mode == 'global' }}
run: |
npm i lambda-live-debugger -g
working-directory: test
- name: Install lambda-live-debugger locally
if: ${{ inputs.mode == 'local' }}
run: |
npm i lambda-live-debugger
working-directory: test
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-west-1
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: GitHubActions
- name: Setup OpenTofu
uses: opentofu/setup-opentofu@v1
- name: OpenTofu Init
run: |
./create_bucket.sh lld-opentofu-basic
tofu init -backend-config="bucket=lld-opentofu-basic"
working-directory: test/opentofu-basic
- name: Destroy
run: npm run destroy
working-directory: test/opentofu-basic
continue-on-error: true
- name: Deploy
run: npm run deploy
working-directory: test/opentofu-basic
- name: Test
run: npx vitest --retry 1 test/opentofu-basic.test.ts
- name: Test - observability mode
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/opentofu-basic.test.ts
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@
"type": "node",
"cwd": "${workspaceRoot}/test/terraform-basic"
},
{
"name": "LLDebugger - OpenTofu basic",
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
"args": ["../../src/lldebugger.ts", "--config-env=test"],
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal",
"type": "node",
"cwd": "${workspaceRoot}/test/opentofu-basic"
},
{
"name": "LLDebugger - OpenTofu basic - observability",
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
"args": ["../../src/lldebugger.ts", "--config-env=test", "-o"],
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"console": "integratedTerminal",
"type": "node",
"cwd": "${workspaceRoot}/test/opentofu-basic"
},
{
"name": "LLDebugger - CDK config",
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ It supports the following frameworks:
- AWS CDK v2
- Serverless Framework v3 (SLS) and [`osls` fork](https://github.com/oss-serverless/serverless)
- AWS Serverless Application Model (SAM)
- Terraform
- Terraform and OpenTofu
- Any other framework or setup by implementing a simple function in TypeScript
- ... (Need support for another framework? Let me know!)

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

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

### Terraform
### Terraform and OpenTofu

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

I am not a Terraform developer, so I only know the basics. Please provide a sample project so I can build better support.
If you use TypeScript, Lambda Live Debugger should automatically locate source files, even when they are transpiled to JavaScript.

If you encounter an unsupported configuration, please open a [GitHub Issue](https://github.com/ServerlessLife/lambda-live-debugger/issues).

### Custom Setup

Expand Down
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"test-sam-alt-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-alt.test.ts",
"test-terraform-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/terraform-basic.test.ts",
"test-terraform-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/terraform-basic.test.ts",
"test-opentofu-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/opentofu-basic.test.ts",
"test-opentofu-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/opentofu-basic.test.ts",
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
Expand Down Expand Up @@ -154,6 +156,7 @@
"test/osls-esbuild-cjs",
"test/sam-basic",
"test/sam-alt",
"test/terraform-basic"
"test/terraform-basic",
"test/opentofu-basic"
]
}
41 changes: 41 additions & 0 deletions src/frameworks/openTofuFramework.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { exec } from 'child_process';
import { promisify } from 'util';
import { TerraformFramework } from './terraformFramework.js';

export const execAsync = promisify(exec);

/**
* Support for Terraform framework
*/
export class OpenTofuFramework extends TerraformFramework {
/**
* Framework name
*/
public get name(): string {
return 'opentofu';
}

/**
* Name of the framework in logs
*/
protected get logName(): string {
return 'OpenTofu';
}

/**
* Get OpenTofu state CI command
*/
protected get stateCommand(): string {
return 'tofu show --json';
}

/**
*
* @returns Get command to check if OpenTodu is installed
*/
protected get checkInstalledCommand(): string {
return 'tofu --version';
}
}

export const openTofuFramework = new OpenTofuFramework();
Loading