<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thivya Thogesan on Medium]]></title>
        <description><![CDATA[Stories by Thivya Thogesan on Medium]]></description>
        <link>https://medium.com/@thivyathog?source=rss-cf44a4fbcd2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Z-TlytiwiA_idNzrLEKmpQ.jpeg</url>
            <title>Stories by Thivya Thogesan on Medium</title>
            <link>https://medium.com/@thivyathog?source=rss-cf44a4fbcd2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:13:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thivyathog/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploy Azure Functions using Terraform]]></title>
            <link>https://medium.com/@thivyathog/deploy-azure-functions-using-terraform-f36ebeb485a2?source=rss-cf44a4fbcd2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f36ebeb485a2</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Thivya Thogesan]]></dc:creator>
            <pubDate>Wed, 10 Nov 2021 10:30:06 GMT</pubDate>
            <atom:updated>2021-11-10T10:33:54.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*4m_Xptrp0ysPjMBh5p9HBw.png" /></figure><p>There are plenty of articles based on the topic Azure Functions , but most of them fail to explain on how to automate the deployment based on a real world scenario.</p><p>Worry NOT! Because ,In this post, I’ll give you an overview of <a href="https://azure.microsoft.com/en-us/services/functions/"><strong>Azure Functions</strong></a><strong> ,</strong><a href="https://www.terraform.io/"><strong>Terraform</strong></a><strong> </strong>and a guide on how to provision azure function using terraform with a simple hands-on example.</p><p>I will start off the article by giving a brief insight on Azure functions and Terraform before we dive into the Hands-on Example.</p><h3>What is Azure Functions?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*stWEyktkMyORLi4bp3ERBA.png" /><figcaption>Overview of Azure Function Composition</figcaption></figure><p>Azure Functions, similar to <a href="https://aws.amazon.com/lambda/">AWS Lambda</a>, is a serverless event driven computing service from Microsoft that may run code in response to specified events or triggers. It is in charge of deployment, availability, scalability, and a lot more. This is also known as FAAS( Function as a Service). Azure Functions are very cost-effective due to their pay-as-you-go pricing model which it inherits from it’s FAAS nature. This is very advantageous for applications which have workloads which contains spikes.</p><p>One of the key aspect of Azure Function is that we only need to focus on the code that matters most to us, while the Azure Functions take care of the rest (underlying infrastructure, operation system, e.t.c).</p><p>Azure Functions are event driven , that is each function will have a specific trigger defined and the function will execute once the trigger is executed. There are several type of <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp#supported-bindings">Triggers</a> that can be associated with the function,some of them are blob storage trigger, HTTP endpoint, Kaka endpoint.</p><p>Azure Functions offers support for a variety of <a href="https://docs.microsoft.com/en-us/azure/azure-functions/supported-languages?WT.mc_id=telerikfunctionspt2-telerikarticle-masoucou">languages</a> which you can choose on to write your logic. The most common languages are Java,Javascript,C# or Python.</p><p>I have covered all what you need to know about azure functions in a brief overview but if you want to learn more, you can always visit their official documentation : <a href="https://docs.microsoft.com/en-us/azure/azure-functions/#:~:text=Azure%20Functions%20is%20a%20cloud,provides%20serverless%20compute%20for%20Azure.https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks?filteringStatus=active&amp;filteringText=&amp;viewNested=true&amp;hideStacks=false">Azure Functions Documentation</a>.</p><h3>What is Terraform?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATNMu1nQTnIXauJYXlDDGw.png" /><figcaption>Terraform IaC Tool</figcaption></figure><p>I’m sure you’ve heard of the Infrastructure as Code (IaC) idea if you’re a DevOps engineer or someone who needs to deal with DevOps-related tasks on a daily basis. If you have no clue what IaC is, it is basically a method of using machine-readable definition files(programming scripts)to provision and manage an entire IT infrastructure. Terraform is one of the most famous IaC tool that has caught the eyes of many IT Engineers.</p><p>Terraform is very similar to the AWS CloudFormation Service which is used to automate the provision of resources.</p><p>Terraform is an open-source tool developed by <a href="https://www.terraform.io/"><em>HashiCorp</em></a><em>. </em>It generates an execution plan that outlines how it will arrive to the desired state, which it then uses to build the infrastructure provided. Terraform can figure out what changed as the configuration changes and provide incremental execution plans that can be put into action.</p><p>The fascinating thing about the declarative nature is that it keeps the state of your infrastructure, so when you run it, it checks what you want vs what’s already in place and only modifies what is required!</p><p>Terraform follows GitOps principles, which means that all code is kept in source control, which means that any change must be authorized by the team, and all change history is saved for auditing purposes.</p><p>If you want to know more about the core concepts which terraform is built on, check the <a href="https://www.terraform.io/intro/index.html"><strong>official documentation</strong></a><strong>.</strong></p><h3>Diving into Hands-On Example</h3><p>It would be advisable if you are aware of the basic concepts of <a href="https://learn.hashicorp.com/terraform"><strong>Terraform</strong></a>.</p><p>We will be creating the terraform script to deploy a python based azure Function which uses a blob storage trigger.</p><h3>Prerequisites</h3><ul><li>An Azure account with an active subscription. <a href="https://azure.microsoft.com/free/?ref=microsoft.com&amp;utm_source=microsoft.com&amp;utm_medium=docs&amp;utm_campaign=visualstudio">Create an account for free</a>.</li><li><strong>Python </strong>(3.6 or 3.7; 3.8 is not yet supported).</li><li><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli"><strong>Azure CLI</strong></a><strong> </strong>to manage Azure resources.</li><li><a href="https://code.visualstudio.com/"><strong>Visual Studio Code</strong></a> on one of the <a href="https://code.visualstudio.com/docs/supporting/requirements#_platforms">supported platforms</a>.</li><li><a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=linux%2Ccsharp%2Cbash#v2"><strong>Azure Functions Core</strong></a> to manage the functions.</li><li>The <a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions"><strong>Azure Functions extension</strong></a><strong> </strong>for Visual Studio Code.</li><li>Terraform <strong>CLI</strong>. Download it from <a href="https://www.terraform.io/downloads.html"><strong>here</strong></a>, extract it and put it in your system PATH.</li></ul><p>Initial Step is check if you can log into the Azure Portal , then try to log into azure using the below command line command and enter the required details when the browser is launched:</p><p>az login</p><h4>Initiating the Project</h4><p>Create a project directory which contains two folders :</p><ul><li>terraform-infra: contains the terraform files</li><li>functions: Contains the Azure functions.</li></ul><h4>Setting up the Terraform Module</h4><p>We’ll define our infrastructure module in two files, using Terraform’s normal naming convention:</p><p>the cloud resources and their configuration will be defined in main.tf.<br>variables.tf is the file that contains definitions of variables used in main.tf.</p><p>Let’s create the Terraform files that will provision the following:</p><ul><li><strong>Resource Group.</strong></li><li><strong>Storage Account</strong>.</li><li><a href="https://docs.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview"><strong>Application Insights </strong></a>for monitoring.</li><li><strong>Log Analytics Workspace + Diagnostic Setting </strong>for monitoring storage account logs</li><li><a href="https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans"><strong>Service Plan</strong></a> used to run the functions.</li><li><a href="https://docs.azure.cn/zh-cn/cli/functionapp?view=azure-cli-latest"><strong>Function App</strong></a></li></ul><p>Navigate to the created before terraform-infra.</p><p>Create a main.tf file which contains the below code to create the Azure Functions Resources. I will go through the script in detailed later on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b0b59ec27966057b9ba4a6551c52cfc/href">https://medium.com/media/5b0b59ec27966057b9ba4a6551c52cfc/href</a></iframe><ul><li>Line 1 to 16: the script adds <a href="https://www.terraform.io/docs/providers/index.html"><strong>provider</strong></a> for Terraform which is in charge of talking to Azure. The provider is “azurerm” and the version is stated and we also ask it to skip provider registration. we need to substitute the subscription id with our azure subscription id. now you will have the question of, how do we get the subscription ID ? just run <strong><em>az login</em></strong> and get the output. The subscription ID is the “<em>id</em>” field</li></ul><p>Note: Stating the subscription ID on the main.tf is not advisable, configure such that it is replaced at run time.</p><ul><li>Line 18 to 27 : Creates <a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/overview#resource-groups"><strong>Azure Resource Group</strong></a>. azureRG is the unique identifier of the resource, which we refer when creating dependent resources. You can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group">here</a>.</li><li>Line 29 to 43 : Creates <a href="https://azure.microsoft.com/en-us/services/storage/blobs/"><strong>Blob Storage account</strong></a>. it uses the resource group which we created before using it’s identifier, the account tier is set to standard and we are allowing public access. You can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account">here</a>.</li><li>Line 45 to 54: Creates Containers, it uses the storage account’s identifier to create the relevant containers. You can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container">here</a>.</li><li>Line 57 to 63: Creates the <a href="https://docs.microsoft.com/en-us/azure/azure-monitor/logs/quick-create-workspace"><strong>Logs Analytics Workspace</strong></a> to monitor storage account logs. you can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/log_analytics_workspace">here</a>.</li><li>Line 67 to 70: It will fetch all available log and metrics categories. We then enable all of them for the storage account level</li><li>Line 71 to 109: Creates the<a href="https://docs.microsoft.com/en-us/rest/api/monitor/diagnostic-settings"> <strong>diagnostic setting</strong></a> for storage account level, and we have set the retention period as 3 months. The depends on attribute is placed inorder to tell the terraform to not create this resource until the log analytics workspace is created.you can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting">here</a>.</li><li>Line 111 to 113 : It will fetch all available log and metrics categories. We then enable all of them for the blob level.</li><li>Line 115 to 154 : Creates the <a href="https://docs.microsoft.com/en-us/rest/api/monitor/diagnostic-settings"><strong>diagnostic setting</strong></a> for blob level, and we have set the retention period as 3 months. The depends on attribute is placed inorder to tell the terraform to not create this resource until the log analytics workspace is created.you can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting">here</a>.</li><li>Line 156 to 161 : Creates the <a href="https://docs.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview"><strong>application insights</strong></a> for the azure function app.you can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/application_insights">here</a>.</li><li>Line 163 to 180 : Creates a Linux Based <a href="https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans"><strong>app service plan</strong></a> and set the SKU as preffered, for this instance we used P2V3. you can explore the other available SKU here. you can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_plan">here</a>.</li><li>Line 182 to 206: Creates the<a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview"> <strong>Azure Function</strong></a><strong> App</strong>, We configure all the resources we created above :the storage account, the app service plan and the resource group to the function app.Then,we set the OS Type as Linux and the Linux_fx_version as Python and we enable the app settings in which mention the runtime as python and we set the connection string for the azure blob storage and we also set the function app to use application insight which we created before.you can refer the usage of other attributes <a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app">here</a>.</li></ul><p>Create a variables.tf file which contains the below code to add the prefix</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51de42ad86381afdf0bfe118a55f9a94/href">https://medium.com/media/51de42ad86381afdf0bfe118a55f9a94/href</a></iframe><h4>Setting up the Local Function Project</h4><p>Navigate into the functions folder and open this folder using the visual studio code.</p><p>Before going into setting up the local function project , we need to set up the virtual environment for python. To not mess up our system’s python environment, using a virtual environment is advisable and it will be needed to further develop the function.</p><p>Create the virtual environment,using the following command:</p><pre>python -m venv azure_functions</pre><p>Activate the virtual environment,using the following command:</p><pre>source azure_function/bin/activate</pre><p>A function project is a container to hold one or multiple azure functions which all share the same configurations.</p><p>We are going to use the visual studio Extension to create the Local Function Project</p><ol><li>Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project… icon.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*cOwsJjPhjTAToySWE9nmJg.png" /><figcaption>Create Azure Function</figcaption></figure><p>2. Choose a directory location for your project workspace and choose Select</p><p>3.Enter The following information for the Prompts</p><ul><li>Select a language for your function project: Choose Python.</li><li>Select a Python alias to create a virtual environment: Choose the location of your Python interpreter.<br>If the location isn’t shown, type in the full path to your Python binary.</li><li>Select a template for your project’s first function: Choose Azure Blob Storage trigger.</li><li>Provide a function name: Type AzureFunctionTest1</li><li>Select your Storage Account</li></ul><p>As you can see now, the command has created a new folder, and inside that folder it contains two essential files <em>`__init__.py` </em>and <em>`function.json`.</em></p><p><em>`__init__.py` </em>is the default starting point for your function. To Learn more about the ‘func.InputStream’ : <a href="https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions.inputstream?view=azure-python">Documentation</a>.</p><p><em>`function.json` is the configuration file for the azure Function.</em></p><p>4.Run the function locally and see.</p><h4>Deploying the Infrastructure and Publishing the Function App</h4><p>That’s it, now we are ready to deploy the infrastructure. First navigate to terraform-infra,then let’s init Terraform, run:</p><p>terraform init</p><p>Before confirming the changes to view the infrastructure changes that were made run,</p><pre>terraform plan</pre><p>And if all the changes are as expected,Then finally run:</p><pre>terraform apply</pre><p>The infrastructure should be deployed to Azure as a result of this. To check the results, go to the portal. The storage account and the Functions App should be visible.</p><p>You will notice that There are no functions available when you click the functions menu on the left. This is due to the fact that the functions are deployed using Azure Core Tools.</p><p>We keep infrastructure and code separate. Terraform should not handle the functions because they are the responsibility of the developers.To deploy the functions go the the folder and run:</p><pre>func azure functionapp publish &lt;function-app-name&gt;</pre><p>Note that that&lt;function-app-name&gt; is the name of the Function App that Terraform previously created, this is the most important link between Azure Functions CLI (for <em>developers</em>) and Terraform (for <em>DevOps</em>).</p><p>Now you should be able to see the functions in the portal and the output will be shown like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*I6vV1hkj4mo14GS1HiUoxA.png" /></figure><p>Tadah! we are finally done with provisioning the resources through terraform and also publishing the Azure Function App.</p><p>Hope you got a insight to Terraform and Azure Functions and on how to deploy the infrastructure using Terraform!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f36ebeb485a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>