Skip to content

Commit

Permalink
Cherry picked additionalArgument from main
Browse files Browse the repository at this point in the history
  • Loading branch information
t-dedah committed Nov 24, 2021
1 parent fe4953c commit 841b125
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ A GitHub Action to deploy ARM templates. With this action you can automate your

This action can be used to deploy Azure Resource Manager templates at different [deployment scopes](https://docs.microsoft.com/bs-latn-ba/Azure/azure-resource-manager/resource-group-template-deploy-rest#deployment-scope) - resource group deployment scope, subscription deployment scope and management group deployment scopes.

By default, the action only parses the output and does not print them out. In order to get the values of ```outputs```use [this](https://github.com/Azure/arm-deploy#another-example-on-how-to-use-this-action-to-get-the-output-of-arm-template).

## Dependencies

* [Azure Login](https://github.com/Azure/login) Login with your Azure credentials
Expand All @@ -21,9 +23,10 @@ This action can be used to deploy Azure Resource Manager templates at different
* `deploymentMode`: `Incremental`(default) (only add resources to resource group) or `Complete` (remove extra resources from resource group) or `Validate` (only validates the template).
* `deploymentName`: Specifies the name of the resource group deployment to create.
* `failOnStdErr`: Specify whether to fail the action if some data is written to stderr stream of az cli. Valid values are: true, false. Default value set to true.
* `additionalArguments`: Specify any additional arguments for the deployment.

## Outputs
Every template output will be exported as output.
Every template output will either be exported as output if output is a json object else will be consoled out where output is not a json object.

## Usage

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ inputs:
description: "Specify whether to fail the action if some data is written to stderr stream of az cli. Valid values are: true, false"
required: false
default: true
additionalArguments:
description: "Specify any additional arguments for the deployment."
required: false
branding:
color: orange
icon: package
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/deploy/scope_managementgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecOptions } from '@actions/exec/lib/interfaces';
import { ParseOutputs, Outputs } from '../utils/utils';
import * as core from '@actions/core';

export async function DeployManagementGroupScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, managementGroupId: string, failOnStdErr: Boolean): Promise<Outputs> {
export async function DeployManagementGroupScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, managementGroupId: string, failOnStdErr: Boolean, additionalArguments: String): Promise<Outputs> {
// Check if region is set
if (!region) {
throw Error("Region must be set.")
Expand All @@ -21,7 +21,8 @@ export async function DeployManagementGroupScope(azPath: string, region: string,
: undefined,
managementGroupId ? `--management-group-id "${managementGroupId}"` : undefined,
deploymentName ? `--name "${deploymentName}"` : undefined,
parameters ? `--parameters ${parameters}` : undefined
parameters ? `--parameters ${parameters}` : undefined,
additionalArguments ? additionalArguments : undefined
].filter(Boolean).join(' ');

// configure exec to write the json output to a buffer
Expand Down
5 changes: 3 additions & 2 deletions src/deploy/scope_resourcegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exec } from '@actions/exec';
import { ExecOptions } from '@actions/exec/lib/interfaces';
import { ParseOutputs, Outputs } from '../utils/utils';

export async function DeployResourceGroupScope(azPath: string, resourceGroupName: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, failOnStdErr: Boolean): Promise<Outputs> {
export async function DeployResourceGroupScope(azPath: string, resourceGroupName: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, failOnStdErr: Boolean, additionalArguments: String): Promise<Outputs> {
// Check if resourceGroupName is set
if (!resourceGroupName) {
throw Error("ResourceGroup name must be set.")
Expand All @@ -23,7 +23,8 @@ export async function DeployResourceGroupScope(azPath: string, resourceGroupName
: undefined,
deploymentMode && deploymentMode != "validate" ? `--mode ${deploymentMode}` : "--mode Incremental",
deploymentName ? `--name "${deploymentName}"` : undefined,
parameters ? `--parameters ${parameters}` : undefined
parameters ? `--parameters ${parameters}` : undefined,
additionalArguments ? additionalArguments : undefined
].filter(Boolean).join(' ');

// configure exec to write the json output to a buffer
Expand Down
5 changes: 3 additions & 2 deletions src/deploy/scope_subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecOptions } from '@actions/exec/lib/interfaces';
import { ParseOutputs, Outputs } from '../utils/utils';
import * as core from '@actions/core';

export async function DeploySubscriptionScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, failOnStdErr: Boolean): Promise<Outputs> {
export async function DeploySubscriptionScope(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.")
Expand All @@ -21,7 +21,8 @@ export async function DeploySubscriptionScope(azPath: string, region: string, te
template.startsWith("http") ? `--template-uri ${template}` : `--template-file ${template}`
: undefined,
deploymentName ? `--name "${deploymentName}"` : undefined,
parameters ? `--parameters ${parameters}` : undefined
parameters ? `--parameters ${parameters}` : undefined,
additionalArguments ? additionalArguments : undefined
].filter(Boolean).join(' ');

// configure exec to write the json output to a buffer
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function main(): Promise<Outputs> {
const deploymentName = getInput('deploymentName')
const parameters = getInput('parameters')
const managementGroupId = getInput('managementGroupId')
const additionalArguments = getInput('additionalArguments')
let failOnStdErr
try {
failOnStdErr = getBooleanInput('failOnStdErr')
Expand All @@ -39,13 +40,13 @@ export async function main(): Promise<Outputs> {
let result: Outputs = {};
switch (scope) {
case "resourcegroup":
result = await DeployResourceGroupScope(azPath, resourceGroupName, template, deploymentMode, deploymentName, parameters, failOnStdErr)
result = await DeployResourceGroupScope(azPath, resourceGroupName, template, deploymentMode, deploymentName, parameters, failOnStdErr, additionalArguments)
break
case "managementgroup":
result = await DeployManagementGroupScope(azPath, region, template, deploymentMode, deploymentName, parameters, managementGroupId, failOnStdErr)
result = await DeployManagementGroupScope(azPath, region, template, deploymentMode, deploymentName, parameters, managementGroupId, failOnStdErr, additionalArguments)
break
case "subscription":
result = await DeploySubscriptionScope(azPath, region, template, deploymentMode, deploymentName, parameters, failOnStdErr)
result = await DeploySubscriptionScope(azPath, region, template, deploymentMode, deploymentName, parameters, failOnStdErr, additionalArguments)
break
default:
throw new Error("Invalid scope. Valid values are: 'resourcegroup', 'managementgroup', 'subscription'")
Expand Down
15 changes: 10 additions & 5 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import * as core from '@actions/core';
export type Outputs = { [index: string]: { value: string } }
export function ParseOutputs(commandOutput: string): Outputs {
// parse the result and save the outputs
var result = JSON.parse(commandOutput) as { properties: { outputs: Outputs } }
var object = result.properties.outputs
for (const key in object) {
if (object.hasOwnProperty(key)) {
core.setOutput(key, object[key].value)
var object: Outputs = {}
try {
var result = JSON.parse(commandOutput) as { properties: { outputs: Outputs } }
object = result.properties.outputs
for (const key in object) {
if (object.hasOwnProperty(key)) {
core.setOutput(key, object[key].value)
}
}
}catch(err){
console.log(commandOutput)
}

return object
Expand Down

0 comments on commit 841b125

Please sign in to comment.