CONTEXT
Whe deploy an Azure Function with a vnet integration with a code like this:
$properties = #{
subnetResourceId = $subnet.Id
}
$vNetParams = #{
ResourceName = "$webapp/VirtualNetwork"
Location = $Location
ResourceGroupName = $ResourceGroupName
ResourceType = "Microsoft.Web/sites/networkConfig"
PropertyObject = $properties
}
$result = New-AzResource #vNetParams -Force
This works fine.
The project get $subnet by looking an available subnet into a spoke VNET.
So I don't want to run the previous code when a VNET integration already exists.
WHAT I NEED
A way to know if a Function has already a VNET integration
WHAT I TESTED
Get-AzFunctionApp -ResourceGroupName $ResourceGroupName -Name $webapp
Get-AzFunctionAppPlan -ResourceGroupName $ResourceGroupName -Name $servicePlan
Get-AzAppServicePlan -ResourceGroupName $ResourceGroupName -Name $servicePlan
Returns no vnet informations
Get-AzResource doesn't work with this resource: "$webapp/VirtualNetwork" (not found)
To check if a function app has already a vnet integration, just use the command below.
$VnetName = (Get-AzFunctionApp -ResourceGroupName <groupname> -Name <functionappname>).SiteConfig.VnetName
if($VnetName){
Write-Output "already intergration"
}
There is a way to figure this in portal.
Navigate to Azure portal
Select the corresponding Web App or Function App
Navigate to "Diagnose and solve problems" and search for "VNet Integration Information"
This will load a blade, which will have details of the Web App in that App Service Plan
This is what the UI looks like
Related
I'm tring to find a way how to get APIs stored on Azure in Microsoft.ApiManagement/service
I have tried different endpoints but none gave mi API with tags. Is there a way to do so?
Thank You!
Below are the PowerShell cmdlets for getting the list of APIs registered in an APIM Instance along with their individual API tags:
$ResourceGroupName = "resource_group_name"
$APImg = "APIM_Instance_Name"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $APImg
$Apis = Get-AzApiManagementApi -Context $ApiMgmtContext
foreach($Api in $Apis){
$ApiId = $Api.ApiId
$ApiName = $Api.Name
$tags = (Get-AzResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.ApiManagement/service/apis/tags -ResourceName "$APImg/$ApiId" -ApiVersion 2018-01-01).Name
Write-Host "Tags of" $ApiName : $tags
}
Result:
To get the list of APIs along with their tags using the REST API, below is the syntax:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apisByTags?api-version=2021-08-01
Thanks to Microsoft Docs as they provided the sample response how it lists the APIs along with their tags for the above cmdlet:
Refer to the Azure API Management Rest APIs for more information.
I am trying to leverage the Variable Group functionality in Azure DevOps.
I have created the variable group within the Release pipeline and I have associated. However, when I release the code to the Function App in Azure; when I go to the Configuration settings in the Function app, the custom settings are not there.
Is there a step I am missing here on getting these to show up?
UPDATE: To fix this; I needed to write the variables. This is the step I did it.
I usually do this using a powershell task after publishing the new code. So add a new powershell task and define it as inline:
$appname = "name of your function app"
$rg = "name of resource group"
$webApp = Get-AzureRmwebApp -ResourceGroupName $rg -Name $appname
$webAppSettings = $webApp.SiteConfig.AppSettings
$hash = #{}
foreach ($setting in $webAppSettings) {
$hash[$setting.Name] = $setting.Value
}
$hash['New name'] = $("pipelineVariable")
Set-AzureRMWebAppSlot -ResourceGroupName $rg -Name $appname -AppSettings $hash -Slot production
PS: define the deployment slot as a variable too
In AWS we have instance IDs to identify machines. What's the equivalent in Azure and how do I find that?
I'd like to list the instance ID in powershell so I can put that into a script.
If I have not misunderstood, I suppose you want to get the InstanceId of the VM in the Azure VM Scale set.
You could try to use Get-AzureRmVmssVM to get it.
Get-AzureRmVmssVM -ResourceGroupName <ResourceGroupName> -VMScaleSetName <VMScaleSetName>
Update:
If you want to get the ResourceId of azure resource, you could use Get-AzureRmResource to do it, just specify the properties what you want.
For example:
1.Get ResourceId of the specific resource:
$resource = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType <ResourceType> -ResourceName <ResourceName>
$resource.ResourceId
2.Get ResourceIds of all resources in the specific resource group
$resource = Get-AzureRmResource -ResourceGroupName <ResourceGroupName>
$resource.ResourceId
3.Get ResourceIds of all resources under your subscription.
$resource = Get-AzureRmResource
$resource.ResourceId
The result will like(actual result will decided by your properties):
I am running Powershell 5 and trying to manipulate my Azure WebApp object using Set-AzureRmWebApp (and NOT Set-AzureResource) to set the "Always On" property of the web app.
My basic code snippet starts with a running web app named "myWebApp", and looks like this:
$name = "myWebApp"
$resourceGroupName = "myResourceGroup"
$app_settings = #{"WEBSITE_LOAD_CERTIFICATES"="*";"CommonDatabase"="Common";"WEBSITE_NODE_DEFAULT_VERSION"="0.10.32"}
$result1 = Set-AzureRmWebApp -ResourceGroupName $resourceGroupName -AppSettings $app_settings -Name $name
$result2 = Set-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $this.name -PropertyObject $propertiesObject -ApiVersion 2015-08-01 -Force
The first Set-AzureRmWebApp statement works. It sets all the variables in $app_settings, and they become visible in the Azure Portal blade for myWebApp.
I tried using "Always On"= on as a property in $app_settings with Set-AzureRmWebApp, and it appeared in the App Settings sub-list in the properties of "myWebApp" on the Azure portal blade, but the actual property "Always On" in the general settings remained off.
I read on another site that using Set-AzureRmResource would work, so I tried it, but it failed.
What do I need to do in Powershell to set a property in the General Settings of my Azure WebApp, specifically "Always On"?
"Always On" is not supported if WebApp is in a free Service Plan tier. If the WebApp is in a free tier, please scale up the App Service Plan. Please refer to the document for more info about how to scale up the App Service Plan.Please have a try to use the solution that sharbag mentioned. It is worked for me and I also check the run result from the azure portal. Snipped code from the solution is as followings:
$ResourceGroupName = 'Your Group Name'
$WebAppName = 'Your WebApp Name'
$WebAppPropertiesObject = #{"siteConfig" = #{"AlwaysOn" = $true}}
$WebAppResourceType = 'microsoft.web/sites'
$webAppResource = Get-AzureRmResource -ResourceType $WebAppResourceType -ResourceGroupName $ResourceGroupName -ResourceName $WebAppName
$webAppResource | Set-AzureRmResource -PropertyObject $WebAppPropertiesObject -Force
If the WebApp in a free tier service plan, when we try to run the PowerShell command to enable "Always On" then we will get the following error message.
I can use the azure portal to add a web app to a virtual network for communications between various services hosted on it. However I have everything else in the environment scripted via Powershell and would like to automate the WebApp/VNET integration too.
I have read the following article so far:
https://azure.microsoft.com/en-gb/documentation/articles/web-sites-integrate-with-vnet/
However that is just how to do it via the portal. I am thinking that the Set-AzureRMWebApp cmdlet is the right thing to use, but i can't see any parameters that might help.
https://msdn.microsoft.com/en-us/library/mt652487.aspx
I had the same issue and couldn't find a way to do this using a PS modules. However functionality has now been added to azure CLI. So you can just involke this from a script.
az webapp vnet-integration add -g "resource group name" -n "app service name" --vnet "vnet name" --subnet "subnet name"
First you need an existing VNet with P2S configured as per my post at http://www.techdiction.com/2016/01/12/creating-a-point-to-site-vpn-connection-on-an-azure-resource-manager-virtual-network/
Then use the below PowerShell to connect the AppService to the VNet using P2S VPN:
$subscription_id = "<Subscription_ID>"
$NetworkName = "<Network_Name>"
$location = "<Region>"
$netrgname = "<Resource_Group_VNet_is_in>"
$AppServiceName = "<AppService_Name>"
$props = #{
"vnetResourceId" = "/subscriptions/$subscription_id/resourcegroups/$netrgname/providers/Microsoft.ClassicNetwork/virtualNetworks/$NetworkName";
"certThumbprint"= "<Client_cert_thumbprint>";
"certBlob"= "<Base64_Cert_Data>";
"routes" = $null;
}
New-AzureRMResource -ResourceName "$AppServiceName/$AppServiceName-to-$NetworkName" -Location $location -ResourceGroupName MarcusWebsites -ResourceType Microsoft.Web/sites/virtualNetworkConnections -PropertyObject $props -ApiVersion "2015-08-01" -force
You can configure custom routes if you require by modifying the routes property. Let me know how you get on and if it resolves the situation please mark this post as the answer.
Marcus
This is currently not supported, we have it on our to-do list, unfortunately I don't have an eta right now