Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding bicep script to deploy azure function Dapr extension samples in ACA #150

Merged
merged 10 commits into from
Sep 20, 2023
21 changes: 0 additions & 21 deletions samples/dotnet-azurefunction/Startup.cs

This file was deleted.

6 changes: 1 addition & 5 deletions samples/dotnet-azurefunction/dotnet-azurefunction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
<RootNamespace>dotnet_azurefunction</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
</ItemGroup>
<ItemGroup>
<!-- Switch to Nuget Reference by uncommenting following line and removing the Project Reference -->
Expand Down
29 changes: 29 additions & 0 deletions samples/sample-infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# azure-functions-dapr-aca-deployment
Steps to deploy the Azure Function with Dapr extension in ACA.

ASHIQUEMD marked this conversation as resolved.
Show resolved Hide resolved
## Create resource group
```
az group create --name {resourceGroupName} --location eastasia
```

## Deploy azure function samples with Dapr extension in ACA
```
az deployment group create --resource-group {resourceGroupName} --template-file deploy-samples.bicep
```

## List of resources bicep will create

1. Azure Storage Account
2. Blob Service
3. Blob Container
4. Log Analytics Workspace
5. Application Insights
6. Managed Environment
7. Redis Cache
8. Event Hub Namespace
9. Event Hub Authorization Rule
10. Event Hub
11. Dapr Component for State Management
12. Dapr Component for Message Bus
13. Dapr Component for Event Hub
14. Azure Function App
59 changes: 59 additions & 0 deletions samples/sample-infra/azure-function.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
param envResourceNamePrefix string
param azStorageConnectionString string
param appInsightsConnectionString string
param environmentId string
param stateStoreName string

resource daprComponentStateManagement 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' existing = {
name: stateStoreName
}

/* ###################################################################### */
// Create Azure Function
/* ###################################################################### */
resource azfunctionapp 'Microsoft.Web/sites@2022-09-01' = {
name: '${envResourceNamePrefix}-funcapp'
location: 'East Asia (Stage)'
kind: 'functionapp,linux,container,azurecontainerapps'
properties: {
name: '${envResourceNamePrefix}-funcapp'
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage'
value: azStorageConnectionString
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: appInsightsConnectionString
}
{
name: 'PubSubName'
value: 'messagebus'
}
{
name: 'StateStoreName'
value: 'statestore'
}
{
name: 'KafkaBindingName'
value: 'sample-topic'
}
]
linuxFxVersion: 'Docker|mcr.microsoft.com/daprio/samples/dotnet-azurefunction:edge'
}
DaprConfig: {
enabled: true
appId: '${envResourceNamePrefix}-funcapp'
appPort: 3001
httpReadBufferSize: ''
httpMaxRequestSize: ''
logLevel: ''
enableApiLogging: true
}
managedEnvironmentId: environmentId
}
dependsOn: [
daprComponentStateManagement
]
}
141 changes: 141 additions & 0 deletions samples/sample-infra/azure-services.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
param location string
param redisCacheName string
param eventHubNamespace string
param eventHubName string
param eventHubSku string
param containerName string
param envResourceNamePrefix string

/* ###################################################################### */
// Create storage account for function app prereq
/* ###################################################################### */
resource azStorageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
ASHIQUEMD marked this conversation as resolved.
Show resolved Hide resolved
name: '${envResourceNamePrefix}storage'
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}

var azStorageConnectionString = 'DefaultEndpointsProtocol=https;AccountName=${azStorageAccount.name};EndpointSuffix=${az.environment().suffixes.storage};AccountKey=${azStorageAccount.listKeys().keys[0].value}'

// Create blob service
resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2019-06-01' = {
name: 'default'
parent: azStorageAccount
}

// Create container
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: containerName
parent: blobService
properties: {
publicAccess: 'None'
metadata: {}
}
}

resource logAnalyticsWorkspace'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: '${envResourceNamePrefix}-la'
location: location
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: '${envResourceNamePrefix}-ai'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}

/* ###################################################################### */
// Create managed ACA environment
/* ###################################################################### */
resource environment 'Microsoft.App/managedEnvironments@2022-10-01' = {
name: '${envResourceNamePrefix}-env'
location: location
properties: {
daprAIInstrumentationKey: appInsights.properties.InstrumentationKey
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
}
}

/* ###################################################################### */
// Create Redis Cache
/* ###################################################################### */
resource redisCache 'Microsoft.Cache/Redis@2020-06-01' = {
name: redisCacheName
location: location
properties: {
enableNonSslPort: true
minimumTlsVersion: '1.2'
sku: {
capacity: 1
family: 'C'
name: 'Standard'
}
}
}

resource eventHubNamespaceResource 'Microsoft.EventHub/namespaces@2021-11-01' = {
name: eventHubNamespace
location: location
sku: {
name: eventHubSku
tier: eventHubSku
capacity: 1
}
properties: {
isAutoInflateEnabled: false
maximumThroughputUnits: 0
kafkaEnabled: true
}
}

resource eventHubAuth 'Microsoft.EventHub/namespaces/authorizationRules@2022-10-01-preview' = {
name: '${envResourceNamePrefix}-eventHubAuth'
parent: eventHubNamespaceResource
properties: {
rights: [
'Listen'
'Manage'
'Send'
]
}
}

/* ###################################################################### */
// Create Azure EventHub
/* ###################################################################### */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move other eventHub resources like namespace and auth below this comment block? Same for other services too.

resource eventHub 'Microsoft.EventHub/namespaces/eventhubs@2021-11-01' = {
parent: eventHubNamespaceResource
name: eventHubName
properties: {
messageRetentionInDays: 7
partitionCount: 1
}
}

output azStorageConnectionString string = azStorageConnectionString
output appInsightsConnectionString string = appInsights.properties.ConnectionString
output environmentId string = environment.id
output eventHubName string = eventHubName
output azStorageAccountName string = azStorageAccount.name
106 changes: 106 additions & 0 deletions samples/sample-infra/dapr-components.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
param azStorageConnectionString string
param envResourceNamePrefix string
param redisCacheName string
param eventHubName string
param azStorageAccountName string
param containerName string
param eventHubNamespace string

resource environment 'Microsoft.App/managedEnvironments@2022-10-01' existing = {
name: '${envResourceNamePrefix}-env'
}

resource redisCache 'Microsoft.Cache/Redis@2020-06-01' existing = {
name: redisCacheName
}

resource eventHubAuth 'Microsoft.EventHub/namespaces/authorizationRules@2022-10-01-preview' existing = {
name: '${eventHubNamespace}/${envResourceNamePrefix}-eventHubAuth'
}

/* ###################################################################### */
// Setup Dapr componet Redis state store in ACA
/* ###################################################################### */
resource daprComponentStateManagement 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' = {
parent: environment
name: 'statestore'
properties: {
componentType: 'state.redis'
version: 'v1'
metadata: [
{
name: 'redisHost'
value: '${redisCacheName}.redis.cache.windows.net:6379'
}
{
name: 'redisPassword'
value: redisCache.listKeys().primaryKey
}
]
scopes: []
}
}

/* ###################################################################### */
// Setup Dapr componet Redis message bus in ACA
/* ###################################################################### */
resource daprComponentMessagebus 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' = {
parent: environment
name: 'messagebus'
properties: {
componentType: 'pubsub.redis'
version: 'v1'
metadata: [
{
name: 'redisHost'
value: '${redisCacheName}.redis.cache.windows.net:6379'
}
{
name: 'redisPassword'
value: redisCache.listKeys().primaryKey
}
]
scopes: []
}
}

/* ###################################################################### */
// Setup Dapr componet Eventhub in ACA
ASHIQUEMD marked this conversation as resolved.
Show resolved Hide resolved
/* ###################################################################### */
resource daprComponentEventHub 'Microsoft.App/managedEnvironments/daprComponents@2023-05-01' = {
parent: environment
name: 'sample-topic'
properties: {
componentType: 'bindings.azure.eventhubs'
version: 'v1'
metadata: [
{
name: 'connectionString'
value: '${eventHubAuth.listKeys().primaryConnectionString};EntityPath=${eventHubName}'
}
{
name: 'storageConnectionString'
value: azStorageConnectionString
}
{
name: 'eventHub'
value: eventHubName
}
{
name: 'consumerGroup'
value: '$Default'
}
{
name: 'storageAccountName'
value: azStorageAccountName
}
{
name: 'storageContainerName'
value: containerName
}
]
scopes: []
}
}

output stateStoreName string = 'statestore'
Loading
Loading