Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added tenant scope deployments for the ARM Deploy action (#125)
* Basic tenant scope logic added. * Added positive and negative test cases. * Added tenant scope to descriptions.
- Loading branch information
Showing
10 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { exec } from '@actions/exec'; | ||
| import { ExecOptions } from '@actions/exec/lib/interfaces'; | ||
| import { ParseOutputs, Outputs } from '../utils/utils'; | ||
| import * as core from '@actions/core'; | ||
|
|
||
| export async function DeployTenantScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, failOnStdErr: Boolean, additionalArguments: String): Promise<Outputs> { | ||
| // Check if region is set | ||
| if (!region) { | ||
| throw Error("Region must be set.") | ||
| } | ||
|
|
||
| // check if mode is set as this will be ignored | ||
| if (deploymentMode && deploymentMode != "validate") { | ||
| core.warning("This deployment mode is not supported for tenant scoped deployments, this parameter will be ignored!") | ||
| } | ||
| // create the parameter list | ||
| const validateParameters = [ | ||
| region ? `--location "${region}"` : undefined, | ||
| template ? | ||
| template.startsWith("http") ? `--template-uri ${template}` : `--template-file ${template}` | ||
| : undefined, | ||
| deploymentName ? `--name "${deploymentName}"` : undefined, | ||
| parameters ? `--parameters ${parameters}` : undefined | ||
| ].filter(Boolean).join(' '); | ||
|
|
||
| let azDeployParameters = validateParameters; | ||
| if(additionalArguments){ | ||
| azDeployParameters += ` ${additionalArguments}`; | ||
| } | ||
|
|
||
| // configure exec to write the json output to a buffer | ||
| let commandOutput = ''; | ||
| let commandStdErr = false; | ||
| const deployOptions: ExecOptions = { | ||
| silent: true, | ||
| ignoreReturnCode: true, | ||
| failOnStdErr: false, | ||
| listeners: { | ||
| stderr: (data: BufferSource) => { | ||
| let error = data.toString(); | ||
| if(error && error.trim().length !== 0) | ||
| { | ||
| commandStdErr = true; | ||
| core.error(error); | ||
| } | ||
| }, | ||
| stdout: (data: BufferSource) => { | ||
| commandOutput += data.toString(); | ||
| }, | ||
| debug: (data: string) => { | ||
| core.debug(data); | ||
| } | ||
| } | ||
| } | ||
| const validateOptions: ExecOptions = { | ||
| silent: true, | ||
| ignoreReturnCode: true, | ||
| listeners: { | ||
| stderr: (data: BufferSource) => { | ||
| core.warning(data.toString()); | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // validate the deployment | ||
| core.info("Validating template...") | ||
| var code = await exec(`"${azPath}" deployment tenant validate ${validateParameters} -o json`, [], validateOptions); | ||
| if (deploymentMode === "validate" && code != 0) { | ||
| throw new Error("Template validation failed.") | ||
| } else if (code != 0) { | ||
| core.warning("Template validation failed.") | ||
| } | ||
|
|
||
| if (deploymentMode != "validate") { | ||
| // execute the deployment | ||
| core.info("Creating deployment...") | ||
| var deploymentCode = await exec(`"${azPath}" deployment tenant create ${azDeployParameters} -o json`, [], deployOptions); | ||
|
|
||
| if (deploymentCode != 0) { | ||
| throw new Error("Deployment failed.") | ||
| } | ||
| if(commandStdErr && failOnStdErr) { | ||
| throw new Error("Deployment process failed as some lines were written to stderr"); | ||
| } | ||
|
|
||
| core.debug(commandOutput); | ||
| core.info("Parsing outputs...") | ||
| return ParseOutputs(commandOutput) | ||
| } | ||
| return {} | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "mgName": { | ||
| "value": "mg-test01" | ||
| }, | ||
| "mgDisplayName": { | ||
| "value": "Test Management Group" | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "$schema": "https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "mgName": { | ||
| "type": "int", | ||
| "defaultValue": "[concat('mg-', uniqueString(newGuid()))]" | ||
| }, | ||
| "mgDisplayName": { | ||
| "type": "int" | ||
| } | ||
| }, | ||
| "resources": [ | ||
| { | ||
| "type": "Microsoft.Management/managementGroups", | ||
| "apiVersion": "2021-04-01", | ||
| "name": "[parameters('mgName')]", | ||
| "properties": { | ||
| "displayName": "[parameters('mgDisplayName')]" | ||
| } | ||
| } | ||
| ], | ||
| "outputs": {} | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "mgName": { | ||
| "value": "mg-test01" | ||
| }, | ||
| "mgDisplayName": { | ||
| "value": "Test Management Group" | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "$schema": "https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#", | ||
| "contentVersion": "1.0.0.0", | ||
| "parameters": { | ||
| "mgName": { | ||
| "type": "string", | ||
| "defaultValue": "[concat('mg-', uniqueString(newGuid()))]" | ||
| }, | ||
| "mgDisplayName": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "resources": [ | ||
| { | ||
| "type": "Microsoft.Management/managementGroups", | ||
| "apiVersion": "2021-04-01", | ||
| "name": "[parameters('mgName')]", | ||
| "properties": { | ||
| "displayName": "[parameters('mgDisplayName')]" | ||
| } | ||
| } | ||
| ], | ||
| "outputs": {} | ||
| } |