Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 259175b

Browse files
neerajmandaltbarlow12
authored andcommitted
feat: specify subscription ID in serverless yaml
1 parent 3691a3f commit 259175b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/plugins/login/azureLoginPlugin.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("Login Plugin", () => {
105105
expect(AzureLoginService.interactiveLogin).toBeCalled()
106106
expect(sls.variables["subscriptionId"]).toEqual("test-subs-id");
107107
expect(sls.cli.log).toBeCalledWith("Using subscription ID: test-subs-id");
108-
})
108+
});
109109

110110
it("Uses the default subscription ID" , async () => {
111111
const sls = MockFactory.createTestServerless();
@@ -115,4 +115,14 @@ describe("Login Plugin", () => {
115115
expect(sls.variables["subscriptionId"]).toEqual("azureSubId");
116116
expect(sls.cli.log).toBeCalledWith("Using subscription ID: azureSubId");
117117
});
118+
119+
it("Uses the subscription ID specified in serverless yaml", async () => {
120+
const sls = MockFactory.createTestServerless();
121+
const opt = MockFactory.createTestServerlessOptions();
122+
sls.service.provider["subscriptionId"] = "test-subs-id";
123+
await invokeLoginHook(false, sls, opt);
124+
expect(AzureLoginService.interactiveLogin).toBeCalled()
125+
expect(sls.variables["subscriptionId"]).toEqual("test-subs-id");
126+
expect(sls.cli.log).toBeCalledWith("Using subscription ID: test-subs-id");
127+
});
118128
});

src/plugins/login/azureLoginPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class AzureLoginPlugin extends AzureBasePlugin<AzureLoginOptions> {
2828
this.serverless.variables["azureCredentials"] = authResult.credentials;
2929
// Use environment variable for sub ID or use the first subscription in the list (service principal can
3030
// have access to more than one subscription)
31-
this.serverless.variables["subscriptionId"] = this.options.subscriptionId || process.env.azureSubId || authResult.subscriptions[0].id;
31+
this.serverless.variables["subscriptionId"] = this.options.subscriptionId || process.env.azureSubId || this.serverless.service.provider["subscriptionId"] || authResult.subscriptions[0].id;
3232
this.serverless.cli.log(`Using subscription ID: ${this.serverless.variables["subscriptionId"]}`);
3333
}
3434
catch (e) {

0 commit comments

Comments
 (0)