DevOps help for Cloud Platform Engineers
  • Welcome!
  • Quick Start Guide
  • About Me
  • CV
  • 🧠DevOps & SRE Foundations
    • DevOps Overview
      • Engineering Fundamentals
      • Implementing DevOps Strategy
      • DevOps Readiness Assessment
      • Lifecycle Management
      • The 12 Factor App
      • Design for Self Healing
      • Incident Management Best Practices (2025)
    • SRE Fundamentals
      • Toil Reduction
      • System Simplicity
      • Real-world Scenarios
        • AWS VM Log Monitoring API
    • Agile Development
      • Team Agreements
        • Definition of Done
        • Definition of Ready
        • Team Manifesto
        • Working Agreement
    • Industry Scenarios
      • Finance and Banking
      • Public Sector (UK/EU)
      • Energy Sector Edge Computing
  • DevOps Practices
    • Platform Engineering
    • FinOps
    • Observability
      • Modern Practices
  • 🚀Modern DevOps Practices
    • Infrastructure Testing
    • Modern Development
    • Database DevOps
  • 🛠️Infrastructure as Code (IaC)
    • Terraform
      • Getting Started - Installation and initial setup [BEGINNER]
      • Cloud Integrations - Provider-specific implementations
        • Azure Scenarios
        • AWS Scenarios
        • GCP Scenarios
      • Testing and Validation - Ensuring infrastructure quality
        • Unit Testing
        • Integration Testing
        • End-to-End Testing
        • Terratest Guide
      • Best Practices - Production-ready implementation strategies
        • State Management
        • Security
        • Code Organization
        • Performance
      • Tools & Utilities - Enhancing the Terraform workflow
        • Terraform Docs
        • TFLint
        • Checkov
        • Terrascan
      • CI/CD Integration - Automating infrastructure deployment
        • GitHub Actions - GitHub-based automation workflows
        • Azure Pipelines - Azure DevOps integration
        • GitLab CI - GitLab-based deployment pipelines
    • Bicep
      • Getting Started - First steps with Bicep [BEGINNER]
      • Template Specs
      • Best Practices - Guidelines for effective Bicep implementations
      • Modules - Building reusable components [INTERMEDIATE]
      • Examples - Sample implementations for common scenarios
      • Advanced Features
      • CI/CD Integration - Automating Bicep deployments
        • GitHub Actions
        • Azure Pipelines
  • 💰Cost Management & FinOps
    • Cloud Cost Optimization
  • 🐳Containers & Orchestration
    • Containerization Overview
    • Docker
      • Dockerfile Best Practices
      • Docker Compose
    • Kubernetes
      • CLI Tools - Essential command-line utilities
        • Kubectl
        • Kubens
        • Kubectx
      • Core Concepts
      • Components
      • Best Practices
        • Pod Security
        • Security Monitoring
        • Resource Limits
      • Advanced Features - Beyond the basics [ADVANCED]
        • Service Mesh
        • Ingress Controllers
          • NGINX
          • Traefik
          • Kong
          • Gloo Edge
      • Troubleshooting - Diagnosing and resolving common issues
        • Pod Troubleshooting Commands
      • Enterprise Architecture
      • Health Management
      • Security & Compliance
      • Virtual Clusters
    • OpenShift
  • Service Mesh & Networking
    • Service Mesh Implementation
  • Architecture Patterns
    • Data Mesh
    • Multi-Cloud Networking
    • Disaster Recovery
    • Chaos Engineering
  • Edge Computing
    • Implementation Guide
    • Serverless Edge
    • IoT Edge Patterns
    • Real-Time Processing
    • Edge AI/ML
    • Security Hardening
    • Observability Patterns
    • Network Optimization
    • Storage Patterns
  • 🔄CI/CD & GitOps
    • CI/CD Overview
    • Continuous Integration
    • Continuous Delivery
      • Deployment Strategies
      • Secrets Management
      • Blue-Green Deployments
      • Deployment Metrics
      • Progressive Delivery
      • Release Management for DevOps/SRE (2025)
    • CI/CD Platforms - Tool selection and implementation
      • Azure DevOps
        • Pipelines
          • Stages
          • Jobs
          • Steps
          • Templates - Reusable pipeline components
          • Extends
          • Service Connections - External service authentication
          • Best Practices for 2025
          • Agents and Runners
          • Third-Party Integrations
          • Azure DevOps CLI
        • Boards & Work Items
      • GitHub Actions
      • GitLab
        • GitLab Runner
        • Real-life scenarios
        • Installation guides
        • Pros and Cons
        • Comparison with alternatives
    • GitOps
      • Modern GitOps Practices
      • GitOps Patterns for Multi-Cloud (2025)
      • Flux
        • Overview
        • Progressive Delivery
        • Use GitOps with Flux, GitHub and AKS
  • Source Control
    • Source Control Overview
    • Git Branching Strategies
    • Component Versioning
    • Kubernetes Manifest Versioning
    • GitLab
    • Creating a Fork
    • Naming Branches
    • Pull Requests
    • Integrating LLMs into Source Control Workflows
  • ☁️Cloud Platforms
    • Cloud Strategy
    • Azure
      • Best Practices
      • Landing Zones
      • Services
      • Monitoring
      • Administration Tools - Platform management interfaces
        • Azure PowerShell
        • Azure CLI
      • Tips & Tricks
    • AWS
      • Authentication
      • Best Practices
      • Tips & Tricks
    • Google Cloud
      • Services
    • Private Cloud
  • 🔐Security & Compliance
    • DevSecOps Overview
    • DevSecOps Pipeline Security
    • DevSecOps
      • Real-life Examples
      • Scanning & Protection - Automated security tooling
        • Dependency Scanning
        • Credential Scanning
        • Container Security Scanning
        • Static Code Analysis
          • Best Practices
          • Tool Integration Guide
          • Pipeline Configuration
      • CI/CD Security
      • Secrets Rotation
    • Supply Chain Security
      • SLSA Framework
      • Binary Authorization
      • Artifact Signing
    • Security Best Practices
      • Threat Modeling
      • Kubernetes Security
    • SecOps
    • Zero Trust Model
    • Cloud Compliance
      • ISO/IEC 27001:2022
      • ISO 22301:2019
      • PCI DSS
      • CSA STAR
    • Security Frameworks
    • SIEM and SOAR
  • Security Architecture
    • Zero Trust Implementation
      • Identity Management
      • Network Security
      • Access Control
  • 🔍Observability & Monitoring
    • Observability Fundamentals
    • Logging
    • Metrics
    • Tracing
    • Dashboards
    • SLOs and SLAs
    • Observability as Code
    • Pipeline Observability
  • 🧪Testing Strategies
    • Testing Overview
    • Modern Testing Approaches
    • End-to-End Testing
    • Unit Testing
    • Performance Testing
      • Load Testing
    • Fault Injection Testing
    • Integration Testing
    • Smoke Testing
  • 🤖AI Integration
    • AIops Overview
      • Workflow Automation
      • Predictive Analytics
      • Code Quality
  • 🧠AI & LLM Integration
    • Overview
    • Claude
      • Installation Guide
      • Project Guides
      • MCP Server Setup
      • LLM Comparison
    • Ollama
      • Installation Guide
      • Configuration
      • Models and Fine-tuning
      • DevOps Usage
      • Docker Setup
      • GPU Setup
      • Open WebUI
    • Copilot
      • Installation Guide
      • VS Code Integration
      • CLI Usage
    • Gemini
      • Installation Guides - Platform-specific setup
        • Linux Installation
        • WSL Installation
        • NixOS Installation
      • Gemini 2.5 Features
      • Roles and Agents
      • NotebookML Guide
      • Cloud Infrastructure Deployment
      • Summary
  • 💻Development Environment
    • Tools Overview
    • DevOps Tools
    • Operating Systems - Development platforms
      • NixOS
        • Installation
        • Nix Language Guide
        • DevEnv with Nix
        • Cloud Deployments
      • WSL2
        • Distributions
        • Terminal Setup
    • Editor Environments
    • CLI Tools
      • Azure CLI
      • PowerShell
      • Linux Commands
      • YAML Tools
  • 📚Programming Languages
    • Python
    • Go
    • JavaScript/TypeScript
    • Java
    • Rust
  • 📖Documentation Best Practices
    • Documentation Strategy
    • Project Documentation
    • Release Notes
    • Static Sites
    • Documentation Templates
    • Real-World Examples
  • 📋Reference Materials
    • Glossary
    • Tool Comparison
    • Recommended Reading
    • Troubleshooting Guide
  • Platform Engineering
    • Implementation Guide
  • FinOps
    • Implementation Guide
  • AIOps
    • LLMOps Guide
  • Development Setup
    • Development Setup
Powered by GitBook
On this page
  • Prerequisites
  • Initial Setup
  • Create a resource group
  • Create a service principal
  • Configure GitHub Secrets
  • Basic Workflow
  • Advanced Workflow Examples
  • Multiple Environment Deployment
  • Preview Changes with What-If
  • Security Best Practices
  • 1. Minimize Service Principal Permissions
  • 2. Use OpenID Connect (OIDC) Instead of Secrets
  • 3. Secure Parameters Handling
  • Monitoring and Troubleshooting
  • Add Deployment Status Comments to PRs
  • Track Deployment History
  • Example Repository Structure
  • Conclusion
Edit on GitHub
  1. Infrastructure as Code (IaC)
  2. Bicep
  3. CI/CD Integration - Automating Bicep deployments

GitHub Actions

In this quick start, you use the GitHub Actions for Azure Resource Manager deployment to automate deploying a Bicep file to Azure.

This guide explains how to set up GitHub Actions for automated deployment of Bicep templates to Azure, covering basic setup, advanced workflows, and security best practices.

Prerequisites

  • An Azure subscription

  • A GitHub repository

  • Basic knowledge of Bicep (Azure's Infrastructure as Code language)

  • Azure CLI installed (for initial setup)

Initial Setup

Create a resource group

First, create a resource group for your deployment:

az group create -n exampleRG -l westus

Create a service principal

Create a service principal with contributor access to your resource group:

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

This command outputs JSON credentials that look similar to:

{
  "clientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "subscriptionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
  "resourceManagerEndpointUrl": "https://management.azure.com/",
  "activeDirectoryGraphResourceId": "https://graph.windows.net/",
  "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
  "galleryEndpointUrl": "https://gallery.azure.com/",
  "managementEndpointUrl": "https://management.core.windows.net/"
}

Configure GitHub Secrets

Store your Azure credentials and configuration as GitHub secrets:

  1. In your GitHub repository, go to Settings > Secrets and variables > Actions > New repository secret

  2. Create the following secrets:

    • AZURE_CREDENTIALS: Paste the entire JSON output from the service principal creation

    • AZURE_RG: Your resource group name (e.g., exampleRG)

    • AZURE_SUBSCRIPTION: Your subscription ID

Basic Workflow

Create a GitHub Actions workflow file at .github/workflows/deploy-bicep.yml:

name: Deploy Bicep Template

on:
  push:
    branches: [ main ]
    paths:
      - 'bicep/**'
      - '.github/workflows/deploy-bicep.yml'
  workflow_dispatch: # Allows manual triggering

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      # Checkout code
      - uses: actions/checkout@v3

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

      # Deploy Bicep file
      - name: Deploy Bicep template
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.AZURE_RG }}
          template: ./bicep/main.bicep
          parameters: 'storagePrefix=mystore storageSKU=Standard_LRS'
          failOnStdErr: false

Advanced Workflow Examples

Multiple Environment Deployment

This example deploys to development and production environments based on branch:

name: Multi-Environment Bicep Deploy

on:
  push:
    branches: [ develop, main ]
  pull_request:
    branches: [ develop, main ]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Install Bicep CLI
        run: |
          curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
          chmod +x ./bicep
          sudo mv ./bicep /usr/local/bin/bicep
      
      - name: Validate Bicep files
        run: |
          bicep build ./bicep/main.bicep --stdout > /dev/null
  
  deploy-dev:
    needs: validate
    if: github.ref == 'refs/heads/develop' || github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    environment: development
    steps:
      - uses: actions/checkout@v3
      
      - uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      
      - name: Deploy to Development
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.DEV_RESOURCE_GROUP }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters/dev.parameters.json
          deploymentName: 'github-${{ github.run_number }}-dev'

  deploy-prod:
    needs: [validate, deploy-dev]
    if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    runs-on: ubuntu-latest
    environment: production # Requires approval in GitHub
    steps:
      - uses: actions/checkout@v3
      
      - uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      
      - name: Deploy to Production
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.PROD_RESOURCE_GROUP }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters/prod.parameters.json
          deploymentName: 'github-${{ github.run_number }}-prod'

Preview Changes with What-If

This workflow validates and previews changes before deployment:

name: Bicep Preview and Deploy

on:
  push:
    branches: [ main ]
    paths:
      - 'bicep/**'
  pull_request:
    branches: [ main ]
  workflow_dispatch:

jobs:
  preview:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      
      - name: Preview Changes (What-If)
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.AZURE_RG }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters.json
          deploymentMode: Validate
          additionalArguments: --what-if
      
      - name: Deploy Bicep (PR Comment)
        if: github.event_name == 'pull_request'
        uses: azure/arm-deploy@v1
        with:
          scope: resourcegroup
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.AZURE_RG }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters.json
          deploymentName: 'pr-${{ github.event.pull_request.number }}'
          additionalArguments: --what-if
  
  deploy:
    needs: preview
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      
      - name: Deploy Bicep
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.AZURE_RG }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters.json
          deploymentName: 'github-${{ github.run_number }}'

Security Best Practices

1. Minimize Service Principal Permissions

Instead of using the Contributor role at the resource group level, consider using custom roles with just the permissions needed:

# Create a custom role definition file (custom-role.json)
{
  "Name": "Bicep Deployer",
  "Description": "Can deploy resources from Bicep files",
  "Actions": [
    "Microsoft.Resources/deployments/*",
    "Microsoft.Resources/subscriptions/resourceGroups/read"
  ],
  "AssignableScopes": [
    "/subscriptions/{subscription-id}/resourceGroups/exampleRG"
  ]
}

# Create the custom role
az role definition create --role-definition custom-role.json

# Assign the custom role to your service principal
az role assignment create --assignee {service-principal-id} \
  --role "Bicep Deployer" \
  --scope "/subscriptions/{subscription-id}/resourceGroups/exampleRG"

2. Use OpenID Connect (OIDC) Instead of Secrets

OIDC provides a more secure way to authenticate GitHub Actions with Azure without storing long-lived credentials:

name: Secure Bicep Deployment with OIDC

on:
  push:
    branches: [ main ]

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Azure login with OIDC
        uses: azure/login@v1
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION }}
      
      - name: Deploy Bicep
        uses: azure/arm-deploy@v1
        with:
          subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
          resourceGroupName: ${{ secrets.AZURE_RG }}
          template: ./bicep/main.bicep
          parameters: ./bicep/parameters.json

To set up OIDC authentication:

  1. Create a federated credential in Azure AD:

# Create an app registration first
appId=$(az ad app create --display-name "GitHub-Actions-OIDC" --query appId -o tsv)
objectId=$(az ad app show --id $appId --query id -o tsv)

# Create a service principal
spId=$(az ad sp create --id $appId --query id -o tsv)

# Assign role
az role assignment create \
  --role Contributor \
  --assignee $spId \
  --scope "/subscriptions/{subscription-id}/resourceGroups/exampleRG"

# Create federated credential
az ad app federated-credential create \
  --id $objectId \
  --parameters "{\"name\":\"github-federated\",\"issuer\":\"https://token.actions.githubusercontent.com\",\"subject\":\"repo:your-org/your-repo:ref:refs/heads/main\",\"audiences\":[\"api://AzureADTokenExchange\"]}"

# Save these values as GitHub secrets
echo "AZURE_CLIENT_ID: $appId"
echo "AZURE_TENANT_ID: $(az account show --query tenantId -o tsv)"
echo "AZURE_SUBSCRIPTION: $(az account show --query id -o tsv)"

3. Secure Parameters Handling

Store sensitive parameters in GitHub secrets and pass them securely:

- name: Deploy with Secure Parameters
  uses: azure/arm-deploy@v1
  with:
    subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
    resourceGroupName: ${{ secrets.AZURE_RG }}
    template: ./bicep/main.bicep
    parameters: >
      storagePrefix=mystore 
      storageSKU=Standard_LRS 
      adminPassword=${{ secrets.ADMIN_PASSWORD }}

In your Bicep file, mark sensitive parameters accordingly:

@secure()
param adminPassword string

Monitoring and Troubleshooting

Add Deployment Status Comments to PRs

- name: Comment PR with Deployment Status
  if: github.event_name == 'pull_request'
  uses: actions/github-script@v6
  with:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    script: |
      const output = `#### Bicep Deployment Preview 🚀
      Validation: ✅ Passed
      
      <details><summary>Show What-If Results</summary>
      
      \`\`\`
      ${{ steps.whatif.outputs.stdout }}
      \`\`\`
      </details>`;
      
      github.rest.issues.createComment({
        issue_number: context.issue.number,
        owner: context.repo.owner,
        repo: context.repo.repo,
        body: output
      })

Track Deployment History

- name: Save Deployment History
  if: success()
  run: |
    echo "Deployment completed at $(date)" >> deployments.log
    echo "Run ID: ${{ github.run_id }}" >> deployments.log
    echo "Commit: ${{ github.sha }}" >> deployments.log
    echo "Template: ./bicep/main.bicep" >> deployments.log
    echo "-------------------------------------------" >> deployments.log
    
- name: Upload Deployment History
  if: always()
  uses: actions/upload-artifact@v3
  with:
    name: deployment-history
    path: deployments.log

Example Repository Structure

├── .github/
│   └── workflows/
│       └── deploy-bicep.yml
├── bicep/
│   ├── main.bicep
│   ├── modules/
│   │   ├── storage.bicep
│   │   └── networking.bicep
│   └── parameters/
│       ├── dev.parameters.json
│       └── prod.parameters.json
└── README.md

Conclusion

Using GitHub Actions with Bicep provides a powerful way to automate your infrastructure deployment to Azure. By implementing proper security practices and leveraging advanced workflow configurations, you can create reliable, secure CI/CD pipelines for your infrastructure code.

For more information, refer to the official documentation:

PreviousCI/CD Integration - Automating Bicep deploymentsNextAzure Pipelines

Last updated 1 day ago

🛠️
Azure Bicep documentation
GitHub Actions for Azure
Azure ARM Deploy Action