Skip to content

Commit 316b19f

Browse files
fix: Support .tofu files [#133] (#134)
1 parent 4393854 commit 316b19f

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

src/frameworks/openTofuFramework.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { exec } from 'child_process';
22
import { promisify } from 'util';
33
import { TerraformFramework } from './terraformFramework.js';
4+
import path from 'path';
5+
import { Logger } from '../logger.js';
6+
import fs from 'fs/promises';
47

58
export const execAsync = promisify(exec);
69

@@ -15,6 +18,40 @@ export class OpenTofuFramework extends TerraformFramework {
1518
return 'opentofu';
1619
}
1720

21+
/**
22+
* Can this class handle the current project
23+
* @returns
24+
*/
25+
public async canHandle(): Promise<boolean> {
26+
// check for any file with .tf, .tf.json, .tofu, or .tofu.json extension
27+
const files = await fs.readdir(process.cwd());
28+
const r = files.some(
29+
(f) =>
30+
f.endsWith('.tf') ||
31+
f.endsWith('.tf.json') ||
32+
f.endsWith('.tofu') ||
33+
f.endsWith('.tofu.json'),
34+
);
35+
36+
if (!r) {
37+
Logger.verbose(
38+
`[${this.logName}] This is not a ${this.logName} project. There are no *.tf, *.tf.json, *.tofu, or *.tofu.json files in ${path.resolve('.')} folder.`,
39+
);
40+
return false;
41+
} else {
42+
// check if Terraform or OpenTofu is installed
43+
try {
44+
await execAsync(this.checkInstalledCommand);
45+
return true;
46+
} catch {
47+
Logger.verbose(
48+
`[${this.logName}] This is not a ${this.logName} project. ${this.logName} is not installed.`,
49+
);
50+
return false;
51+
}
52+
}
53+
}
54+
1855
/**
1956
* Name of the framework in logs
2057
*/

src/frameworks/terraformFramework.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ export class TerraformFramework implements IFramework {
6767
* @returns
6868
*/
6969
public async canHandle(): Promise<boolean> {
70-
// is there any filey with *.tf extension
70+
// check for any files with .tf or .tf.json extension
7171
const files = await fs.readdir(process.cwd());
72-
const r = files.some((f) => f.endsWith('.tf'));
72+
const r = files.some((f) => f.endsWith('.tf') || f.endsWith('.tf.json'));
7373

7474
if (!r) {
7575
Logger.verbose(
76-
`[${this.logName}] This is not a ${this.logName} project. There are no *.tf files in ${path.resolve('.')} folder.`,
76+
`[${this.logName}] This is not a ${this.logName} project. There are no *.tf or *.tf.json files in ${path.resolve('.')} folder.`,
7777
);
7878
return false;
7979
} else {

test/cdk-basic/CdkbasicStack.yaml

Whitespace-only changes.

test/cdk-basic/cdk-synth.log

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
2+
use `logGroup` instead
3+
This API will be removed in the next major release.
4+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
5+
use `logGroup` instead
6+
This API will be removed in the next major release.
7+
Bundling asset CdkbasicStack/TestTsCommonJs/Code/Stage...
8+
9+
...5d8888acd02a3a8300fd1812aaaadea60eb4d5e94fdc8b74-building/index.js 2.5kb
10+
11+
⚡ Done in 5ms
12+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
13+
use `logGroup` instead
14+
This API will be removed in the next major release.
15+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
16+
use `logGroup` instead
17+
This API will be removed in the next major release.
18+
Bundling asset CdkbasicStack/TestTsEsModule/Code/Stage...
19+
20+
...6da3d4a35f4bd8700dc1cd1e51cb1f8e221896ac5b1e3a6-building/index.mjs 952b
21+
22+
⚡ Done in 3ms
23+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
24+
use `logGroup` instead
25+
This API will be removed in the next major release.
26+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
27+
use `logGroup` instead
28+
This API will be removed in the next major release.
29+
Bundling asset CdkbasicStack/TestJsCommonJs/Code/Stage...
30+
31+
...13fdc37e5dff5529e8d38cc279c44a91ddc79ee0a6999101-building/index.js 970b
32+
33+
⚡ Done in 3ms
34+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
35+
use `logGroup` instead
36+
This API will be removed in the next major release.
37+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
38+
use `logGroup` instead
39+
This API will be removed in the next major release.
40+
Bundling asset CdkbasicStack2/TestJsEsModule/Code/Stage...
41+
42+
...8ac79e932e94cba6a9050b4975ea1709894b6ab846714ba-building/index.mjs 952b
43+
44+
⚡ Done in 3ms
45+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
46+
use `logGroup` instead
47+
This API will be removed in the next major release.
48+
[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
49+
use `logGroup` instead
50+
This API will be removed in the next major release.
51+
You currently have 50 unconfigured feature flags that may require attention to keep your application up-to-date. Run 'cdk flags' to learn more.
52+
53+
NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)
54+
55+
34892 CDK CLI will collect telemetry data on command usage starting at version 2.1100.0 (unless opted out)
56+
57+
Overview: We do not collect customer content and we anonymize the
58+
telemetry we do collect. See the attached issue for more
59+
information on what data is collected, why, and how to
60+
opt-out. Telemetry will NOT be collected for any CDK CLI
61+
version prior to version 2.1100.0 - regardless of
62+
opt-in/out. You can also preview the telemetry we will start
63+
collecting by logging it to a local file, by adding
64+
`--unstable=telemetry --telemetry-file=my/local/file` to any
65+
`cdk` command.
66+
67+
Affected versions: cli: ^2.0.0
68+
69+
More information at: https://github.com/aws/aws-cdk/issues/34892
70+
71+
72+
If you don’t want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 34892".
File renamed without changes.

0 commit comments

Comments
 (0)