Programmatically Configure HTTPS Only for Azure Function App - azure

Is there a way to programmatically enable the HTTPS Only flag on a custom domain of an Azure Function App? I've been using the CLI quite extensively and have been pleased with the comprehensive coverage it provides, but I can't seem to figure this out out.

Try the command as below.
az functionapp update --name '<function name>' --resource-group '<resource group name>' --set httpsOnly=true

Good news!
There is support for https-only=true in az functionapp create since az-cli version 2.41.0:
Documentation:
https://learn.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-create
Example of command:
az functionapp create \
--name $APPNAME \
--resource-group $RESOURCEGROUP \
--consumption-plan-location $LOCATION \
--storage-account $STORAGEACCOUNTNAME \
--app-insights-key $APPLICATIONINSIGHTS_INSTRUMENTATIONKEY \
--functions-version 4 \
--https-only true
After running the command you will get this in azure portal:

Related

Azure Function App - Swap deployment Slots stuck then crashing completely

Recently my function apps have stopped swapping slots, they worked fine for months but suddenly they have all stopped swapping by taking a long time then crashing. I have recreated the function apps using the same scripts and have replicated the issue but still can't fix.
Is there anything I am setting to stop the slots from switching?
Here is the fundamental build script I am using. I am able to run this but when trying to swap slots in Azure it freezes then crashes with a vague error message:
# Azure Login
az login
# Set deployment Environment
$environment = "stage"
# Resource Group Variables
$subscriptionId = ""
$domain = "test4"
$resourceGroup = "xx-platform-$domain-$environment"
$region = "northEurope"
# Functions app variables
$storageName = "xxfn$domain$environment" # must be less than 24 chars and all lower case
$functionAppDeploymentSlotName = "test"
$functionAppName = "xx-platform-$domain-fn-$environment"
$functionAppEnvironment = "AZURE_FUNCTIONS_ENVIRONMENT=Development"
$websiteRunFromPackage = "WEBSITE_RUN_FROM_PACKAGE=1"
#########################################################################################################################################################################
## Resource Group
Write-output "Creating resource group";
# Set subscription
az account set --subscription $subscriptionId
# Create resource group
az group create -l $region -n $resourceGroup
#########################################################################################################################################################################
## Functions App
Write-output "Creating Functions App";
# Create storage account
az storage account create --name $storageName --location $region --resource-group $resourceGroup --sku Standard_LRS
# Create functions app - using consumption plan
az functionapp create --name $functionAppName --storage-account $storageName --consumption-plan-location northEurope --resource-group $resourceGroup --functions-version 4
# Set functions app configuration settings
# Environment
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings $functionAppEnvironment
# WEBSITE_RUN_FROM_PACKAGE
az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroup --settings $websiteRunFromPackage
# SET DOT NET FRAMEWORK ERSION
az functionapp config set --net-framework-version v6.0 -g $resourceGroup -n $functionAppName
# Create functions app deployment slot
az functionapp deployment slot create --name $functionAppName --resource-group $resourceGroup --slot $functionAppDeploymentSlotName
I have modified your script in initializing the variable values directly to the cmdlets:
# Azure Login
az login
az account set --subscription "<Ur_Azure_Subscription_Id>"
# Function App Create
az functionapp create --name dt-platform-fn-stage --storage-account dtfnstageenvironment --consumption-plan-location northEurope --resource-group HariTestRG --runtime dotnet --functions-version 4
# Environment
az functionapp config appsettings set --name dt-platform-fn-stage --resource-group HariTestRG --settings AZURE_FUNCTIONS_ENVIRONMENT=Development
# WEBSITE_RUN_FROM_PACKAGE
az functionapp config appsettings set --name dt-platform-fn-stage --resource-group HariTestRG --settings WEBSITE_RUN_FROM_PACKAGE=1
# SET DOT NET FRAMEWORK ERSION
az functionapp config set --net-framework-version v6.0 -g HariTestRG -n dt-platform-fn-stage
# Create functions app deployment slot
az functionapp deployment slot create --name dt-platform-fn-stage --resource-group HariTestRG --slot test
Created the Http Trigger Function using the cmdlets given in the below given MS Document.
For Continuous deployments, this app setting needs to be configured:
az functionapp config appsettings set --name dt-platform-fn-stage --resource-group HariTestRG --settings "SCM_DO_BUILD_DURING_DEPLOYMENT=true"
Deployed the Function to the Azure Functions using az cli cmdlet given in one of my workarounds.
By default, Auto Swap on Slots will be disabled:
It is working fine during the slot swapping and make sure you have followed the considerations mentioned in this MS Doc that also provides the list of az cli cmdlets for managing the slots like creating, listing, deleting, swapping and auto swapping configuration.
Above Azure CLI Commands have been taken from this MS Doc references.

Creating vm using azure cli

I'm learning azure for 2 weeks now, I'm curious about creating vm on the cli. For example if I want to create a vm in a region with a specific size using cli, but it turns out that the size isn't available so I want the script to auto select another size with the same specs that I chose in the first place but I don't know how. This is my script now:
az group create --name TestingVM --location eastus
az vm create \
--resource-group TestingVM \
--name TestingVM \
--image Debian \
--admin-username aloha \
--size Standard_F8s_v2 \
--location eastus \
--admin-password *somepassword*
thanks!

Best way to deploy code and restore database in a managed Application on Azure MarketPlace

Our goal is publishing our offer to Azure MarketPlace. We created an ARM template for our infrastructure and had no issues with that.
Our main issue is how to deploy our code and DB schema through the purchase process.
Microsoft recommends Deployment Scripts so we made ours which contains, CLI commands to restore a .BACPAC sql file, app settings configurations and a CURL command for zip deployment via KUDU for the web application.
.BACPAC and zip package for code are in blob storage.
If we run our scripts in a custom ARM template deployment in Azure, they work fine !!
But when we run them through the marketplace purchase, they fail with no error logs.
Down below you can find our script commands.
"scriptContent": "
az sql db import -s $sqlserver -n $sqldatabase -g $rg -p $sqlpassword -u $sqlusername --storage-key $sqlstoragekey --storage-key-type $storagekeytype --storage-uri $storageuri \r\n
az webapp deployment user set --user-name $deploymentUser --password $deploymentPass \r\n
az webapp config connection-string set --name $applicationName --resource-group $rg --settings DefaultConnection=\"Server=tcp:$sqlserver.database.windows.net,1433;Initial Catalog=$sqldatabase;Persist Security Info=False;User ID=$sqlusername;Password=$sqlpassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;\" --connection-string-type SQLAzure \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings PortalUrl=\https://$applicationName.azurewebsites.net/\ \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:Domain=\"$AADDomain\" \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:ClientId=\"$AADClientId\" \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:TenantId=\"$AADTenantId\" \r\n
az webapp config appsettings set --name $applicationName --resource-group $rg --settings AzureAd:ClientSecret=\"$AADClientSecret\" \r\n
az webapp restart --name $applicationName --resource-group $rg \r\n
curl -X PUT -u $deploymentUser:$deploymentPass https://$applicationName.scm.azurewebsites.net/api/zipdeploy -H \"Content-Type: application/json\" -d \"{'packageUri':'$applicationUri$applicationStorageKey'}\" \r\n
",
In case our approach is wrong, any example, documentation and suggestions will be super helpful.
Feel free to ask for more information if any.
Thank you

Unable to add spot node pool to Azure Kubernetes Cluster

Unable to add spot node pool to Azure Kubernetes Cluster
AWS-CLI
azure-cli 2.12.0
core 2.12.0
telemetry 1.0.6
Extensions:
aks-preview 0.4.63
Following the instructions on Microsoft site: https://learn.microsoft.com/en-us/azure/aks/spot-node-pool
Ran the following
# Create a resource group in East US
az group create --name myResourceGroup --location westus2
# Create a basic single-node AKS cluster
az aks create \
--resource-group myResourceGroup \
--name myAKSCluster \
--vm-set-type VirtualMachineScaleSets \
--node-count 1 \
--generate-ssh-keys \
--load-balancer-sku standard
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
az aks nodepool add \
--resource-group myResourceGroup \
--cluster-name myAKSCluster \
--name spotnodepool \
--priority Spot \
--spot-max-price -1 \
--eviction-policy Delete \
--node-vm-size Standard_D2as_v4 \
--node-count 1
Got the following error:
Error code:
ValidationError: Operation failed with status: 'Bad Request'. Details: Provisioning of resource(s) for Agent Pool spotnodepool failed. Error: {
"code": "InvalidTemplateDeployment",
"message": "The template deployment failed with error: 'The resource with id: '/subscriptions/REDACTED/resourceGroups/MC_myResourceGroup_myAKSCluster_westus2/providers/Microsoft.Compute/virtualMachineScaleSets/aks-REDACTED-vmss' failed validation with message: 'The requested size for resource '/subscriptions/REDACTED/resourceGroups/MC_myResourceGroup_myAKSCluster_westus2/providers/Microsoft.Compute/virtualMachineScaleSets/aks-REDACTED-vmss' is currently not available in location 'westus2' zones '' for subscription 'REDACTED'. Please try another size or deploy to a different location or zones. See https://aka.ms/azureskunotavailable for details.'.'."
}
I have tried other AZ region, useast, uswest2, etc but with no luck
If I run the following it will work:
az aks nodepool add \
--resource-group myResourceGroup \
--cluster-name myAKSCluster \
--name mynodepool \
--node-count 1
Is spot node pool not supported? It is in the official docs: https://learn.microsoft.com/en-us/cli/azure/ext/aks-preview/aks/nodepool?view=azure-cli-latest
I just realised that this is not a AKS or Spot issue. This is a subscription issue.
In the docs (https://learn.microsoft.com/en-us/azure/virtual-machines/spot-vms#limitations) it says that only Pay-As-You-Go subscription are allowed to use spot instances. I just recently upgraded to Pay-As-You-Go model but my offerID is still stuck as "Free Trial" - I just need to be patient for it to change over

Unable to deploy Azure Function with Premium Service Plan

When I try to create a FunctionApp Premium Plan using the following commands:
# Create a Resource Group
az group create \
--name $rg_name \
--location $az_loc
# Create a Function App Storage Account
az storage account create \
--name $fa_storage_name \
--resource-group $rg_name \
--location $az_loc \
--sku Standard_LRS
# Create a Premium plan
az functionapp plan create \
--name $fap_name \
--resource-group $rg_name \
--location $az_loc \
--sku P2v2
I receive an error:
The requested app service plan cannot be created in the current
resource group because it is hosting Linux apps. Please choose a
different resource group or create a new one.
I also tried the sku EP2 with same result. The SKU's are really hard to find in the docs(!). Does anyone know which sku's work with Linux Azure Functions and what I might be missing here?
This is common error.
The solution is to create a new Resourse Group and put the function app in.
The problem comes from the conflict between azure function plan based on windows and based on linux.
Create a new Resource group is the only way, and notice to separate function based on linux and windows in your development.
Here is what ended up working for me. Note the --is-linux true flag in az functionapp plan create and the --plan flag in az functionapp create:
# Create a Premium plan
az functionapp plan create \
--name $fap_name \
--is-linux true \
--resource-group $rg_name \
--location $az_loc \
--sku EP2
# Create Function App (container for Azure Function)
#--consumption-plan-location $az_loc \
az functionapp create \
--name $fa_name \
--resource-group $rg_name \
--storage-account $fa_storage_name \
--plan $fap_name \
--os-type Linux \
--runtime python \
--runtime-version 3.7 \
--subscription $az_sub \
--functions-version 2
There is a current limitation where Windows and Linux apps cannot exist in the same resource group.
https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#limitations
Therefore, it was failing when deploying a Windows resource and worked when --is-linux was set to true

Resources