Deploying Azure Function & Logic App
Task Requirements :
Create and deploy an Azure Function that performs a specific task (e.g file processing) and documents the process.
Provision an Azure Logic App that performs a specific task and documents the use case.
Implement infrastructures for both serverless applications using Terraform.
Execution :
Create Terraform Files & Define Each Resource Block
Create a terraform sub-folder that is going to have your terraform files (e.g. main.tf, data.tf, providers.tf, variables.tf, storage.tf, logic.tf, terraform.tfvars etc).
Sample of the terraform files can be found at this link ----> https://github.com/mightygull/Knixat_PG/blob/main/Functions%20Folder/File%20Processing%20Time%20Trigger/main.tf
First things first, run the
terraform init
command to initialize the plugins from the cloud provider.Run the
terraform validate
&terraform plan
command to verify the terraform codes and also preview how many resources are going to be created and used.Then run
terraform apply --auto-approve
command to create the function app & logic app in the Azure portal.
Create an Azure Function
Once your Function App is created, go to its dashboard in the Azure Portal.
In the left sidebar, click on "Functions" under the "Functions" section.
Click the "+ New function" button to create a new function. You can choose a template that suits your file processing needs examples are http trigger, service bus trigger, blob trigger. In my case, I used a time trigger.
Configure function, the template of the cron-jobs is to run a backup for certain file extensions in a blob storage once it is 12 AM daily, also configured the function app to use a python runtime stack.
Typically, you'll use Azure Blob Storage bindings for file processing. Configure the bindings and timer by editing the
function.json
file. Sample of the file can be found at this link ----> https://github.com/mightygull/Knixat_PG/blob/main/Functions%20Folder/File%20Processing%20Time%20Trigger/function.json
Develop the File Processing Logic
In the Function App, navigate to your newly created function and click on "Code + Test."
Write the code to process the files. A sample of the
init.py
can be found in this link ----> https://github.com/mightygull/Knixat_PG/blob/main/Functions%20Folder/File%20Processing%20Time%20Trigger/init.pyTest your function locally using the
Azure Functions Core Tools
to ensure it works as expected.
Deploy the Azure Function
Click on the Azure Tool Extension on the Visual Studio Code and navigate to the workspace section.
Click on the Azure Function Icon to deploy the function in your workspace in your preferred resource group.
Automating Slack Notifications for GitHub Pull Requests with Azure Logic App
Create an Azure Logic App :
- The Logic App has already been configured to use the appropriate subscription and resource group in the terraform file.
Define a Trigger :
- Add a trigger to start the workflow. In this case, select the "When a pull request is created" trigger from GitHub.
Connect GitHub :
Sign in to your GitHub account and configure the Logic App to connect to your GitHub repository.
Select the specific repository and set the trigger to activate when a new pull request is created.
Add a Condition :
- You can add a condition to filter pull requests based on specific criteria, such as the branch name, labels, or author, to determine whether you want to send a Slack notification.
Connect to Slack :
Add a step to send a message to Slack.
Configure the Slack action to connect to your Slack workspace.
Select the target channel or user where you want to send the message.
Create a Notification Message :
- In the Slack message action, define the content of the message. You can use dynamic content from the GitHub trigger to include information about the pull request, title, author, or a link to the pull request.
Save and Enable the Logic App :
- Save your Logic App and enable it. It will now listen for new pull requests in the specified GitHub repository.
A sample of the logic app code template can be found at this link ----> https://github.com/mightygull/Knixat_PG/blob/main/Logic_App%20Folder/logicapp.json
Screenshot Of The Logic App Work Template
Screenshot Of The Slack Notifications Created
Subscribe to my newsletter
Read articles from Samson Oladipo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Samson Oladipo
Samson Oladipo
DevOps enthusiast sharing real-world insights. ๐ #Automation #CI/CD #InfrastructureAsCode