Skip to content

Commit 70c4f5c

Browse files
damienaichehDamien AichehJustrebl
authored
feat: Add TF IaC + rephrase lab doc
- IaC extracted from https://github.com/damienaicheh/azure-workshop-setup - Rephrased a few steps in the lab doc - Extended the devcontainer for Terraform and C# Devkit --------- Co-authored-by: Damien Aicheh <[email protected]> Co-authored-by: Julien S <[email protected]>
1 parent fb80378 commit 70c4f5c

28 files changed

+886
-24
lines changed

.devcontainer/devcontainer.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"azurite.azurite",
4444
// Language related extensions
4545
"ms-dotnettools.csharp",
46+
"ms-dotnettools.csdevkit",
4647
"ms-python.python",
4748
// Mardown helpers :
4849
"davidanson.vscode-markdownlint",

.github/workflows/packages.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v3
16+
17+
- name: Terraform
18+
run: cd terraform && zip -r ../terraform.zip .
1619

1720
- name: .NET zip solutions
1821
run: cd src/solutions/dotnet && zip -r ../../../dotnet-solution.zip .

.gitignore

+44
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,47 @@ __blobstorage__*
55
__queuestorage__*
66
__azurite_*
77
*.bkp
8+
9+
# Local Dotnet Dev Tools
10+
*.sln
11+
12+
### Terraform ###
13+
# Local .terraform directories
14+
**/.terraform/*
15+
16+
# .tfstate files
17+
*.tfstate
18+
*.tfstate.*
19+
20+
# dev tf files
21+
tf
22+
plan.out
23+
24+
# Crash log files
25+
crash.log
26+
crash.*.log
27+
28+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
29+
# password, private keys, and other secrets. These should not be part of version
30+
# control as they are data points which are potentially sensitive and subject
31+
# to change depending on the environment.
32+
*.tfvars
33+
*.tfvars.json
34+
35+
# Ignore override files as they are usually used to override resources locally and so
36+
# are not checked in
37+
override.tf
38+
override.tf.json
39+
*_override.tf
40+
*_override.tf.json
41+
42+
# Include override files you do wish to add to version control using negated pattern
43+
# !example_override.tf
44+
45+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
46+
# example: *tfplan*
47+
48+
# Ignore CLI configuration files
49+
.terraformrc
50+
terraform.rc
51+
.terraform.lock.hcl

docs/assets/serverless.drawio

+345-10
Large diffs are not rendered by default.

docs/workshop.md

+51-12
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The **FastTrack** required steps will be prefixed with a `🚀` label : These ar
5353
5454
</div>
5555

56-
## 🚀 Prerequisites
56+
## 🚀 Dev Environment Setup
5757

5858
Before starting this lab, be sure to set your Azure environment :
5959

@@ -132,7 +132,9 @@ The following tools and access will be necessary to run the lab in good conditio
132132

133133
Once you have set up your local environment, you can clone the Hands-on-lab-serverless repo you just forked on your machine, and open the local folder in Visual Studio Code and head to the next step.
134134

135-
### 👉 All : Load the Workspace
135+
## 🚀 Visual Studio Code Setup
136+
137+
### 👉 Load the Workspace
136138

137139
Once your environment is ready, you will have to enter the Visual Studio Workspace to get all the tools ready.
138140
To do so, click the **burger menu** in the top left corner (visible only with codespace), **File** and then **Open Workspace from File...**
@@ -149,7 +151,7 @@ To do so, click the **burger menu** in the top left corner (visible only with co
149151

150152
Let's begin!
151153

152-
### 🔑 All : Sign in to Azure
154+
### 🔑 Sign in to Azure
153155

154156
<div class="task" data-title="Task">
155157

@@ -197,6 +199,44 @@ az provider register --namespace 'Microsoft.Web'
197199

198200
</details>
199201

202+
### Deploy the infrastructure
203+
204+
If you choose to do the FastTrack version, you must deploy the infrastructure before starting the lab.
205+
206+
First, you need to initialize the terraform infrastructure by running the following command:
207+
208+
```bash
209+
cd terraform && terraform init
210+
```
211+
212+
Then run the following command to deploy the infrastructure:
213+
214+
```bash
215+
# Apply the deployment directly
216+
terraform apply -auto-approve
217+
```
218+
219+
Now you can deploy the web app code into the Static Web App:
220+
221+
```bash
222+
# Restore packages
223+
cd ../src/webapp && npm install
224+
225+
# Build the Web App
226+
npm run swa:build
227+
228+
# Deploy the web app code into the Static Web App
229+
RESOURCE_GROUP_NAME="$(terraform output -raw resource_group_name)"
230+
STATIC_WEB_APP="$(terraform output -raw static_web_app_name)"
231+
232+
npm run swa:deploy -- \
233+
--resource-group $RESOURCE_GROUP_NAME \
234+
--app-name $STATIC_WEB_APP \
235+
--no-use-keychain
236+
```
237+
238+
The deployment should take around 5 minutes to complete.
239+
200240
## Scenario
201241

202242
The goal of the full lab is to upload an audio file to Azure and retrieve the transcripts back using a Web Application.
@@ -369,7 +409,7 @@ This command will create the Static Web App in Azure and will then prompt you fo
369409

370410
You can also opt for building and deploying the web app from your machine without having to fork the project and give permissions to [AzureAppServiceCLI][app-service-cli] to access the code.
371411

372-
First let's [download][webapp-zip] or clone the [project][github-hol] locally and go inside the `src/webapp` folder.
412+
First let's go inside the `src/webapp` folder.
373413

374414
Now, you can follow these steps to create the static web app:
375415

@@ -1391,7 +1431,7 @@ It's now time to connect the Azure Function App which stand for a small API to u
13911431
<details>
13921432
<summary>📚 Toggle solution</summary>
13931433
1394-
First, go to the Azure Static Web App resource and inside `Configuration` in the `Application Settings` set the environment variable `FILE_UPLOADING_URL` to the same Azure Function `AudioUpload` endpoint you retrieved earlier in the lab above.
1434+
First, go to the Azure Static Web App resource and inside `Configuration` in the `Application Settings` set the environment variable `FILE_UPLOADING_URL` to the same Azure Function `AudioUpload` endpoint you retrieved earlier in the lab above like `https://<functionapp>.azurewebsites.net/api/audioupload?code=<...>`.
13951435

13961436
If your function expects a binary as an input then you will also need to set `FILE_UPLOADING_FORMAT` to `binary`
13971437

@@ -1744,15 +1784,15 @@ The next step is to use the newly created Web PubSub instance (`wps<environment>
17441784
17451785
Add a new Cosmos DB-triggered function `CosmosToWebPubSub` to your Function App and use the following settings:
17461786
1747-
| App setting | Description |
1748-
|-------------------------------------|-----------------------------------|
1749-
| WEB_PUBSUB_HUB_ID | Web PubSub hub name |
1750-
| WEB_PUBSUB_CONNECTION_STRING | Web PubSub hub connection string |
1787+
| App setting | Description |
1788+
|-------------------------------------|---------------------------------------|
1789+
| WEB_PUBSUB_HUB_ID | Web PubSub resource name |
1790+
| WEB_PUBSUB_CONNECTION_STRING | Web PubSub primary connection string |
17511791
17521792
You need to update the App settings of the Function App by adding the 2 new settings:
17531793
17541794
- Set `WEB_PUBSUB_HUB_ID` with the name of the Web PubSub resource
1755-
- Set `WEB_PUBSUB_CONNECTION_STRING` with one of the connection string in the `Keys` section of your Web PubSub resource on Azure.
1795+
- Set `WEB_PUBSUB_CONNECTION_STRING` with the primary connection string in the `Keys` section of your Web PubSub resource on Azure.
17561796
17571797
</details>
17581798
@@ -1882,7 +1922,7 @@ The last step is to consume the newly published transcriptions in the demo Web A
18821922
18831923
> Set environment variables in your Static Web App for:
18841924
> - The connection string of the Web PubSub with `WPS_CONNECTION_STRING`
1885-
> - The Web PubSub name with `WPS_HUB_NAME`
1925+
> - The Web PubSub resource name with `WPS_HUB_NAME`
18861926
> - Ensure that new transcriptions are displayed in the Web App as you upload new audio files.
18871927
18881928
</div>
@@ -1941,5 +1981,4 @@ To do so, click on `delete resource group` in the Azure Portal to delete all the
19411981
```bash
19421982
# Delete the resource group with all the resources
19431983
az group delete --name <resource-group>
1944-
19451984
```

src/solutions/dotnet/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## files generated by popular Visual Studio add-ons.
33

44
# Azure Functions localsettings file
5-
local.settings.json
5+
!local.settings.json
66

77
# User-specific files
88
*.suo
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
5+
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
6+
"STORAGE_ACCOUNT_CONTAINER": "",
7+
"STORAGE_ACCOUNT_CONNECTION_STRING": "",
8+
"WEB_PUBSUB_HUB_ID": "",
9+
"WEB_PUBSUB_CONNECTION_STRING": "",
10+
"COSMOS_DB_DATABASE_NAME": "",
11+
"COSMOS_DB_CONTAINER_ID": "",
12+
"COSMOS_DB_CONNECTION_STRING_SETTING": ""
13+
}
14+
}

src/solutions/nodejs/.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ out
9191
bin
9292
obj
9393
appsettings.json
94-
local.settings.json
94+
95+
# Azure Functions localsettings file
96+
!local.settings.json
9597

9698
# Azurite artifacts
9799
__blobstorage__
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"FUNCTIONS_WORKER_RUNTIME": "node",
5+
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
6+
"STORAGE_ACCOUNT_CONTAINER": "",
7+
"STORAGE_ACCOUNT_CONNECTION_STRING": "",
8+
"WEB_PUBSUB_HUB_ID": "",
9+
"WEB_PUBSUB_CONNECTION_STRING": "",
10+
"COSMOS_DB_DATABASE_NAME": "",
11+
"COSMOS_DB_CONTAINER_ID": "",
12+
"COSMOS_DB_CONNECTION_STRING_SETTING": ""
13+
}
14+
}

terraform/aai.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "azurerm_application_insights" "this" {
2+
name = format("aai-%s", local.resource_suffix_kebabcase)
3+
location = azurerm_resource_group.this.location
4+
resource_group_name = azurerm_resource_group.this.name
5+
application_type = "web"
6+
}

terraform/cognitive.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "azurerm_cognitive_account" "this" {
2+
name = format("cog-%s", local.resource_suffix_kebabcase)
3+
location = azurerm_resource_group.this.location
4+
resource_group_name = azurerm_resource_group.this.name
5+
kind = "SpeechServices"
6+
7+
sku_name = "S0"
8+
9+
tags = local.tags
10+
}

terraform/cosmos_db.tf

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
resource "azurerm_cosmosdb_account" "this" {
2+
name = format("cosmos-%s", local.resource_suffix_kebabcase)
3+
location = azurerm_resource_group.this.location
4+
resource_group_name = azurerm_resource_group.this.name
5+
offer_type = "Standard"
6+
kind = "GlobalDocumentDB"
7+
tags = local.tags
8+
9+
capabilities {
10+
name = "EnableServerless"
11+
}
12+
13+
consistency_policy {
14+
consistency_level = "Session"
15+
max_interval_in_seconds = 5
16+
max_staleness_prefix = 100
17+
}
18+
19+
geo_location {
20+
location = azurerm_resource_group.this.location
21+
failover_priority = 0
22+
}
23+
}
24+
25+
resource "azurerm_cosmosdb_sql_database" "this" {
26+
name = local.cosmos_db_database_name
27+
resource_group_name = azurerm_cosmosdb_account.this.resource_group_name
28+
account_name = azurerm_cosmosdb_account.this.name
29+
}
30+
31+
resource "azurerm_cosmosdb_sql_container" "this" {
32+
name = local.cosmos_db_container_name
33+
resource_group_name = azurerm_cosmosdb_account.this.resource_group_name
34+
account_name = azurerm_cosmosdb_account.this.name
35+
database_name = azurerm_cosmosdb_sql_database.this.name
36+
partition_key_path = "/id"
37+
partition_key_version = 1
38+
39+
indexing_policy {
40+
indexing_mode = "consistent"
41+
42+
included_path {
43+
path = "/*"
44+
}
45+
46+
included_path {
47+
path = "/included/?"
48+
}
49+
50+
excluded_path {
51+
path = "/excluded/?"
52+
}
53+
}
54+
55+
unique_key {
56+
paths = ["/idlong", "/idshort"]
57+
}
58+
}

terraform/data.tf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "azurerm_client_config" "current" {}

terraform/egst.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "azurerm_eventgrid_system_topic" "this" {
2+
count = var.full_deployment ? 1 : 0
3+
name = format("egst-audio-storage-%s", local.resource_suffix_kebabcase)
4+
resource_group_name = azurerm_resource_group.this.name
5+
location = azurerm_resource_group.this.location
6+
source_arm_resource_id = azurerm_storage_account.this.id
7+
topic_type = "Microsoft.Storage.StorageAccounts"
8+
}

terraform/func.tf

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
resource "azurerm_linux_function_app" "func_cache" {
2+
name = format("func-%s", local.resource_suffix_kebabcase)
3+
resource_group_name = azurerm_resource_group.this.name
4+
location = azurerm_resource_group.this.location
5+
6+
storage_account_name = azurerm_storage_account.func.name
7+
storage_account_access_key = azurerm_storage_account.func.primary_access_key
8+
service_plan_id = azurerm_service_plan.this.id
9+
10+
tags = local.tags
11+
12+
identity {
13+
type = "SystemAssigned"
14+
}
15+
16+
app_settings = {
17+
FUNCTIONS_WORKER_RUNTIME = "dotnet-isolated"
18+
STORAGE_ACCOUNT_CONTAINER = "audios"
19+
STORAGE_ACCOUNT_CONNECTION_STRING = azurerm_storage_account.this.primary_connection_string
20+
APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.this.instrumentation_key
21+
APPLICATIONINSIGHTS_CONNECTION_STRING = azurerm_application_insights.this.connection_string
22+
COSMOS_DB_DATABASE_NAME = local.cosmos_db_database_name
23+
COSMOS_DB_CONTAINER_ID = local.cosmos_db_container_name
24+
COSMOS_DB_CONNECTION_STRING_SETTING = azurerm_cosmosdb_account.this.primary_sql_connection_string
25+
WEB_PUBSUB_HUB_ID = azurerm_web_pubsub.this.name
26+
WEB_PUBSUB_CONNECTION_STRING = azurerm_web_pubsub.this.primary_connection_string
27+
}
28+
29+
site_config {
30+
application_stack {
31+
dotnet_version = "7.0"
32+
use_dotnet_isolated_runtime = true
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)