Azure

Terraform On Azure – Creating A Azure Operate Working On App Service Plan

Introduction

In case you are utilizing the Consumption Plan for Azure Operate, then the Operate execution will get timed out after 5 minutes by default, or at max you’ll be able to set the timeout for 10 minutes. There will be situations the place you could have to host lengthy operating code in Azure Features. For instance, you might be planning to host an extended operating background process on Azure Operate. In such situations, you should use App Service Plan for Azure Features. We created an Azure WebApp utilizing Terraform after which we created Azure Digital Machine and a Storage Account. Within the final article, we created an Azure Operate operating on Consumption Plan. The next are hyperlinks to the earlier articles.

Create Azure Operate utilizing Terraform

Allow us to create a Useful resource Group and inside it, we will create an Azure Operate.

Log in to the Azure portal at https://portal.azure.com. Allow us to use Azure Cloud Shell to create assets utilizing Terraform. Azure Cloud Shell has Terraform put in and you needn’t do any set up or configuration to work with Terraform.

As soon as the Azure Cloud Shell opens up, choose Bash. Allow us to begin creating scripts to create an Azure Operate. We will use nano editor to create the Infrastructure as Code script for the Azure Operate utilizing Terraform.

Execute the next command to open a nano editor and create a file named myterraformscript.tf.

nano myterraformscript.tf

Add the next code to the nano editor. This could create a Useful resource Group. Exchange {ResourceGroup} with the title of your Useful resource Group that you’re planning to create.

terraform {
    required_providers {
        azurerm = {
            supply = "hashicorp/azurerm"
        }
    }
}
supplier "azurerm" {
    options {}
}
useful resource "azurerm_resource_group"
"{ResourceGroup}" {
    title = "{ResourceGroup}"
    location = "eastus"
}

Add the next code in nano editor to create a Storage Account. Exchange {ResourceGroup} with the title of your Useful resource Group and {StorageAccount} with the title of your Storage Account.

useful resource "azurerm_storage_account"
"{StorageAccount}" {
    title = "{StorageAccount}"
    resource_group_name = azurerm_resource_group. {
        ResourceGroup
    }.title
    location = azurerm_resource_group. {
        ResourceGroup
    }.location
    account_tier = "Customary"
    account_replication_type = "LRS"
}

Add the next code to create an App Service Plan. Exchange {ResourceGroup} with the title of your Useful resource Group, {Plan} with the title of your App Service Plan.

useful resource "azurerm_app_service_plan"
"{Plan}" {
    title = "{Plan}"
    location = azurerm_resource_group. {
        ResourceGroup
    }.location
    resource_group_name = azurerm_resource_group. {
        ResourceGroup
    }.title
    sku {
        tier = "Customary"
        dimension = "S1"
    }
}

Add the next code to create the Azure Operate. Exchange {ResourceGroup} with the title of your Useful resource Group, {StorageAccount} with the title of your Storage Account and {Plan} with the title of your App Service Plan.

useful resource "azurerm_function_app"
"{Operate}" {
    title = "{Operate}"
    location = azurerm_resource_group. {
        ResourceGroup
    }.location
    resource_group_name = azurerm_resource_group. {
        ResourceGroup
    }.title
    app_service_plan_id = azurerm_app_service_plan. {
        Plan
    }.id
    storage_account_name = azurerm_storage_account. {
        StorageAccount
    }.title
    storage_account_access_key = azurerm_storage_account. {
        StorageAccount
    }.primary_access_key
}

The next is the script file that you simply created. You’ll be able to consult with the connected script file and check out the pattern.

terraform {
    required_providers {
        azurerm = {
            supply = "hashicorp/azurerm"
        }
    }
}
supplier "azurerm" {
    options {}
}
useful resource "azurerm_resource_group"
"{ResourceGroup}" {
    title = "{ResourceGroup}"
    location = "eastus"
}
useful resource "azurerm_storage_account"
"{StorageAccount}" {
    title = "{StorageAccount}"
    resource_group_name = azurerm_resource_group. {
        ResourceGroup
    }.title
    location = azurerm_resource_group. {
        ResourceGroup
    }.location
    account_tier = "Customary"
    account_replication_type = "LRS"
}
useful resource "azurerm_app_service_plan"
"{Plan}" {
    title = "{Plan}"
    location = azurerm_resource_group. {
        ResourceGroup
    }.location
    resource_group_name = azurerm_resource_group. {
        ResourceGroup
    }.title
    sku {
        tier = "Customary"
        dimension = "S1"
    }
}
useful resource "azurerm_function_app"
"{Operate}" {
    title = "{Operate}"
    location = azurerm_resource_group. {
        ResourceGroup
    }.location
    resource_group_name = azurerm_resource_group. {
        ResourceGroup
    }.title
    app_service_plan_id = azurerm_app_service_plan. {
        Plan
    }.id
    storage_account_name = azurerm_storage_account. {
        StorageAccount
    }.title
    storage_account_access_key = azurerm_storage_account. {
        StorageAccount
    }.primary_access_key
}

Run the next command to provoke Terraform. This could fetch all dependencies wanted to execute the Terraform script.

terraform init

Now allow us to create an execution plan for Terraform. Allow us to present the title of the execution plan within the out parameter.

terraform plan -out myfunc.tfplan

Execute the execution plan utilizing the next command. The Azure Operate will get created.

terraform apply "myfunc.tfplan"

Conclusion

On this article, we discovered tips on how to create an Azure Operate with App Service Plan. Within the subsequent article, we are going to discover ways to create an Azure SQL Database utilizing Terraform.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button