Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 1,
"stdout": "Error: No configuration files"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAWS } from './../../../src/aws-terraform-command-handler';
import { TerraformCommandHandlerAWS } from "../../../src/aws-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAWS: TerraformCommandHandlerAWS = new TerraformCommandHandlerAWS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 1,
"stdout": "Execution failed: invalid config files"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAWS } from './../../../src/aws-terraform-command-handler';
import { TerraformCommandHandlerAWS } from "../../../src/aws-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAWS: TerraformCommandHandlerAWS = new TerraformCommandHandlerAWS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "provider aws"
},
"terraform apply -auto-approve -no-color": {
"terraform apply -input=false -auto-approve -no-color": {
"code": 0,
"stdout": "Executed successfully"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAWS } from './../../../src/aws-terraform-command-handler';
import { TerraformCommandHandlerAWS } from "../../../src/aws-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAWS: TerraformCommandHandlerAWS = new TerraformCommandHandlerAWS();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "provider aws"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 0,
"stdout": "Executed successfully"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAWS } from './../../../src/aws-terraform-command-handler';
import { TerraformCommandHandlerAWS } from "../../../src/aws-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAWS: TerraformCommandHandlerAWS = new TerraformCommandHandlerAWS();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 1,
"stdout": "Error: No configuration files"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAzureRM } from './../../../src/azure-terraform-command-handler';
import { TerraformCommandHandlerAzureRM } from "../../../src/azure-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAzureRM: TerraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 1,
"stdout": "Execution failed: invalid config files"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAzureRM } from './../../../src/azure-terraform-command-handler';
import { TerraformCommandHandlerAzureRM } from "../../../src/azure-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAzureRM: TerraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve -no-color": {
"terraform apply -input=false -auto-approve -no-color": {
"code": 0,
"stdout": "Executed successfully"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAzureRM } from './../../../src/azure-terraform-command-handler';
import { TerraformCommandHandlerAzureRM } from "../../../src/azure-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAzureRM: TerraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 0,
"stdout": "Executed successfully"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAzureRM } from './../../../src/azure-terraform-command-handler';
import { TerraformCommandHandlerAzureRM } from "../../../src/azure-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAzureRM: TerraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();
Expand Down
62 changes: 50 additions & 12 deletions ...Tests/ApplyTests/Azure/AzureApplySuccessAuthenticationSchemeWorkloadIdentityFederation.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
import { TokenGenerator } from './../../../src/id-token-generator';
import { TokenGenerator } from "../../../src/id-token-generator";

let tp = path.join(__dirname, './AzureApplySuccessAuthenticationSchemeWorkloadIdentityFederationL0.js');
let tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(tp);

// Mock the TokenGenerator class
tr.registerMock('../../../src/id-token-generator', {
TokenGenerator: function() {
return {
generate: function() {
console.log('Mocked token generator called');
return Promise.resolve('DummyIdToken');
}
};
},
generateIdToken: function() {
console.log('Mocked generateIdToken called');
return Promise.resolve('DummyIdToken');
}
});

// Mock the azure-pipelines-tasks-artifacts-common/webapi module
tr.registerMock('azure-pipelines-tasks-artifacts-common/webapi', {
getFederatedToken: function() {
console.log('Mocked getFederatedToken called');
return Promise.resolve('DummyFederatedToken');
}
});

tr.setInput('provider', 'azurerm');
tr.setInput('command', 'apply');
tr.setInput('workingDirectory', 'DummyWorkingDirectory');
tr.setInput('environmentServiceNameAzureRM', 'AzureRM');
tr.setInput('commandOptions', '');

tr.setInput('environmentServiceNameAzureRM', 'AzureRM');
tr.setInput('environmentServiceIdAzureRM', 'AzureRM');

process.env['ENDPOINT_AUTH_SCHEME_AzureRM'] = 'WorkloadIdentityFederation';
process.env['ENDPOINT_DATA_AzureRM_SUBSCRIPTIONID'] = 'DummmySubscriptionId';
process.env['ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID'] = 'DummyTenantId';
process.env['ENDPOINT_AUTH_PARAMETER_AzureRM_SERVICEPRINCIPALID'] = 'DummyServicePrincipalId';
process.env['ENDPOINT_AUTH_PARAMETER_AzureRM_TENANTID'] = 'DummyTenantId';
process.env['ENDPOINT_AUTH_PARAMETER_AzureRM_IDTOKEN'] = 'DummyIdToken';

// Pre-set environment variables that would be set by the handler
process.env['ARM_CLIENT_ID'] = 'DummyServicePrincipalId';
process.env['ARM_TENANT_ID'] = 'DummyTenantId';
process.env['ARM_SUBSCRIPTION_ID'] = 'DummmySubscriptionId';
process.env['ARM_OIDC_TOKEN'] = 'DummyIdToken';
process.env['ARM_USE_OIDC'] = 'true';

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"which": {
Expand All @@ -25,21 +59,25 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"terraform": true
},
"exec": {
"terraform providers": {
"terraform apply -auto-approve -input=false": {
"code": 0,
"stdout": "Executed successfully"
"stdout": "Executed Successfully"
},
"terraform apply -input=false -auto-approve": {
"code": 0,
"stdout": "Executed Successfully"
},
"terraform apply -auto-approve": {
"code": 0,
"stdout": "Executed successfully"
"stdout": "Executed Successfully"
},
"terraform providers": {
"code": 0,
"stdout": "provider[registry.terraform.io/hashicorp/azurerm]"
}
}
}

var mock = {
"generateIdToken" : function(command) { return Promise.resolve('12345'); }
}

tr.registerMock('./id-token-generator', mock);
tr.setAnswers(a);
tr.run();

tr.run();
37 changes: 28 additions & 9 deletions ...sts/ApplyTests/Azure/AzureApplySuccessAuthenticationSchemeWorkloadIdentityFederationL0.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import { TerraformCommandHandlerAzureRM } from './../../../src/azure-terraform-command-handler';
import tl = require('azure-pipelines-task-lib');
import { TerraformCommandHandlerAzureRM } from "../../../src/azure-terraform-command-handler";
import tl = require('azure-pipelines-task-lib/task');

let terraformCommandHandlerAzureRM: TerraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();
let terraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();

export async function run() {
async function run() {
try {
const response = await terraformCommandHandlerAzureRM.apply();
if (response === 0) {
console.log("Starting apply command execution");
console.log("Provider:", tl.getInput('provider'));
console.log("Command:", tl.getInput('command'));
console.log("Working Directory:", tl.getInput('workingDirectory'));
console.log("Command Options:", tl.getInput('commandOptions'));
console.log("Environment Service Name:", tl.getInput('environmentServiceNameAzureRM'));
console.log("Auth Scheme:", process.env['ENDPOINT_AUTH_SCHEME_AzureRM']);

// Debug environment variables
console.log("ARM_CLIENT_ID:", process.env['ARM_CLIENT_ID']);
console.log("ARM_TENANT_ID:", process.env['ARM_TENANT_ID']);
console.log("ARM_SUBSCRIPTION_ID:", process.env['ARM_SUBSCRIPTION_ID']);
console.log("ARM_OIDC_TOKEN:", process.env['ARM_OIDC_TOKEN'] ? 'Set' : 'Not set');
console.log("ARM_USE_OIDC:", process.env['ARM_USE_OIDC']);

try {
await terraformCommandHandlerAzureRM.apply();
console.log("Apply command completed successfully");
tl.setResult(tl.TaskResult.Succeeded, 'AzureApplySuccessAuthenticationSchemeWorkloadIdentityFederationL0 should have succeeded.');
} else{
tl.setResult(tl.TaskResult.Failed, 'AzureApplySuccessAuthenticationSchemeWorkloadIdentityFederationL0 should have succeeded but failed.');
} catch (applyError) {
console.log("Apply command execution failed with error:", applyError instanceof Error ? applyError.message : applyError);
console.log("Error stack:", applyError instanceof Error ? applyError.stack : 'No stack available');
throw applyError;
}
} catch(error) {
} catch (error) {
console.log("Test failed with error:", error instanceof Error ? error.message : error);
tl.setResult(tl.TaskResult.Failed, 'AzureApplySuccessAuthenticationSchemeWorkloadIdentityFederationL0 should have succeeded but failed.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"code": 0,
"stdout": "Executed successfully"
},
"terraform apply -auto-approve": {
"terraform apply -auto-approve -input=false": {
"code": 0,
"stdout": "Executed successfully"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TerraformCommandHandlerAzureRM } from './../../../src/azure-terraform-command-handler';
import { TerraformCommandHandlerAzureRM } from "../../../src/azure-terraform-command-handler";
import tl = require('azure-pipelines-task-lib');

let terraformCommandHandlerAzureRM: TerraformCommandHandlerAzureRM = new TerraformCommandHandlerAzureRM();
Expand Down
Loading
Loading