Skip to content

Commit 299ae0e

Browse files
author
hvalfangst
committed
Created scripts for provisioning Azure resources with Terraform and a preliminary README
0 parents  commit 299ae0e

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Azure Function ETL with Pandas and CI/CD
2+
3+
4+
This repository hosts a pair of Azure Functions designed for Extract, Transform, Load (ETL) operations:
5+
6+
1. HTTP-triggered Function:
7+
Handles CSV file uploads from request body to the Blob 'in/input.csv' under container 'hvalfangstcontainer'.
8+
9+
2. Blob-triggered Function:
10+
Listens for changes to aforementioned Blob 'in/input.csv' and responds by loading the CSV into a Pandas dataframe on changes.
11+
Conducts calculations to determine correlations between specific columns.
12+
Stores the resulting correlations in a dictionary and dumps said dictionary to JSON.
13+
It then proceeds to upload the JSON contents to the Blob 'out/statistics.json'.
14+
15+
16+
17+
A CI/CD pipeline has been implemented utilizing a GitHub Actions Workflow script,
18+
which enabled automatic deployment to Azure Function App on repository pushes. Azure resources are provisioned with Terraform via shell scripts 'up' and 'down'.
19+
20+
## Requirements
21+
22+
* x86-64
23+
* Linux/Unix
24+
* [Python](https://www.python.org/downloads/)
25+
26+
## Creating resources
27+
28+
The shell script 'up' allocates Azure resources with Terraform.
29+
30+
## Deleting resources
31+
32+
The shell script 'down' deallocates Azure resources.
33+
34+
## Guide
35+
36+
### 1. Provision Azure Resources
37+
38+
- Run the 'up' script to provision Azure resources with Terraform.
39+
40+
41+
### 2. Access Azure Portal
42+
43+
- Open your browser and navigate to the Azure Portal.
44+
45+
46+
### 3. Function App Publish Profile
47+
48+
- Navigate to the newly created Function App 'hvalfangstlinuxfunctionapp'
49+
- Click on 'Get publish profile' to download a file.
50+
- The associated file contents will be used in the next step.
51+
52+
### 4. GitHub Repository Secrets
53+
54+
- Open the 'Settings' tab of your GitHub repository.
55+
- Click on 'Actions' under 'Security' -> 'Secrets and variables'.
56+
- Create the following repository secret:
57+
- PUBLISH_PROFILE: Copy value from downloaded file obtained in step #3
58+
59+
### 5. Deploy Workflow
60+
61+
Our Azure Function will be deployed on repository pushes by utilizing a GitHub Actions workflow script.

down.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Exits immediately if a command exits with a non-zero status
4+
set -e
5+
6+
echo "Deleting Azure resources..."
7+
terraform -chdir=infra destroy;

infra/terraform.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "3.49.0"
6+
}
7+
}
8+
}
9+
10+
provider "azurerm" {
11+
features {}
12+
}
13+
14+
resource "azurerm_resource_group" "hvalfangst" {
15+
name = "hvalfangstresourcegroup"
16+
location = "West Europe"
17+
}
18+
19+
resource "azurerm_storage_account" "hvalfangst" {
20+
name = "hvalfangststorageaccount"
21+
resource_group_name = azurerm_resource_group.hvalfangst.name
22+
location = azurerm_resource_group.hvalfangst.location
23+
account_tier = "Standard"
24+
account_replication_type = "LRS"
25+
}
26+
27+
resource "azurerm_storage_container" "hvalfangst" {
28+
name = "hvalfangstcontainer"
29+
storage_account_name = azurerm_storage_account.hvalfangst.name
30+
container_access_type = "private"
31+
}
32+
33+
resource "azurerm_service_plan" "hvalfangst" {
34+
name = "hvalfangstserviceplan"
35+
location = azurerm_resource_group.hvalfangst.location
36+
resource_group_name = azurerm_resource_group.hvalfangst.name
37+
os_type = "Linux"
38+
sku_name = "Y1"
39+
}
40+
41+
resource "azurerm_application_insights" "hvalfangst" {
42+
name = "hvalfangstapplicationinsights"
43+
resource_group_name = azurerm_resource_group.hvalfangst.name
44+
location = azurerm_resource_group.hvalfangst.location
45+
application_type = "other"
46+
}
47+
48+
resource "azurerm_linux_function_app" "hvalfangst" {
49+
name = "hvalfangstlinuxfunctionapp"
50+
resource_group_name = azurerm_resource_group.hvalfangst.name
51+
location = azurerm_resource_group.hvalfangst.location
52+
storage_account_name = azurerm_storage_account.hvalfangst.name
53+
storage_account_access_key = azurerm_storage_account.hvalfangst.primary_access_key
54+
service_plan_id = azurerm_service_plan.hvalfangst.id
55+
site_config {
56+
application_insights_key = azurerm_application_insights.hvalfangst.instrumentation_key
57+
application_insights_connection_string = azurerm_application_insights.hvalfangst.connection_string
58+
application_stack{
59+
python_version = "3.10"
60+
}
61+
}
62+
app_settings = {
63+
"APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.hvalfangst.instrumentation_key
64+
"AzureWebJobsFeatureFlags" = "EnableWorkerIndexing"
65+
}
66+
}

up.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# Exits immediately if a command exits with a non-zero status
4+
set -e
5+
6+
echo "Initializing Terraform..."
7+
terraform -chdir=infra init;
8+
9+
echo "Planning Azure resource provisioning..."
10+
terraform -chdir=infra plan;
11+
12+
echo "Applying planned Azure resource provisioning..."
13+
terraform -chdir=infra apply;

0 commit comments

Comments
 (0)