Posted on Leave a comment

Deploy azurerm function app with zip_deploy_file terraform

When you need to deploy code in a function app using terraform you can use the zip_deploy_file parameter. Using this you can specify a zip file that will be created from your committed code and by doing so you can dynamically deploy code using terraform.

The first thing that you will need to do is to create a folder with the code that you want to commit in the function_app. In my example I have the terraform files inside the aws and azure folders and in the same directory I have a folder called resources where the code is located. This code need to be deployed in the serverless function app.

Create a data archive_file with terraform and specify where your code is located. You should correctly point where the files are stored.

data "archive_file" "python_function_package" {  
  type = "zip"  
  source_file = "../resources/" 
  output_path = ""

Then you should use the above data archive and use it along with zip_deploy_file.

resource "azurerm_linux_function_app" "functionapp" {
  name                = var.serviceplan_name
  resource_group_name =
  location            = azurerm_resource_group.rg.location

  storage_account_name       =
  storage_account_access_key =
  service_plan_id            =
  zip_deploy_file = data.archive_file.python_function_package.output_path
  app_settings              = "${var.app_settings}"

  site_config {
    application_stack {
        python_version = "3.10"


When you deploy your terraform code the function app will correctly upload the code in your infra component and you can check that by navigating inside the code on azure portal.

azurerm_linux_function_app | Resources | hashicorp/azurerm | Terraform | Terraform Registry

Posted on Leave a comment

Function Apps are not supported in Free and Shared plans. Please choose a different plan

When you use terraform and functions apps in azure you may end up with the below issue.

Creating Linux Function App: (Site Name "multicloud-serviceplan" / Resource
│ Group "multicloudrg"): web.AppsClient#CreateOrUpdate: Failure sending
│ request: StatusCode=400 -- Original Error: Code="BadRequest" Message="You
│ tried creating a function app in the 'Free' SKU. Function Apps are not
│ supported in Free and Shared plans. Please choose a different plan."
│ Details=[{"Message":"You tried creating a function app in the 'Free' SKU.
│ Function Apps are not supported in Free and Shared plans. Please choose a
│ different
│ plan.

The issue indicates that a Function app cannot be created using the Free tier F1 of the service plan.

In order to fix the issue you must select one of the additional plans Consumption, Premium or Dedicated.

In Consumption plan hosting, each function app typically runs in its own plan. In the Azure portal or in code, you may also see the Consumption plan referred to as Dynamic or Y1.

The details of each plans are described below.

The terraform issue will be resolved when you select Y1 instead of F1 which is the free tier.

Posted on Leave a comment

Create a confluence page with REST API

Confluence can become a great tool when it is combined with other services that we use. In some cases tho you cannot find an available integration but there comes the rest api that you can use.

In this example we will automatically create a confluence page from another service using a rest API. In this example I was working on a custom confluence installation and not jira cloud. When using Jira Cloud the API can be different.

Using the link from confluence documentation you can locate any actions that you need to perform. Lets take as example the creation of a sub-page inside an existing page. You can find the curl API call below.

curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer TOKEN' -d '{"type":"page","title":"test incident","ancestors":[{"id":pageID}], "space":{"key":"dd"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}'


TOKEN: You should create a personal access token for a user with the rights to open/create/edit a page. You can use also username and password authentication with parameter -u user:password.
Title: the title of your new sub-page
Ancestors: The parent page under which to create a new page.
Space Key: your confluence space where you will create the page.
Body: you should keep the json format and pass the content you need to appear on the page body.
URL: you should use the url of the REST API. Just change the domain name and it will work on v7.18+

When we make the request we can see that a new page is created with the title that we provided.

Posted on Leave a comment

Create and use terraform modules

Terraform modules are useful in various scenarios when working with Infrastructure as Code (IaC) using Terraform. Modules provide a way to encapsulate and reuse infrastructure configurations, making it easier to manage and scale your infrastructure code.

Every Terraform configuration has at least one module, known as its root module, which consists of the resources defined in the .tf files in the main working directory.

A module can call other modules, which lets you include the child module’s resources into the configuration in a concise way. Modules can also be called multiple times, either within the same configuration or in separate configurations, allowing resource configurations to be packaged and re-used.

Lets take a look how we can create and use terraform modules. The first thing that you will need to do is to structure your code somehow. A most common way to create a structure would be to create folders and name them after your module. For example if you have to deploy a cloud solution with multiple components you could create a module for each component. In my structure you can find two folders with the name module1 and module2. The module2 will call module1 to reuse its code inside the terraform configuration.

The module1 folder contains the files that are shown. file will be used to fetch all the necessary providers. In my example I use the random provider to generate a random string with terraform.

terraform {
  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "~> 3.5"
} will call the random code to generate the string.

resource "random_string" "module1_random" {
  length           = 16
  special          = true
  override_special = "/@£$"

And finally the file will be used to mark the string as an output and print it in the console.

The module2 folder will only include a which will call module1. In order to make a module in terraform we will only need to specify the location of the folder. We do not need complex actions or definitions. In this example module2 will call module1 to generate the random string.

the file will only call the module1

module "kati" {
    source = "../module1"

In order to call the module I will need to perform an apply on module2.

cd module2; terraform apply

As we have not specified an output variable in module2 the result will not be printed in the console, you can see from below screenshot that module2 is calling kati file from module1 to generate the random string.

However we can find the result by navigating in the terraform.tfstate file of module2.

When we have more complex scenarios we will need to pass variables inside the calling modules. In order to learn how to pass variables in the calling modules you can read my previous article.

You can find the example on GitHub

Modules – Configuration Language | Terraform | HashiCorp Developer

Youtube video: