Terraform module for creating app service environment Azure V2 - azure

I have a terraform module that creates app service environment using an ARM template and I am planning to move to terraform module azurerm_app_service_encironment as arm templates are getting deprecated.
When I search the terraform repo with app service environment here , I get module azurerm_app_service_Environment and azurerm_app_service_environment_v3. I am currently using ASEV2, how do I create that using terraform? I see V3 has a separate module, what about V2?
Also my ARM template is using params like dnsSuffix which I cannot find in ASE terraform module but exist in ASE version 3.

There is no document available in terraform for azurerm_app_service_environment_v2 but if you are planning to Migrate App Service Environment v3 from azurerm_app_service_environment_v2 using ARM so you can refer this document :
Also there is feature difference between azurerm_app_service_environment and azurerm_app_service_environment_v3 so few features available in update version that not in earlier version so that is the reason dns_suffix is not there in azurerm_app_service_environment.
I tried to create app_service_enviroment from portal you only have option to create App Service Environment v3(Latest).
Note : After 31 August 2024, if you haven't migrated to App Service Environment v3, your App Service Environment v1/v2s and the apps deployed in them will no longer be available.

Related

Azure Function App shows custom runtime for images deployed as docker image

I am deploying an Azure Function via Terraform as a docker image and using the mcr.microsoft.com/azure-functions/python:4-python3.9-slim image as base.
I found no explanation on why the runtime version is still custom (~4) as seen on the image below.
[Configuration page, Function runtime settings]
I tried to specify the following App Setting for the Function App:
FUNCTIONS_WORKER_RUNTIME = "python"
This does not change anything, the function works with or without this setting.
Based on all the Microsoft documentation, there is no evidence why it shows custom (~4) instead of ~4 .
Is it completely normal because of the docker image or is some configuration missing?
Based on all the Microsoft documentation, there is no evidence why it shows custom (~4) instead of ~4 .
The Azure Function Image mcr.microsoft.com/azure-functions/python:4-python3.9-slim states that the Python 3.9 Version with Azure Functions Core Tools Version 4:
As given in this Terraform Official Doc of Azure Functions Python, you have to specify the FUNCTIONS_WORKER_RUNTIME to python:
app_settings {
FUNCTIONS_WORKER_RUNTIME = "python"
}
When you deploy the base image of Python docker Azure Functions to the Azure Function App in the Cloud, then the Function Worker Runtime will be set to Python if specified in the Terraform Code:
Azure Portal shows custom (~4) for Runtime version in both cases.
If you have specified the version = "~4" under function app resource in the terraform code, then the function runtime version is set to 4 in the Azure portal, given in the Same Terraform doc given above.
Even Python 3.9 version is supported in both V4 and V3 of Azure Functions Core Tools as mentioned in this MS Doc, you have used the Version 4 of Python 3.9 Azure Functions. So, the Runtime version is Application Settings Configuration Menu is set to 4.
Refer to this MCR Doc for list of the Supported Python Version in Azure Functions - Docker Context to the Azure Functions Core tools Version

Upgraded Azure Function cannot test from the portal

We had a Azure Function with Timer Trigger which was develop using function version 3.0 and .NET 3.1. This function is running on Windows App Service Plan on Azure. So, I have upgraded it to function version 4.0 and .NET 6.0 using below steps:
Upgrade your local project
The following changes are required in the .csproj XML project file:
Change the value of PropertyGroup.TargetFramework to net6.0.
Change the value of PropertyGroup.AzureFunctionsVersion to v4.
Replace the existing ItemGroup.PackageReference list with the following ItemGroup:
Image
After you make these changes, your updated project should look like the following example:
Image
Upgrade the local.settings.json file
Image
Run the function app locally and verify the functionality.
Upgrade your function app in Azure
Run below command to set the FUNCTIONS_EXTENSION_VERSION application setting to ~4 on your function app in Azure.
az functionapp config appsettings set --settings FUNCTIONS_EXTENSION_VERSION=~4 -g <RESOURCE_GROUP_NAME> -n <APP_NAME>
Change the .NET version of the function app. If you're function app is hosted on Windows, run below command.
az functionapp config set --net-framework-version v6.0 -g <RESOURCE_GROUP_NAME> -n <APP_NAME>
However, I cannot test or see the function.json file from Azure Portal.
I have taken the .NET 3.1 Azure Function Project with Timer Trigger in the VS 2022 IDE:
Published the .NET Core 3.1 Azure Functions Project to Azure Function App in the Azure Portal and then changed the FUNCTIONS_EXTENSION_VERSION to 4 using Azure CLI Command by following this MS Doc:
Running locally after migration to V4-.NET 6:
Then, deployed the migrated project to the Azure Function App and tested as shown below:
I was able to find the reason for the issue by running "Diagnose and solve problems" from Azure portal.
The issue was related to the function name. My function name length was more than 32 characters long. By default, the Host ID is auto-generated from the Function App name, by taking the first 32 characters. If you have multiple Function Apps sharing a single storage account and they're each using the same Host ID (generated or explicit), that can result in a Host ID collision. For example, if you have multiple apps with names longer than 32 characters their computed IDs may be the same. Consider two Function Apps with names myfunctionappwithareallylongname-eastus-production and
myfunctionappwithareallylongname-westus-production
that are sharing the same storage account. The first 32 characters of these names are the same, resulting in the same Host ID myfunctionappwithareallylongname being generated for each(Please refer https://github.com/Azure/azure-functions-host/wiki/Host-IDs#host-id-collisions for more information).
So, to solve the issue, I just rename the function name on Azure.

Azure Terraform initial setup

I worked with Terraform for AWS before successfully. Now I am trying to work with Azure and facing a few challenges. I have successfully authenticated to my azure account using Azure CLI. When I run the basic terraform provider arm .tf and do a terraform init it just works. But when I put in any additional code like container creation or blob creation .tfs, the init is not working and is giving me the below message :
No available provider "azure" plugins are compatible with this Terraform version.
Error: no available version is compatible with this version of Terraform
Terraform version :
bash-3.2$ terraform -v
Terraform v0.12.19
+ provider.azurerm v1.38.0
I used version 1.38.0 and tried many others but it still continues to give me error.
They are the two providers for the different Azure models.
Azure Service Management Provider model is the classic model in Azure and is not recommended to use now. It provides the resources with format azure_xxx.
Azure Resource Manager Provider model is the Resource Manager model which calls ARM and is recommended to use and supported well. It provides the resources with format azurerm_xxx.
You can also learn more about the ASM and ARM model in document Azure Resource Manager vs. classic deployment: Understand deployment models and the state of your resources.

Azure App Service sticky slot settings in Terraform

I'm using Terraform to create a slot on an azure app service but I need some of the app settings to be sticky. This is normally done using the "slotConfigNames" in ARM but doesn't seem to be possible in Terraform.
Is this possible?
https://www.terraform.io/docs/providers/azurerm/r/app_service_slot.html
Thanks
It is not possible to use azurerm_app_service_slot directly since the Sticky Slot settings are not supported in terraform. But you can make use of the Azure Template Deployment resource in Terraform.
The solution will create an App Service with one or more Slots
attached to it and will also make use of Slot settings in order to
have the configuration tied to the environment as opposed to transform
a config file with a CI/CD server such as Octopus Deploy or perhaps
use multiple appSettings.json for each environment as you would on a
.net application.
You can get more details from this blog.
This has ben implemented now in v3.4.0 of the AzureRM provider.
terraform-provider-azurerm 3.4.0 (April 28, 2022) release notes
terraform documentation: sticky_settings
UPDATE: after some investigation into the AZ powershell module for sticky settings (Set-AzWebAppSlotConfigName), I realized that you don't need to set this on the terraform slot resource - you just set it on the primary resource (production slot).
The sticky_settings block has been added to the parent resources (app service, function app), but not the slot.

How to add azure function's javascript / c# code into terraform scripts?

I am working in a project that will be deployed at my client's Microsoft Azure. Thus I am currently testing terraform to assist me when the time comes.
create a azure function with terraform that will trigger on blob storage input data
My question is about how to add the azure functions's javascript/c# code into the terraform script so it will be automatically deployed ?
I checked the terraform docs, but it wasn't of much help:
https://www.terraform.io/docs/providers/azurerm/r/function_app.html
Any ideas?
Terraform doesn't handle pushing code to Azure resources, that's usually done in a following step in the pipeline (e.g. 1- execute terraform 2- deploy code).
However, the Azure Function App does have the ability to connect directly to your repo, and the Terraform azurerm_function_app module exposes the source_control property.
Terraform's azurerm_function_app documentation
So with Terraform you can configure the function app to pull the code directly from the repo when a change is detected.
Microsoft's Azure Function Continuous Deployment documentation

Resources