From 24b22895c6ab06db4fc6bc23912f327134d80720 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Sat, 11 Nov 2023 17:08:08 -0800 Subject: [PATCH] Set location --- azurecontainerapps.ts | 10 ++++++++-- dist/index.js | 30 ++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/azurecontainerapps.ts b/azurecontainerapps.ts index 6e46f075..0ddcb273 100644 --- a/azurecontainerapps.ts +++ b/azurecontainerapps.ts @@ -233,17 +233,23 @@ export class azurecontainerapps { // Set deployment location, if provided let location: string = this.toolHelper.getInput('location', false); let resourceGroup: string = this.toolHelper.getInput('resourceGroup', false); + let containerAppEnvironment: string = this.toolHelper.getInput('containerAppEnvironment', false); - // If no location was provided, use the default location for the Container App service + // If no location was provided, attempt to discover the location of the existing Container App + // or Container App Environment in the resource group or use the default location. if (this.util.isNullOrEmpty(location)) { if (!this.util.isNullOrEmpty(resourceGroup)) { let doesContainerAppExist = await this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup); + let doesContainerAppEnvironmentExist = await this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup); if (doesContainerAppExist) { var environmentName = await this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup); location = await this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup); + } else if (doesContainerAppEnvironmentExist) { + location = await this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup); + } else { + location = await this.appHelper.getDefaultContainerAppLocation(); } } - // location = await this.appHelper.getDefaultContainerAppLocation(); } return location; diff --git a/dist/index.js b/dist/index.js index 347f4d06..8257895b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -256,26 +256,40 @@ var azurecontainerapps = /** @class */ (function () { */ azurecontainerapps.getLocation = function () { return __awaiter(this, void 0, void 0, function () { - var location, resourceGroup, doesContainerAppExist, environmentName; + var location, resourceGroup, containerAppEnvironment, doesContainerAppExist, doesContainerAppEnvironmentExist, environmentName; return __generator(this, function (_a) { switch (_a.label) { case 0: location = this.toolHelper.getInput('location', false); resourceGroup = this.toolHelper.getInput('resourceGroup', false); - if (!this.util.isNullOrEmpty(location)) return [3 /*break*/, 4]; - if (!!this.util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 4]; + containerAppEnvironment = this.toolHelper.getInput('containerAppEnvironment', false); + if (!this.util.isNullOrEmpty(location)) return [3 /*break*/, 9]; + if (!!this.util.isNullOrEmpty(resourceGroup)) return [3 /*break*/, 9]; return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, resourceGroup)]; case 1: doesContainerAppExist = _a.sent(); - if (!doesContainerAppExist) return [3 /*break*/, 4]; - return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; + return [4 /*yield*/, this.appHelper.doesContainerAppEnvironmentExist(containerAppEnvironment, resourceGroup)]; case 2: + doesContainerAppEnvironmentExist = _a.sent(); + if (!doesContainerAppExist) return [3 /*break*/, 5]; + return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentName(this.containerAppName, resourceGroup)]; + case 3: environmentName = _a.sent(); return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(environmentName, resourceGroup)]; - case 3: + case 4: location = _a.sent(); - _a.label = 4; - case 4: return [2 /*return*/, location]; + return [3 /*break*/, 9]; + case 5: + if (!doesContainerAppEnvironmentExist) return [3 /*break*/, 7]; + return [4 /*yield*/, this.appHelper.getExistingContainerAppEnvironmentLocation(containerAppEnvironment, resourceGroup)]; + case 6: + location = _a.sent(); + return [3 /*break*/, 9]; + case 7: return [4 /*yield*/, this.appHelper.getDefaultContainerAppLocation()]; + case 8: + location = _a.sent(); + _a.label = 9; + case 9: return [2 /*return*/, location]; } }); });