diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..32f986b --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,25 @@ +name: learn-github-actions + +on: + push: + branches: + - main + +env: + AZURE_RESOURCEGROUP_NAME: ToyWebsiteTest + ENVIRONMENT_TYPE: Test + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + - uses: azure/arm-deploy@v1 + with: + deploymentName: ${{ github.run_number }} + resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }} + template: ./deploy/main.bicep + parameters: environmentType=${{ env.ENVIRONMENT_TYPE }} diff --git a/deploy/main.bicep b/deploy/main.bicep new file mode 100644 index 0000000..aa4364c --- /dev/null +++ b/deploy/main.bicep @@ -0,0 +1,88 @@ +@description('The location into which your Azure resources should be deployed.') +param location string = resourceGroup().location + +@description('Select the type of environment you want to provision. Allowed values are Production and Test.') +@allowed([ + 'Production' + 'Test' +]) +param environmentType string + +@description('A unique suffix to add to resource names that need to be globally unique.') +@maxLength(13) +param resourceNameSuffix string = uniqueString(resourceGroup().id) + +param storageAccountNameParam string = uniqueString(resourceGroup().id) + +// Define the names for resources. +var appServiceAppName = 'toy-website-${resourceNameSuffix}' +var appServicePlanName = 'toy-website' +var applicationInsightsName = 'toywebsite' +var storageAccountName = 'mystorageresourceNameSuffix' + +// Define the SKUs for each component based on the environment type. +var environmentConfigurationMap = { + Production: { + appServicePlan: { + sku: { + name: 'S1' + capacity: 1 + } + } + } + Test: { + appServicePlan: { + sku: { + name: 'F1' + } + } + } +} + +resource appServicePlan 'Microsoft.Web/serverfarms@2021-01-15' = { + name: appServicePlanName + location: location + sku: environmentConfigurationMap[environmentType].appServicePlan.sku +} + +resource appServiceApp 'Microsoft.Web/sites@2021-01-15' = { + name: appServiceAppName + location: location + properties: { + serverFarmId: appServicePlan.id + siteConfig: { + appSettings: [ + { + name: 'APPINSIGHTS_INSTRUMENTATIONKEY' + value: applicationInsights.properties.InstrumentationKey + } + { + name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' + value: applicationInsights.properties.ConnectionString + } + ] + } + } +} + +resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = { + name: applicationInsightsName + location: location + kind: 'web' + properties: { + Application_Type: 'web' + Request_Source: 'rest' + Flow_Type: 'Bluefield' + } +} + +resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = { + name: storageAccountName + location: location + kind: 'StorageV2' + sku: { + name: 'Standard_LRS' + } +} + +output appServiceAppHostName string = appServiceApp.properties.defaultHostName