Azure / arm-deploy

ARM action to deploy an Azure Resource Manager (ARM) template to all the deployment scopes
MIT License
83 stars 39 forks source link

Execute bicep file with subscription deployment mode #112

Closed leandromsft closed 1 year ago

leandromsft commented 2 years ago

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/arm-deploy@v1.0.8
        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

t-dedah commented 2 years ago

Hi @leandromsft the workflow file looks okay to me. Can you please confirm if the path /home/runner/work/dotnet-container-app/dotnet-container-app/src/aspnetcoreiac/main.bicep is correct ?

If yes, then can you also add few more commands like ls -a and pwd just to check if the file still exists in the directory?

- name: Script
  run : | 
    ls -a
    pwd
leandromsft commented 2 years ago

Hi @t-dedah

I ran the command ls-R and the main.bicep file is inside the folder as expected, bellow the results

./src/aspnetcoreiac:
ContainerRegistry.bicep
Kubernetes.bicep
SQLServer.bicep
main.bicep

As a workaround I am running bicep file using az cli command using the same path src/aspnetcoreiac/main.bicep and it is working fine

- name: Running bicep file
        run: |
          az deployment sub create --location ${{ env.AZ_RG_LOCATION }} --template-file src/aspnetcoreiac/main.bicep --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 }} sqlAdminLogin=${{ secrets.AZURE_SQL_USERNAME }} sqlAdminPassword=${{ secrets.AZURE_SQL_PASSWORD }}

You can see the workflow file and logs here aspnetcore-deployment.yml

Thank you for help

leandromsft commented 2 years ago

Hi @t-dedah any update about this case?

leandromsft commented 1 year ago

Hi @t-dedah / @bishal-pdMSFT Please, do you have any update about this case?

Thank you

t-dedah commented 1 year ago

Hi @leandromsft I tried to replicate the issue but my workflow is failing while running the deployment rather than early stages. Run

Should I do something extra to replicate the issue?

leandromsft commented 1 year ago

Hi @t-dedah I recreate my workflow, and now everthing works. Thank you for help!