Git Product home page Git Product logo

azure-bicep-examples's Introduction

azure-bicep-examples

Infrastructure as code using Azure Bicep and GitHub Actions

Introduction

This repository demonstrates how to write infrastructure-as-code using Bicep (a Domain Specific Language for deploying resources on Azure) and how to write CI/CD pipelines using GitHub Actions.

This repository contains end-to-end examples of Node & Laravel (PHP) apps deployed to App Service and Azure Container Apps. The examples deploy additional resources such as Container Registry, Service Bus, Postgres & Cosmos database, storage accounts, Key Vault and configure Front Door load balancer and Azure DNS.

Infrastructure has been laid out as tiers based on the foundation platform tier. The platform resources are likely to be organisation-wide shared resources and defined once. The domain tier builds on this and provides resources shared across applications in the same domain. Finally the application tiers defines app or service-specific resources.

Resource names have been defined in json files. You'll find these as *-infra.json files in the .bicep folder. Defining these one-time allows different modules and workflows to access these resources without duplicating resource names across the iac files. It also provides an easy way to manage and update resource names without hunting through the code.

Sample apps

App Stack Deployment Target
app1 NestJs (Node) Container Apps
app2 Laravel (PHP) Container Apps
app3 NestJs (Node) App Service
app4 Laravel (PHP) App Service

Running examples locally

Later in this guide you'll find a walkthrough how to run the scripts locally. Note: You'll probably need to change some of the resource names in infra json files and other settings to avoid naming conflicts due to some of the global Azure naming restrictions.

Running GitHub Actions pipelines

The examples come complete with GitHub Actions workflows. However these require some initial set-up of secrets such as Service Principal, credentials, Azure subscription details. The quick start guide details these settings.

Quick Start

You'll probably need to change the following:

  • domain name in *-infra.json files
  • Update your domain's nameserver records on completion of platform provisioning to point to Azure DNS

Local Testing

Login to Azure:

az login

List subscriptions:

az account list --output table

Select one of your listed subscriptions:

az account set --subscription <Subscription Id>

Create platform resources:

az group create --name rg-bicep-examples-plat --location australiaeast
az deployment group create --name dp-platform-infra-au --resource-group rg-bicep-examples-plat --template-file .bicep/platform-infra.bicep --parameters postgresPassword=<super secure password>

Create domain resources:

az group create --name rg-bicep-examples-dmn --location australiaeast
az deployment sub create --name dp-domain-infra-au --template-file .bicep/domain-infra.bicep --location australiaeast --parameters platformResourceGroup=rg-bicep-examples-plat domainResourceGroup=rg-bicep-examples-dmn

Create app resources:

az deployment sub create --name dp-app1-infra-au --template-file .bicep/app1-infra.bicep --location australiaeast --parameters platformResourceGroup=rg-bicep-examples-plat domainResourceGroup=rg-bicep-examples-dmn dockerImage=mcr.microsoft.com/azuredocs/containerapps-helloworld:latest
az deployment sub create --name dp-app2-infra-au --template-file .bicep/app2-infra.bicep --location australiaeast --parameters platformResourceGroup=rg-bicep-examples-plat domainResourceGroup=rg-bicep-examples-dmn dockerImage=mcr.microsoft.com/azuredocs/containerapps-helloworld:latest
az deployment sub create --name dp-app3-infra-au --template-file .bicep/app3-infra.bicep --location australiaeast --parameters platformResourceGroup=rg-bicep-examples-plat domainResourceGroup=rg-bicep-examples-dmn
az deployment sub create --name dp-app4-infra-au --template-file .bicep/app4-infra.bicep --location australiaeast --parameters platformResourceGroup=rg-bicep-examples-plat domainResourceGroup=rg-bicep-examples-dmn

Delete resources:

az group delete --name rg-bicep-examples-dmn
az group delete --name rg-bicep-examples-plat

Setting up GitHub pipelines

GitHub Actions Secrets

Create the following repository secrets:

Secret Description
AZ_CREDS Subscription-scoped Service Principal.
POSTGRES_PASSWORD Desired admin password. Should meet minimum password requirements
SP_NAME Name of the Subscription-scoped Service Principal
SUBSCRIPTION_ID Azure Subscription Id. Run az account list --output table

Pipelines

Run pipelines in order:

  1. Provision Platform resources with Bicep
  2. Provision Domain resources with Bicep
  3. Provision App3 resources with Bicep
  4. Provision App4 resources with Bicep
  5. Build App1 (Nest Container App)
  6. Build App2 (Laravel Container App)
  7. Build App3 (Nest App Service)
  8. Build App4 (Laravel App Service)

Bicep code

azure-bicep-examples's People

Contributors

nad-au avatar anikpat avatar

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.