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 {
2828 protected get stateCommand ( ) : string {
2929 return 'tofu show --json' ;
3030 }
31+
32+ /**
33+ *
34+ * @returns Get command to check if OpenTodu is installed
35+ */
36+ protected get checkInstalledCommand ( ) : string {
37+ return 'tofu --version' ;
38+ }
3139}
3240
3341export const openTofuFramework = new OpenTofuFramework ( ) ;
Original file line number Diff line number Diff line change @@ -47,6 +47,21 @@ export class TerraformFramework implements IFramework {
4747 return 'Terrform' ;
4848 }
4949
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+
5065 /**
5166 * Can this class handle the current project
5267 * @returns
@@ -60,9 +75,20 @@ export class TerraformFramework implements IFramework {
6075 Logger . verbose (
6176 `[${ this . logName } ] This is not a Terraform or OpenTofu project. There are no *.tf files in ${ path . resolve ( '.' ) } folder.` ,
6277 ) ;
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+ }
6391 }
64-
65- return r ;
6692 }
6793
6894 /**
@@ -242,13 +268,6 @@ export class TerraformFramework implements IFramework {
242268 return lambdas ;
243269 }
244270
245- /**
246- * Get Terraform state CI command
247- */
248- protected get stateCommand ( ) : string {
249- return 'terraform show --json' ;
250- }
251-
252271 protected async readTerraformState ( ) : Promise < TerraformResource [ ] > {
253272 // Is there a better way to get the Terraform state???
254273
Original file line number Diff line number Diff line change @@ -19,10 +19,16 @@ const observableMode = process.env.OBSERVABLE_MODE === 'true';
1919describe ( 'opentofu-basic' , async ( ) => {
2020 const folder = await getTestProjectFolder ( 'opentofu-basic' ) ;
2121 let lldProcess : ChildProcess | undefined ;
22+ const args : string [ ] = [ ] ;
2223
2324 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+
2430 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 ) ;
2632 }
2733 } ) ;
2834
@@ -137,7 +143,7 @@ describe('opentofu-basic', async () => {
137143
138144 test ( 'remove infra' , async ( ) => {
139145 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 ) ;
141147 const lambdaName = await getFunctionName (
142148 folder ,
143149 'lambda-test-js-commonjs_1_name' ,
You can’t perform that action at this time.
0 commit comments