Giter VIP home page Giter VIP logo

arm-deploy's Introduction

GitHub Action for Azure Resource Manager (ARM) deployment

A GitHub Action to deploy ARM templates. With this action you can automate your workflow to deploy ARM templates and manage Azure resources.

This action can be used to deploy Azure Resource Manager templates at different deployment scopes - 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 outputsuse this.

Dependencies

  • Azure Login Login with your Azure credentials
  • Checkout To checks-out your repository so the workflow can access any specified ARM template.

Inputs

  • scope: Provide the scope of the deployment. Valid values are: resourcegroup(default) , tenant, subscription, managementgroup.

  • resourceGroupName: Conditional Provide the name of a resource group. Only required for Resource Group Scope

  • subscriptionId: Conditional Provide a value to override the subscription ID set by Azure Login.

  • managementGroupId: Conditional Specify the Management Group ID, only required for Management Group Deployments.

  • region: Conditional Provide the target region, only required for Tenant, Management Group or Subscription deployments.

  • template: Required Specify the path or URL to the Azure Resource Manager template.

  • parameters: Specify the path or URL to the Azure Resource Manager deployment parameter values file (local / remote) and/or specify local overrides.

  • 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. These arguments will be ignored while validating the template.

    A good way to use additionalArguments would be to send optional parameters like --what-if or --what-if-exclude-change-types. Read more about this here

Outputs

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

- uses: azure/arm-deploy@v1
  with:
    subscriptionId: <YourSubscriptionId>
    resourceGroupName: <YourResourceGroup>
    template: <path/to/azuredeploy.json>

Example

on: [push]
name: AzureARMSample

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    - uses: azure/arm-deploy@v1
      with:
        resourceGroupName: github-action-arm-rg
        template: ./azuredeploy.json
        parameters: examples/template/parameters.json storageAccountType=Standard_LRS sqlServerPassword=${{ secrets.SQL_SERVER }}
        additionalArguments: "--what-if --rollback-on-error --what-if-exclude-change-types Create Ignore"

Another example which ensures the Azure Resource Group exists before ARM deployment

In the preceeding example there is a pre-requisite that an existing Azure Resource Group named github-action-arm-rg must already exist.

The below example makes use of the Azure CLI Action to ensure the resource group is created before doing an ARM deployment. Note that the command az group create is idempotent, so it will run sucessfully even if the group already exists.

Steps

When generating your credentials (in this example we store in a secret named AZURE_CREDENTIALS) you will need to specify a scope at the subscription level.

az ad sp create-for-rbac --name "{sp-name}" --sdk-auth --role contributor --scopes /subscriptions/{subscription-id}

See Configure deployment credentials.

Example

on: [push]
name: AzureARMSample

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    env:
      ResourceGroupName: github-action-arm-rg
      ResourceGroupLocation: "australiaeast"
    steps:
    - uses: actions/checkout@master
    - uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    - uses: Azure/CLI@v1
      with:
        inlineScript: |
          #!/bin/bash
          az group create --name ${{ env.ResourceGroupName }} --location ${{ env.ResourceGroupLocation }}
          echo "Azure resource group created"
    - uses: azure/arm-deploy@v1
      with:
        resourceGroupName: ${{ env.ResourceGroupName }}
        template: ./azuredeploy.json
        parameters: storageAccountType=Standard_LRS

Another example on how to use this Action to get the output of ARM template

In this example, our template outputs containerName.

Steps

- uses: azure/arm-deploy@v1
  id: deploy
  with:
    resourceGroupName: azurearmaction
    template: examples/template/template.json
    parameters: examples/template/parameters.json
    deploymentName: github-advanced-test

Here we see a normal use of the Action, we pass the template as json file as well as the parameters. If we look into the template.json File we can see at the very bottom the defined outputs:

{
  ...
  "outputs": {
    ...
    "containerName": {
      "type": "string",
      "value": "[parameters('containerName')]"
    }
  }
}

And we know our Action writes this output(s) to an action output variable with the same name, we can access it using ${{ steps.deploy.outputs.containerName }} (Note: deploy comes from the id field from above.)

If we now add a Shell script with a simple echo from that value, we can see that on the console the containername to be printed.

- run: echo ${{ steps.deploy.outputs.containerName }}

ARM Deploy Actions is supported for the Azure public cloud as well as Azure government clouds ('AzureUSGovernment' or 'AzureChinaCloud') and Azure Stack ('AzureStack') Hub. Before running this action, login to the respective Azure Cloud using Azure Login by setting appropriate value for the environment parameter.

Example on how to use failOnStdErr

In this example, we are setting failOnStdErr to false.

- uses: azure/arm-deploy@v1
  id: deploy
  with:
    resourceGroupName: azurearmaction
    template: examples/template/template.json
    parameters: examples/template/parameters.json
    deploymentName: github-advanced-test
    failOnStdErr: false

failOnStdErr equals true implied that if some data is written to stdErr and exit code from az-cli is 0, then action execution will fail.

failOnStdErr equals false implies that if some data is written to stdErr and return code from az-cli is 0, then action will continue execution. This input is added to support cases where stdErr is being used to stream warning or progress info.

Non zero Exit code will always lead to failure of action irrespective the value of failOnStdErr.

For more examples, refer : Example Guide

Az CLI dependency

Internally in this action, we use azure CLI and execute az login with the credentials provided through secrets. In order to validate the new az CLI releases for this action, canary test workflow is written which will execute the action on az CLI's edge build which will fail incase of any breaking change is being introduced in the new upcoming release. The test results can be posted on a slack or teams channel using the corresponding integrations. Incase of a failure, the concern will be raised to azure-cli for taking a necessary action and also the latest CLI installation will be postponed in Runner VMs as well for hosted runner to prevent the workflows failing due to the new CLI changes.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

arm-deploy's People

Contributors

actions-user avatar anthony-c-martin avatar bearmannl avatar bishal-pdmsft avatar dependabot[bot] avatar fvilches17 avatar harvey-k avatar kanika1894 avatar larryclaman avatar majastrz avatar microsoft-github-operations[bot] avatar microsoftopensource avatar pankajgovindrao avatar picccard avatar pulkitaggarwl avatar t-dedah avatar tejasd1990 avatar tomkerkhove avatar zainuvk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arm-deploy's Issues

ERROR: 'str' object has no attribute 'get'

Hi Team,

Looks like a code issue to me. I get the following error when trying to deploy my DataFactory ARM Template.

Validating template...
Warning: ERROR: 'str' object has no attribute 'get'

Warning: Template validation failed.
Creating deployment...
Error: ERROR: 'str' object has no attribute 'get'

Error: Deployment failed.

I validated the ARMTemplate also, just to check, But all seems to be good.

Im using the azure-data-factory-utilities npm package method to create the ARMTemplate

Self-Hosted Gitrub Runner in Azure using Managed Identities to deploy

Thank you for creating this action!

Is it possible to allow for Managed Identities executing within a Virtual Machine using a Self-Hosted run to deploy ARM Templates rather than specifying credentials in Github? From what I can see of the code the Credentials must be provided, however, we'd like to avoid that and have the permissions evaluated in Azure directly.

Cheers,
JD

Error: The process '/usr/bin/az' failed with exit code 2

The deployment using Az CLI works but fails when using the action. Maybe it's obvious but I don't see what I'm doing wrong...

So in my GitHub Action this will works perfectly

   - uses: azure/login@v1
      with:
        creds: ${{ secrets.GR_azUrlGitHubDev_CREDENTIALS }}

    - run: |
        az group deployment create -n github-dev -g UrlShortnerDEV --template-file deployment/azureDeploy.json --parameters "deployment/azureDeploy.params.dev.json"

but this fails (I'm using the same everything, paths, names, creds)

    - uses: azure/arm-deploy@v1
      with:
        resourceGroupName: UrlShortnerDEV
        deploymentName: github-dev
        template: deployment/azureDeploy.json
        parameters: deployment/azureDeploy.params.dev.json

Here the error message:

Run azure/arm-deploy@v1
  with:
    deploymentMode: Validate
    resourceGroupName: UrlShortnerDEV
    deploymentName: github-dev
    template: ./deployment/azureDeploy.json
    parameters: ./deployment/azureDeploy.params.dev.json
  env:
    AZURE_HTTP_USER_AGENT: 
    AZUREPS_HOST_ENVIRONMENT: 
Changing subscription context...
Error: The process '/usr/bin/az' failed with exit code 2

Any Idea?

ERROR: InvalidTemplate - Deployment template validation failed: 'The template resource '_artifactsLocation'

Hello,

Below is my github actions deployment, but still getting an error. Anybody can help me? Thank you!

deploy:
  name: Deploy
  runs-on: ubuntu-latest
  steps:
    - name: Checkout
      uses: actions/checkout@v3

    - name: Login to Azure Cloud
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: Run ARM deploy
      uses: azure/arm-deploy@v1
      with:
        resourceGroupName: group1
        template: azure/templates/armdeploy.json
        parameters: azure/templates/armdeploy.parameters.json 
        additionalArguments: "--what-if --rollback-on-error --what-if-exclude-change-types Create Ignore"

armdeploy.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "_artifactsLocation": {
          "type": "string",
          "defaultValue": "[deployment().properties.templateLink.uri]",
          "metadata": {
              "description": "The base URI where artifacts required by this template are located, including a trailing '/'"
          }
      },
      "_artifactsLocationSasToken": {
          "type": "securestring",
          "defaultValue": "",
          "metadata": {
              "description": "The sasToken required to access _artifactsLocation. When the template is deployed using the accompanying scripts, a sasToken will be automatically generated. Use the defaultValue if the staging location is not secured."
          }
      },

error

ERROR: InvalidTemplate - Deployment template validation failed: 'The template resource '_artifactsLocation' at line '1' and column '182' is not valid: The language expression property 'templateLink' doesn't exist, available properties are 'template, templateHash, parameters, mode, provisioningState'.. Please see https://aka.ms/arm-template-expressions for usage details.'.

Allow to create resource group

This action seems to only work if the resource group has been created previously.

As a workaround one has to either go to the azure portal and manually create the resource group or add a previous workflow step to automate the creation of the resource group (e.g. using azure cli to create the rg).

It would be nice to be able to create (assuming it's the first run) the resource group or update the resource group.

Example: See the Azure DevOps equivalent. See option 'Create or Update Resource Group'

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#yaml-snippet

Task fails for bicep template deploy

Using arm-deploy@v1 to deploy a bicep ARM template:

on: [push]
name: AzureBicepSample

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    - uses: azure/arm-deploy@v1
      with:
        resourceGroupName: github-action-arm-rg
        template: ./main.bicep
        parameters: environmentType=Test

Task fails with following output:

Run azure/arm-deploy@v1
with:
resourceGroupName: github-action-arm-rg
template: ./main.bicep
parameters: environmentType=Test
failOnStdErr: true
env:
AZURE_HTTP_USER_AGENT:
AZUREPS_HOST_ENVIRONMENT:
Validating template...
Warning: WARNING: Build succeeded: 0 Warning(s), 0 Error(s)

Creating deployment...
Error: WARNING: Build succeeded: 0 Warning(s), 0 Error(s)

Error: Deployment process failed as some lines were written to stderr


This error seems to be similar to #48

Azure Deployment history is not kept

When looking at deployments completed with this action in Azure portal, you only see the newest deployment. It seems that the deployment is overwritten each time with the latest, and the history is not kept.

I have done numerous deployments using this action to the resource group below, but the deployments panel only show the latest.

image

please add the ability for resource groups to be created

Please allow the workflow to create resource groups, if it doesn't exist.

Looking to migrate from Azure DevOps to GitHub Actions and it appears that when running the workflow the resource group doesn't get created and end up having to create it manually.

here is the option that I use on DevOps:
image

aliasPrimaryConnectionString doesn't exist anymore

We have some ARM templates that try to get the aliasPrimaryConnectionString key from an EventHub that have DR enabled. The templates have been working fine for the past few months but around yesterday they all stopped working with the following error msg:

##[error]InvalidTemplate: Unable to process template language expressions for resource '/subscriptions/[SubscriptionId]/resourceGroups/[RG Name]/providers/Microsoft.Resources/deployments/[DeploymentName]' at line '1' and column '11619'. 'The language expression property 'aliasPrimaryConnectionString' doesn't exist, available properties are 'primaryConnectionString, secondaryConnectionString, primaryKey, secondaryKey, keyName'.'

Here's the problematic line:

"EventHubServiceSettings:EventHubConnectionString": {
    "value": "[listKeys(resourceId(parameters('eventHubResourceGroupName'),'Microsoft.EventHub/namespaces/eventhubs/authorizationRules', parameters('eventHubNamespace'), parameters('eventHubName'),  variables('eventHubAccessPolicies')),'2017-04-01').aliasPrimaryConnectionString]"
},

Anything have changed recently?

Deployment fails if output section is defined in ARM template

Issue

We have an ARM template where we are creating App insight and cosmos db resource, once resources are created, in output section we are trying to fetch the connection strings for the cosmos db as well as app insights key but this results in failure of deployment.
Deployment fails when output section is defined in the ARM template file. Please find the sample repo where it is happening. It specifically fails on parsing output with below error.

Error: (e || "").replace is not a function

Please checkout this action for more detailed error message

  • ARM template is validated on portal and it is getting deployed successfully.

Unknown error with parameter allowedValues refering to other parameter

Hi!

I have unknown error when trying to do "allowedValues": "[parameters('locationsAllowed')]". It works with "allowedValues": [ "southcentralus", ...] . So I wonder if this operation is even supported?

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "locationsAllowed": {
      "type": "array",
      "defaultValue": [
        "southcentralus",
        "westcentralus"
      ]
    },
    "location": {
      "type": "string",
      "metadata": {
        "description": "Specify a location for the resources."
      },
      "defaultValue": "southcentralus",
      "allowedValues": "[parameters('locationsAllowed')]"
      // NOR
      // "allowedValues": "[array(parameters('locationsAllowed'))]"
    },

Please note that this case works

    "location": {
      "type": "string",
      "metadata": {
        "description": "Specify a location for the resources."
      },
      "defaultValue": "eastus",
      "allowedValues": [
        "southcentralus",
        "westus",
        "centralus",
        "eastus",
        "northcentralus",
        "westcentralus"
      ]
    },

deploying fileService fails with HTTP 400 after a fileservice has been created with "XML specified is not syntactically valid" during the EndRequest event

Hi,

The deployment seems to create all the resources, but still fails for the EndRequest when a filService is being created.

I am using a self-hosted github action runner with an official ubuntu focal image.

The template was generated by the azure portal. I just removed some of the circular dependencies to get it working.

Could this issue be due to incompatible Azure cli version?

arm-deploy: v1
Azure cli: (2.0.x) https://packages.ubuntu.com/source/focal/azure-cli

Azure cli Message:

ERROR: {"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"InvalidXmlDocument\",\r\n \"message\": \"XML specified is not syntactically valid.\\nRequestId:159c9e46-901a-0021-729b-1b5b5f000000\\nTime:2022-12-29T15:39:40.9681373Z\"\r\n }\r\n}"}]}}

Azure activity logs:

https://gist.github.com/sydseter/3e6b28becdec123bfd80cb956dd9c7d3

Github action workflow yml:

https://gist.github.com/sydseter/6ffc4f027852ca9e7fe32add6cf37de4

arm template.json:

https://gist.github.com/sydseter/3f27eb01f0cc6bd7287073f9a299912c

arm parameters.json:

https://gist.github.com/sydseter/b87f0d1135af5e21f9557737680b1988

Validate Fails

When only validating templates I get the following error:

Validating template...
Warning: InvalidArgumentValueError: az deployment group validate: 'validate' is not a valid value for '--mode'.
Still stuck? Run 'az deployment group validate --help' to view all commands or go to 'https://docs.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest' to learn more

Warning: Template validation failed.
Creating deployment...
Warning: InvalidArgumentValueError: az deployment group create: 'validate' is not a valid value for '--mode'.
Try this: 'az deployment group create --resource-group testrg --name rollout01 --template-file azuredeploy.json --parameters '*** \"policyName\": *** \"value\": \"policy2\" *** ***''
Still stuck? Run 'az deployment group create --help' to view all commands or go to 'https://docs.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest' to learn more

Error: The process '/usr/bin/az' failed with exit code 2

False Alert on GitHub workflow.

I'm using this step like this:

      - name: Analyze Bicep Template
        id: main-deploy-check

        uses: Azure/arm-deploy@v1
        with:
          resourceGroupName: ${{ env.AZURE_RESOURCE_GROUP_DEV }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters.dev.json
          deploymentMode: Validate

and I get this error in the pipeline

C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" account set --subscription 70b77cc4-67c1-4e40-bd7b-b4853065111a"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\azureclitaskscript1628109034773.ps1'"
**ERROR: 'NoEffect'**
##[error]Script failed with exit code: 1
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" account clear"

So, does this action support Bicep files with deploymentMode of Validate?

Because running this in incremental mode works simply fine.

Allow JSON input as parameter

Hello there,
I am trying to use your module to deploy an Azure Red Hat OpenShift. To deploy a cluster correctly the deployment requires the use of a pull secret from Red Hat which is in json format (structure below). Unforuntately I cannot seem to get the bicep module finish using github actions unless I hard code the pull secret in the bicep file itself. This is obviously not ideal. I have tried using github envs and github secrets but they result in the bicep file failing due to "an invalid secret", through troubleshooting this is because github actions places *** throughout the json.

pullSecret.json

{
  "auths": {
     "cloud.openshift.com" : {
         "auth": "XXXXXXX",
         "email": "[email protected]"
     },
     "quay.io" : {
         "auth": "XXXXXXX",
         "email": "[email protected]"
     },
     "registry.connect.redhat.com" : {
         "auth": "XXXXXXX",
         "email": "[email protected]"
     },
     "registry.redhat.com" : {
         "auth": "XXXXXXX",
         "email": "[email protected]"
     }
  }
}

The job from the github action workflow;

jobs:
   deploy_aro:
   runs_on: ubuntu-latest
   steps:
    - name: checkout code
      uses: actions/checkout@main

    - name: azure login
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: aro_cluster
      uses: azure/arm-deploy@v1
      with:
        scope: resourcegroup
        subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
        resourceGroupName: ${{ secrets.RG_NAME }}
        template: aro.bicep
        parameters: parameters.json pullSecret="${{ secrets.PULL_SECRET }}" location="${{ env.LOCATION }}" 

I have experimented writing the secret to a json file on the runner and then trying extract the contents to a parameter, but again no success. In the OpenShift documentation the pullsecret file is referenced using the "@" symbol[1], or as a parameter override with the pull secret contents in an environment file[2].

  1. Using the @ symbol to reference the file
az aro create \
  --resource-group $RESOURCEGROUP \
  --name $CLUSTER \
  --vnet aro-vnet \
  --master-subnet master-subnet \
  --worker-subnet worker-subnet --pull-secret @pullSecret.json
  1. Using the contents of the pullsecret as an override when deploying a bicep module.
az deployment group create \
    --name aroDeployment \
    --resource-group $RESOURCEGROUP \
    --template-file azuredeploy.json \
    --parameters location=$LOCATION \
    --parameters domain=$DOMAIN \
    --parameters pullSecret=$PULL_SECRET \
    --parameters clusterName=$ARO_CLUSTER_NAME \
    --parameters aadClientId=$SP_CLIENT_ID \
    --parameters aadObjectId=$SP_OBJECT_ID \
    --parameters aadClientSecret=$SP_CLIENT_SECRET \
    --parameters rpObjectId=$ARO_RP_SP_OBJECT_ID

Is there a way to use the contents of a json file as a parameter in this module?
Perhaps if this cannot be done then you could advise on another appropriate way using this module?

Reference links;
[1] https://docs.microsoft.com/en-au/azure/openshift/tutorial-create-cluster#get-a-red-hat-pull-secret-optional
[2] https://docs.microsoft.com/en-au/azure/openshift/quickstart-openshift-arm-bicep-template?pivots=aro-bicep#deploy-the-cluster---azure-cli

Is there any way to mark outputs of the template as secrets?

Looking at the code (https://github.com/Azure/arm-deploy/blob/main/src/utils/utils.ts), it seems that template outputs are always set using setOutput. However that means that all outputs are potentially visible in logs when used later.

For some more sensitive values (e.g. even AppInsights Instrumentation Key), it would be good to mask them in the logs.
This can be achieved by calling core.setSecret before core.setOutput.

This cannot be done after arm-deploy (see actions/runner#475), so it would be good if arm-deploy step could be configured to mark some outputs as secrets.

Warning from Bicep results in failed action

When setting bicepconfig.json to the following

{
  "experimentalFeaturesEnabled": {
    "userDefinedTypes": true
  }
}

Bicep will warn about using an experimental feature. However, the azure/arm-deploy action interprets this warning as an error and fails the whole run, even though the actual deployment went well:

Run azure/arm-deploy@v1
Changing subscription context...
Validating template...
Warning: WARNING: WARNING: Symbolic name support in ARM is experimental, and should be enabled for testing purposes only. Do not enable this setting for any production usage, or you may be unexpectedly broken at any time!


Creating deployment...
Error: WARNING: WARNING: Symbolic name support in ARM is experimental, and should be enabled for testing purposes only. Do not enable this setting for any production usage, or you may be unexpectedly broken at any time!


Error: Deployment process failed as some lines were written to stderr

Using failOnStdErr: false feels like a too harsh workaround because then there is no possibility anymore to distinguish between a warning and a real error.

Support for User Managed Identity

In order to prevent the possible exposure of credentials in the Cloud, we need to use a User Managed Identity to run this action from a self-hosted agent deployed in Azure.
Is there a plan to implement that?

Using folder path for multiple ARM templates

Is it possible to provide only folder path containing multiple files instead of specific JSON path to deploy?
For example:
template: ./templates/*/*.json
or:
template: templates

azure/arm-deploy@v1 fails after new release of Azure CLI Version 2.24.1

Hello ๐Ÿ™‚ Since the new release (1. June 2021) of Azure CLI Version 2.24.1, our github actions deployment to azure fails on azure/arm-deploy@v1 with following error:

The process 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd' failed because one or more lines were written to the STDERR stream

Have you experienced similar problem or this is not related in your opinion?

Thanks

Deploying bicep files with warnings fails the deployment

Using the task with a bicep file as the template parameter when bicep has warning outputs results in the message:

Deployment process failed as some lines were written to stderr

This is correct, bicep is writing lines to stderr, but they are warnings only, not errors.

The result is that the bicep deploy doesn't occur. If I use az deployment sub create locally, the bicep deployment completes successfully.

Is there a way to continue deployment even though these warnings are written to stderr?

I've tried setting continue-on-error: true but it seems the error occurs after bicep to arm compilation and before the arm deployment so the result of this setting doesn't effect the ARM stage of the deployment

I've opened an issue at Azure/bicep#2905 for the underlying issue as the warnings are incorrect compared to the ARM spec.

Azure Bicep Outputs Are Not Parsed

When using GitHub Actions to deploy infrastructure in Azure, specifically via Azure Bicep templates, even though the template may have outputs defined, this is not parsed correctly and therefore no information is returned to the console.

AzureBicep-GHAction-Output

Sample Bicep Code

param accountPrefix string = 'test'
param location string = 'eastus'
param utc string = utcNow()

var storageAccountName_var = '${replace(replace(replace(accountPrefix, '.', ''), '_', ''), '-', '')}ghedata${utc}'
var storageAccountType = 'Premium_LRS'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-01-01' = {
  name: toLower(take(storageAccountName_var, 24))
  location: location
  sku: {
    name: storageAccountType
  }
  kind: 'StorageV2'
}

output storageAccount_Name string = storageAccount.name
output storageAccount_Location string = storageAccount.location
output storageAccount_SKUName string = storageAccount.sku.name
output storageAccount_Kind string = storageAccount.kind

Sample GitHub Actions Workflow

name: Deploy GHES using Azure Bicep

on:
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
    inputs:
      gh_handle:
        description: 'What is your GitHub handle?'
        required: true
      accountPrefix:
        description: 'Unique prefix for your Storage Account and VM name. Must be all lower case letters or numbers. No spaces or special characters.'
        required: true
      location:
        description: "What Azure region to deploy to (ie. 'eastus', 'canadacentral')"
        default: 'eastus'
        required: true
      ghes_version:
        description: "What version of GHES do you need (ie. 2.22.19, 3.0.13, 3.1.5)?"
        default: 'latest'
        required: true

jobs:
  create_resource_group:
    name: Create Resource Group
    runs-on: ubuntu-latest
    steps:
      # Log into Azure
      - name: Log into Azure
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      - name: Create Resource Group
        run:
          az group create --name 'GHES-${{ github.event.inputs.gh_handle }}' --location ${{ github.event.inputs.location }} --tags [Owner[= ${{ github.event.inputs.gh_handle }} ]]

  deploy_ghes:
    name: Deploy GHES
    runs-on: ubuntu-latest
    needs: [create_resource_group]
    steps:
      # Checkout code
      - name: Checkout code
        uses: actions/checkout@main

      # Log into Azure
      - name: Log into Azure
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      # Deploy Bicep file
      - name: Deploy GHES
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: GHES-${{ github.event.inputs.gh_handle }}
          template: ./Bicep/main.bicep
          parameters: ./Bicep/bicep.parameters.json accountPrefix=${{ github.event.inputs.accountPrefix }} ghesversion=${{ github.event.inputs.ghes_version }}
          failOnStdErr: false

ARM template outputs containing resource ids sanitized

When using the Azure Login GitHub action with the creds parameter:

    - name: Login via Az module
      uses: azure/login@v1
      with:
        creds: ${{secrets.AZURE_CREDENTIALS}}

secrets.AZURE_CREDENTIALS:

{
    "clientId": "<GUID>",
    "clientSecret": "<GUID>",
    "subscriptionId": "<GUID>",
    "tenantId": "<GUID>",
    (...)
  }

and then deploying an ARM template with the arm-deploy action that returns a resourceId as a template output, GitHub sanitizes the step output due to the subscriptionId within the resourceId being present within the AZURE_CREDENTIALS secret.

Allow for parameter override

When creating an ARM deployment, I would like to provide both a parameter file and override certain parameters through the arm-deploy action. This is handy when overall parameters exist in the parameter file, but you would like to override certain values during deploy in your pipeline.

One example is where I want to use this action twice, once for creating a resource group, where I determine the resourcegroup name in the workflow and then reuse that value for deploying the resources.

  # Deployment of resource group template    
  - name: Deploy ARM Template resourcegroup
    uses: azure/arm-deploy@v1
    with:
      # You can change these environment variables for your configuration:   AZURE_SUBSCRIPTION_ID
      scope: subscription
      subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
      region: centralus # Set this to your target region
      template: repo/ARM/azuredeploy.resourcegroup.json  # Set this to the location of your template file
      parameters: repo/ARM/azuredeploy.resourcegroup.parameters.json # Set this to the location of your parameters file
      parameters: rgName=${{env.RESOURCEGROUP_NAME}} #override rgName in parameters file

  # Deployment of template    
  - name: Deploy ARM Template resources
    uses: azure/arm-deploy@v1
    with:
      # You can change these environment variables for your configuration:   AZURE_SUBSCRIPTION_ID
      scope: resourcegroup
      subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
      resourcegroup: ${{env.RESOURCEGROUP_NAME}} # reuse resourcegroup name
      region: centralus # Set this to your target region
      template: repo/ARM/azuredeploy.json  # Set this to the location of your template file
      parameters: repo/ARM/azuredeploy.parameters.json # Set this to the location of your parameters file

README.md overly complex

While reviewing the README file, the example for "Another example which ensures the Azure Resource Group exists before ARM deployment" seems overly complex. Currently the code example shows:

        inlineScript: |
          #!/bin/bash
          if $(az group exists --name ${{ env.ResourceGroupName }}) ; then
            echo "Azure resource group already exists, skipping creation..."
          else
            az group create --name ${{ env.ResourceGroupName }} --location ${{ env.ResourceGroupLocation }}
            echo "Azure resource group created"
          fi

az group create is an idempotent command (it returns success even if the group already exists), so I don't think the conditional code is necessary at all. I believe you could simply run:

          #!/bin/bash
            az group create --name ${{ env.ResourceGroupName }} --location ${{ env.ResourceGroupLocation }}
            echo "Azure resource group created"

I realize this is a nitpick but simplicity should always be valued :)

Support `--rollback-on-error` option

The Az CLI (and Az Powershell module) have a method of specifying the behavior of the deployment should an error happen during the run. In this case, we can either specify a deployment name to rollback to or simply use it as a flag to rollback to the latest successful deployment if there's an error. It'd be great if this parameter was exposed to the GH Action.

Ability to see logging output

We use

      - name: Run ARM deploy
        uses: azure/arm-deploy@65ae74fb7aec7c680c88ef456811f353adae4d06
        with:
          resourceGroupName: ${{ secrets.PREVIEW_ENV_RESOURCE_GROUP }}
          subscriptionId: ${{ secrets.NONPROD_SUBSCRIPTION_ID }}
          template: ./azure-preview-env-template.json
          deploymentName: ${{ env.DEPLOYMENT_NAME }}
          parameters: appName="${{ env.APP_NAME }}"
            containerImage="${{ env.DOCKER_IMAGE }}"
            dockerRegistryUrl="${{ secrets.NONPROD_REGISTRY_SERVER }}"
            dockerRegistryUsername="${{ env.NONPROD_REGISTRY_USERNAME }}"
            dockerRegistryPassword="${{ secrets.NONPROD_REGISTRY_PASSWORD }}"

It's working great. We're starting up Azure Container Instances nicely based on our Docker registry.
But a couple of times, the web servers inside the Docker file has failed to start (and bind to a port).
If you were to run it locally with, like, docker run -t -i --rm -p 4000:4000 my-tag you'd see on your terminal the error message which most likely is a traceback/stacktrace from the application pointing out something obvious like an undefined environment variable or something like that.

What would be great is if we could have output from the azure/arm-deploy command somehow. Then we could print it as part of our GitHub Action workflow. I'm guessing, by default, underlying'ly it starts the container in some sort of background process.
But similar to the docker CLI you can do docker logs my-container (without the --follow) to get a glimpse of anything from stdout or stderr.

Mistake in readme

I noticed that you removed the Required tag from the scope parameter. Tho according to your action.yml this is a required parameter and there is no default to it.

Is it possible to refer to a template file via pattern referring or similar?

I am currently developing functionality for deploying a bicep file to Azure. Since I am downloading the file from an artifact, I would like to know is it possible to indirectly refer to this file (as it is the only file in the working directory).

image

Is something like "*.bicep" or "." possible or considered for future versions?

Thank you in advance!

Execute bicep file with subscription deployment mode

Hello,

I create a bicep file to create a resource group and other resources within this resource group
This bicep file works fine when I execute using az deployment sub create command

So, I create GitHub workflow to automate my bice file execution, as fallow:

     # Checkout code
      - name: Checkout aspnetcoreiac
        uses: actions/checkout@v3
        with:
          path: src/aspnetcoreiac
      
      # Log into Azure
      - name: Login
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      # Deploy Bicep file
      - name: Deploy Template
        uses: Azure/[email protected]
        with:
          scope: subscription
          region: ${{ env.AZ_RG_LOCATION }}
          template: src/aspnetcoreiac/main.bicep
          deploymentMode: Incremental
          deploymentName: 'gh-actions'
          parameters: rgName=${{ env.AZ_RG_NAME }} rgLocation=${{ env.AZ_RG_LOCATION }} acrName=${{ env.AZ_ACR_NAME }} clusterName=${{ env.AZ_AKS_NAME }} sqlserverName=${{ env.AZ_SQLSERVER_NAME }}
          failOnStdErr: false

But when the workflow run, result this warning:

Warning: This deployment mode is not supported for subscription scoped deployments, this parameter will be ignored!
Validating template...
Warning: ERROR: An error occurred reading file. Could not find file '/home/runner/work/dotnet-container-app/dotnet-container-app/src/aspnetcoreiac/main.bicep'.

So, my questions is: How I can automatically run my bicep files in the subscription scope?

Thank you

Default deploymentName

The default deploymentName seems to be the base name of the template file. Could it be set to the repository name with a timestamp?

In Azure DevOps, date and random chars are added so that two deployments in the same resource group don't collide.
Here's an example where the last deployment was done using github:
image

Warning should be removed

This warning here should be removed from my point of view:

// check if mode is set as this will be ignored
if (deploymentMode && deploymentMode != "validate") {
core.warning("This deployment mode is not supported for subscription scoped deployments, this parameter will be ignored!")
}

The warning does not even mention what parameter is affected and lastly this warning is not true. It very much is relevant whether you set the mode to validate or something else. Not sure why this warning is even presented to the user.

You should rather just add a warning that mentions that the mode "Complete" is not supported and therefore it will switch to "Incremental". However, this warning message does not make a whole lot of sense to me.

Connection string parameter from repo secret error

Hi there,

I try to deploy azure datafctory with multiple parameters including connection string of sql server.
I have this following issue when trying tu set connection string (store in a GitHub secret) to a parameter:
image
I think it's because the connection string contains white space ("[...]intial catalog=[...]")

With quotes(simple and double) i have this error :
image
In the ARM template the parameter is a "SecureString"

JSON array as parameter input

Hello.

Is it possible to use a JSON array as a parameter value in the parameters input?
For example
parameters: param1=

Thank you.

ERROR: Error while attempting to retrieve the latest Bicep version: 403 Client Error: rate limit exceeded for url: https://api.github.com/repos/Azure/bicep/releases/latest.

I'm really surprised no-one has logged this yet.

It's been mentioned over in AZURE/bicep Azure/bicep#3689

with:
    subscriptionId: ***
    resourceGroupName: shp-DataGateway-rg
    template: Deployments/Main.bicep
    scope: resourcegroup
    parameters: Deployments/prd.Main.parameters.json
    failOnStdErr: false
    deploymentName: shp-DataGateway-func-Deployment
  env:
    AZURE_FUNCTIONAPP_PACKAGE_PATH: .
    DOTNET_VERSION: 6.0.x
    AZURE_HTTP_USER_AGENT: 
    AZUREPS_HOST_ENVIRONMENT: 
Changing subscription context...
Validating template...
Warning: ERROR: Error while attempting to retrieve the latest Bicep version: [4](https://github.com/StottHoare/DataGateway-func/actions/runs/3763393948/jobs/6396885352#step:4:4)03 Client Error: rate limit exceeded for url: https://api.github.com/repos/Azure/bicep/releases/latest.

Warning: Template validation failed.
Creating deployment...
Error: ERROR: Error while attempting to retrieve the latest Bicep version: 403 Client Error: rate limit exceeded for url: https://api.github.com/repos/Azure/bicep/releases/latest.

Error: Deployment failed.

I'm running about 1-3 actions per day.

The issue linked above should indicate the fix or workaround that needs to be applied here.

`set-output` deprecation warning from GitHub actions

Similar to #114 GitHub is also warning about deprecating the use of the set-output command.

The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Their solution for action authors is to bump @actions/core to v1.10.0 or greater.

I note there is a PR from dependabot #111 to bump to 1.91, but that will not fix this issue.

Arm deployment for Azure Data Factory failed without error message

We try to implement CI/CD for Azure Data Factory (https://docs.microsoft.com/en-us/azure/data-factory/continuous-integration-deployment) using Github Action. In Actions, we use azure/arm-deploy@v1 for ARM deployment.
It was working fine last month, and then a few weeks ago, it started to failed without error message.

Screenshot 2021-02-09 at 16 26 23

According to Microsoft Support, there is nothing wrong with the ARM template itself and they asked us to open an issue here.

stdout should be provided on deployment and validation

When using arm-deploy @v1, there is no output of the validate or deployment steps - only these messages.

image

To validate the deployment or validation steps, it would be nice to know the general deployment output by just writing the output from the -o json to standard output.

This will also help with history keeping when looking back at the logs.

Redeploying Bastion via template fails (Subnet AzureBastionSubnet is in use)

I'm not sure if this belongs here, but I'll give it a try.

I've created a bicep template to deploy a vnet resource with a Bastion resource. The first time deploying this template works as expected and all resources are created.

But when redeploying the template, I get the error "Subnet AzureBastionSubnet is in use by /subscriptions/..../resourceGroups/rg-test/providers/Microsoft.Network/bastionHosts/avd-vnet-bastion/bastionHostIp
Configurations/IpConf and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet."

What I'm expecting is that when redeploying the template, it would detected that the resources exist and no changes are made to the resources. This is how other templates work when deploying other resources. I don't understand why it's trying to delete the AzureBastionSubnet.

See attached file that is the bicep template.
bastion.txt

Warning in workflow about nodejs version

It seems that GitHub is deprecating nodejs12 which gives warnings when using this action in a workflow:
image

Warning in text:

Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: azure/arm-deploy, azure/functions-action

Skipping `Parsing Ouputs...` during arm-deploy step

The arm-deploy action skips Parsing Ouputs.. during the step execution. The outputs are populated in the Azure deployments. When we enabled logs to the runner, we could see the output object is pointing to a null value.

Note: The arm-deploy step is part of a reusable workflow and the same workflow works for other bicep deployments

MicrosoftTeams-image (1)
MicrosoftTeams-image (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.