How to export json template from azure app service - azure

Is it possible to export the JSON definition for an existing app service in Azure?
Ie this json object: https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites
The app service was created using the Azure Portal UI and I want to recreate it using the Azure CLI command line.

You could use az group export --name *** >test.json to capture a resource group as a template. Please refer to this link.
But currently resource type Microsoft.Web/sites does not support export, please refer to this feedback.
Note: If also could find the error log on Azure Portal.

Related

New Azure Resources Show Up in Portal but not CLI

After running a DevOps pipeline that created several resources, only two (a new resource group and a Functions app) show up in Azure CLI using az ... list --subscription ....
Other resources, like Static Web Apps and a SQL Server don't show up in that list or when running az staticwebapp list --subscription ... or az sql server list --subscription ... with the subscription argument specified. I have confirmed that these resources DO show up in the portal, and my account is listed as an owner (inherited from subscription) for them in the portal.
I have deployed Azure Static WebApp using Azure Devops.
Followed this MSDoc to publish the static web app.
By using,
az staticwebapp list --resource-group YourRGName
and
az staticwebapp list --subscription YourSubscriptionID
,Iam able to get the StaticWeb App list
For anyone else running into this:
I have not found a solution to getting the az staticwebapp list command to work for my use case, as the results that show up immediately after creating a resource are just inconsistent. However, as a workaround that should satisfy most use cases, using this API (using az rest command) to find all resources associated with the group created by the pipeline, then filtering those down to find the Static Web App I want, seems to work.
Then, when using other APIs that reference that app before it shows up in the normal list, fully specifying subscription and resource group alongside the app's name seems to make things more reliable too.
As far as I can tell, this is probably just a limitation with the inconsistency of how long information about newly deployed resources takes to propagate that shows up when trying to find a resource immediately after creating it.

Is there any option to script the export for an Azure Dashboard?

In Azure, you can create dashboards and export them using a button on the portal. However, there seems to be no option to export the ARM through an API/SDK/CLI. Am I wrong, or is this indeed a gap in the Dashboard experience?
You can also export the template of the resource group via Azure CLI, PowerShell, and the REST API.
Update:
You can see the description here like below:
Shared dashboards in Azure are resources just like virtual machines
and storage accounts. Therefore, they can be managed programmatically
via the Azure Resource Manager REST APIs, the Azure CLI, Azure
PowerShell commands, and many Azure portal features build on top of
these APIs to make resource management easier.
Actually, what you download in the Azure Dashboard with the button is not a resource, so you cannot export it with commands or API. What you need is to make the dashboard template as a resource, then you can use the commands(Azure CLI or PowerShell) and API to export it.
Here is the example in the portal as a resource:
Then use the Azure CLI command to export the template like this:
az group deployment export -g grouName -n templateName > dashboard.json

Is it possible to publish cloud service package using AZ powershell script?

I want to find out is it possible to deploy classic cloud service package (Microsoft.ClassicCompute) to Azure deployment slot with AZ powershell.
There is a classic service inside a resource group already created in Azure. A package that is going to be deployed is uploaded to a separate Storage Profile blob.
Currently, the webroles are deployed using REST API. An appropriate path to a package in the blob is specified in element of a post request and this works fine.
I am trying to do the same thing using AZ powershell, particulary, by calling New-AzResource cmdlet with '-PropertyObject' parameter specified like that:
#{
deploymentLabel = 'XXX';
configuration = '<?xml version=\"1.0\" encoding=\"utf-8\"?> .... ';
packageUrl = '{valid_url_to_package}';
....
}
but an error returns:
The request content was invalid and could not be deserialized: 'Could
not find member 'packageUrl' on object of type
'DeploymentSlotProperties'. Path 'properties.packageUrl'
If to remove 'packageUrl' property from the object and execute the cmdlet again an another error is shown up:
The deployment request is missing the package link.
Unfortunately, I cannot find any any information about format of '-PropertyObject' parameter. Or maybe there is a better way to deploy a package via AZ?
According to my research, Azure PowerShell Az module is used to manage Azure ARM resource. But Azure Cloud service is Classic resource. So we cannot deploy azure cloud service with az module. For more details, please refer to the document and issue. If you want to know to deploy Azure cloud service with PowerShell, please refer to https://github.com/MicrosoftDocs/azure-cloud-services-files/tree/master/Scripts/cloud-services-continuous-delivery

Add Application Insights to an azure function with Azure CLI

I have a PowerShell script which creates an azure function app on a consumption plan and its associated storage account within a resource group using the azure cli following the example In the Microsoft Docs
However to enable application insights I have to go to the azure portal, find the func select monitor and click enable application insights.
How can I expand that script to enable automate this step for the newly created function? I have been unable to find any specific documentation or examples and I would prefer to avoid resource templates if possible.
OF course, you could enable Application Insights to the azure function by Azure CLI.
But you need to create the Application Insights in the portal first, currently, it is unable to create Application Insights via Azure CLI.
You could follow the steps below.
1.Go to your Application Insights in the portal, copy the Instrumentation Key in the screenshot.
2.After creating the function app by your command , just use the CLI command below.
az functionapp config appsettings set --name <functionname> --resource-group <resourcegroupname> --settings 'APPINSIGHTS_INSTRUMENTATIONKEY = <Instrumentation Key>'
It works fine on my side, you could check it in the portal.

Unable to create storage for persisting account files in Azure Cloud Shell (CLI)

I'm trying to setup Azure CLI. The first step is to create a storage for account files. I'm using my Developer Program Benefit subscription.
After I click "Create storage" I get an error:
Storage creation failed
Error:409
{"error":{"code":"MissingSubscriptionRegistration","message":"The subscription is not registered to use namespace 'Microsoft.Storage'. See https://aka.ms/rps-not-found for how to register subscriptions."}}
Can't create a storage account. Please try again.
How to resolve this issue?
The reason you're getting this error is because Microsoft.Storage resource provider which manages Storage Account related resources and activities is not registered with your Azure Subscription.
To fix this, please run the following command:
azure provider register --namespace "Microsoft.Storage" --subscription "<your subscription name or id>"
To get the subscription name/id, please run the following command:
azure account list
For more details on why you're getting this error, please see this: The subscription is not registered to use namespace 'Microsoft.DataFactory error
If you prefer GUI, then you can do it on the Azure portal too:
On the left pane click More services and then select Subscriptions
Select the subscription, in our case Developer Program Benefit
In the Settings area click Resource providers
Find Microsoft.Storage and click Register
This same error with detailed solutions are provided in this post:
How to fix Azure Cloud Shell error "MissingSubscriptionRegistration - The subscription is not registered to use namespace 'Microsoft.Storage'"

Resources