From 209a8eddbda98df85638ffa59e71e163984407f7 Mon Sep 17 00:00:00 2001 From: Turgay Akbas Date: Fri, 7 Jun 2024 09:22:15 +0200 Subject: [PATCH] Setup Azure infrastructure with Bicep and GitHub Actions --- .github/workflows/deploy_infra.yml | 22 ++++++++++++++++++++++ infra/appservice.bicep | 21 +++++++++++++++++++++ infra/main.bicep | 21 +++++++++++++++++++++ infra/storageaccount.bicep | 14 ++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 .github/workflows/deploy_infra.yml create mode 100644 infra/appservice.bicep create mode 100644 infra/main.bicep create mode 100644 infra/storageaccount.bicep diff --git a/.github/workflows/deploy_infra.yml b/.github/workflows/deploy_infra.yml new file mode 100644 index 0000000..9279693 --- /dev/null +++ b/.github/workflows/deploy_infra.yml @@ -0,0 +1,22 @@ +name: Deploy Infrastructure + +on: + push: + branches: + - main + +jobs: + deploy_infra: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Deploy Bicep files + run: | + az deployment group create --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --template-file ./infra/main.bicep --parameters appServiceName=${{ secrets.APP_SERVICE_NAME }} storageAccountName=${{ secrets.STORAGE_ACCOUNT_NAME }} diff --git a/infra/appservice.bicep b/infra/appservice.bicep new file mode 100644 index 0000000..641d147 --- /dev/null +++ b/infra/appservice.bicep @@ -0,0 +1,21 @@ +param appServiceName string +param location string = 'eastus' +param appServicePlanId string + +resource appService 'Microsoft.Web/sites@2021-02-01' = { + name: appServiceName + location: location + kind: 'app' + properties: { + serverFarmId: appServicePlanId + httpsOnly: true + } + siteConfig: { + appSettings: [ + { + name: 'WEBSITE_NODE_DEFAULT_VERSION' + value: '10.14.1' + } + ] + } +} diff --git a/infra/main.bicep b/infra/main.bicep new file mode 100644 index 0000000..7410fb8 --- /dev/null +++ b/infra/main.bicep @@ -0,0 +1,21 @@ +targetScope = 'resourceGroup' + +resource appService 'Microsoft.Web/sites@2021-02-01' = { + name: 'appServiceName' + location: 'location' + properties: { + serverFarmId: 'appServicePlanId' + } +} + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = { + name: 'storageAccountName' + location: 'location' + kind: 'StorageV2' + sku: { + name: 'Standard_LRS' + } + properties: { + accessTier: 'Hot' + } +} diff --git a/infra/storageaccount.bicep b/infra/storageaccount.bicep new file mode 100644 index 0000000..e850b87 --- /dev/null +++ b/infra/storageaccount.bicep @@ -0,0 +1,14 @@ +param storageAccountName string +param location string = 'eastus' + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = { + name: storageAccountName + location: location + kind: 'StorageV2' + sku: { + name: 'Standard_LRS' + } + properties: { + accessTier: 'Hot' + } +}