File tree Expand file tree Collapse file tree 3 files changed +44
-11
lines changed Expand file tree Collapse file tree 3 files changed +44
-11
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ export class OpenTofuFramework extends TerraformFramework {
28
28
protected get stateCommand ( ) : string {
29
29
return 'tofu show --json' ;
30
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
+ }
31
39
}
32
40
33
41
export const openTofuFramework = new OpenTofuFramework ( ) ;
Original file line number Diff line number Diff line change @@ -47,6 +47,21 @@ export class TerraformFramework implements IFramework {
47
47
return 'Terrform' ;
48
48
}
49
49
50
+ /**
51
+ * Get Terraform state CI command
52
+ */
53
+ protected get stateCommand ( ) : string {
54
+ return 'terraform show --json' ;
55
+ }
56
+
57
+ /**
58
+ *
59
+ * @returns Get command to check if Terraform is installed
60
+ */
61
+ protected get checkInstalledCommand ( ) : string {
62
+ return 'terraform --version' ;
63
+ }
64
+
50
65
/**
51
66
* Can this class handle the current project
52
67
* @returns
@@ -60,9 +75,20 @@ export class TerraformFramework implements IFramework {
60
75
Logger . verbose (
61
76
`[${ this . logName } ] This is not a Terraform or OpenTofu project. There are no *.tf files in ${ path . resolve ( '.' ) } folder.` ,
62
77
) ;
78
+ return false ;
79
+ } else {
80
+ // check if terraform is installed
81
+ try {
82
+ await execAsync ( this . checkInstalledCommand ) ;
83
+ return true ;
84
+ } catch ( error : any ) {
85
+ Logger . verbose (
86
+ `[${ this . logName } ] This is not a ${ this . logName } project. Terraform is not installed.` ,
87
+ { cause : error } ,
88
+ ) ;
89
+ return false ;
90
+ }
63
91
}
64
-
65
- return r ;
66
92
}
67
93
68
94
/**
@@ -242,13 +268,6 @@ export class TerraformFramework implements IFramework {
242
268
return lambdas ;
243
269
}
244
270
245
- /**
246
- * Get Terraform state CI command
247
- */
248
- protected get stateCommand ( ) : string {
249
- return 'terraform show --json' ;
250
- }
251
-
252
271
protected async readTerraformState ( ) : Promise < TerraformResource [ ] > {
253
272
// Is there a better way to get the Terraform state???
254
273
Original file line number Diff line number Diff line change @@ -19,10 +19,16 @@ const observableMode = process.env.OBSERVABLE_MODE === 'true';
19
19
describe ( 'opentofu-basic' , async ( ) => {
20
20
const folder = await getTestProjectFolder ( 'opentofu-basic' ) ;
21
21
let lldProcess : ChildProcess | undefined ;
22
+ const args : string [ ] = [ ] ;
22
23
23
24
beforeAll ( async ( ) => {
25
+ if ( process . env . RUN_TEST_FROM_CLI === 'true' ) {
26
+ // localy I need to specify it is OpenTofu, because I have also Terraform installed
27
+ args . push ( '--framework=opentofu' ) ;
28
+ }
29
+
24
30
if ( process . env . CI === 'true' || process . env . RUN_TEST_FROM_CLI === 'true' ) {
25
- lldProcess = await startDebugger ( folder , [ '--framework=opentofu' ] ) ;
31
+ lldProcess = await startDebugger ( folder , args ) ;
26
32
}
27
33
} ) ;
28
34
@@ -137,7 +143,7 @@ describe('opentofu-basic', async () => {
137
143
138
144
test ( 'remove infra' , async ( ) => {
139
145
if ( process . env . CI === 'true' || process . env . RUN_TEST_FROM_CLI === 'true' ) {
140
- await removeInfra ( lldProcess , folder , [ '--framework=opentofu' ] ) ;
146
+ await removeInfra ( lldProcess , folder , args ) ;
141
147
const lambdaName = await getFunctionName (
142
148
folder ,
143
149
'lambda-test-js-commonjs_1_name' ,
You can’t perform that action at this time.
0 commit comments