Referencing template in Azure Templates - azure

I have an ARM Template stored in Azure Templates.
Is there a way to reference this template from script (either in Azure Cloud Shell or PowerShell/CLI on local machine)? Right now it seems the only way to deploy the template is through the Azure portal UI.
Update
I wanted to clarify what I am asking. I am asking specifically about Azure Templates (Preview) service. It seems that once you store a template in Templates service the only way to access it is through the Azure portal.
For example, let's say I am creating a VM in Azure portal. I can save the ARM template to Templates service as shown in the images below.
You can click on Download Template and parameters link, on next page click on Add to library to save the template to Templates service (Templates service can be found in Azure portal through All Service > filter for "Templates").
I was doing the course on edX.org: Automating Azure Workloads and it was talking about this service, that's why I became interested in this service.

You can deploy a template with every possible mean you mention. Not only the portal UI.
There is documentation here - section Deploy a template from external reosurce (also explains how to deploy from a private resource using SAS:
New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup `
-TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json `
-storageAccountType Standard_GRS
The referenced documentation also provides sample for use with Cloud Shell.

Related

AppService access restrictions and access from Release Pipelines

As part of my deployment I would like to call some endpoint in my application to smoke test it.
But we are using Access Restrictions and calls from Azure Devops Release Pipeline are rejected.
Is there a way around this?
Right after asking question I noticed there is new option in Preview in Access Restrictions page in Azure portal.
With this rule Azure Devops will be able to reach application endpoints.
Or using Powershell
Add-AzWebAppAccessRestrictionRule
-ResourceGroupName "resourcegroup"
-WebAppName "webapi"
-Priority 65000
-ServiceTag Azurecloud
-Action Allow
In future you should be able to use AzureDevOps service tag, but looks like it's not supported in Preview - Set a service tag-based rule (preview)

Azure: figure out if resource was deployed manually or via arm template

Is there a way to figure out if resource was deployed manually (via Azure portal) or via arm template?
I would say that your best option, although it won't guarantee 100% accuracy, is to look at the deployment name. If you look at a Resource Group from the Azure Portal and navigate to Deployments, you'll see a list of all deployments to that RG.
From my observations:
if the deployment name is in the format Resource.Provider-Timestamp (Microsoft.RouteTable-20200824154745) it was done via the Portal
if the deployment name is somewhat friendly or irregular (VirtualWanDeployment) it was a manual ARM template deployment (PowerShell in my case)
if the deployment name is in the format resource-date-time-xxxx (applicationGateway-20200821-135645-bf71) it was an Azure DevOps pipeline

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

New deployment slot for azure websites

Is there a REST API call to create a new deployment slot in Azure website?
I am not able to find anything here.
You can do this using the Azure PowerShell cmdlets. For example, I tested this with a site named "cloudallocweb" in East US and then used the following command to create a new deployment slot in the cloudallocweb site.
New-AzureWebsite -Name "cloudallocweb" -Location "East US" -Slot "test"
Peeking into what the New-AzureWebsite cmdlet is doing in the command above, I found this POST operation which is basically the Create a web site REST API. Notice that it is passing the WebSpace setting (matching in the URL), which I don't see documented in the REST API.
At any rate, it appears the Create a Web Site REST API is what you need. This makes sense considering that a deployment slot is really just a web site. You may also take a look at the List Webspaces API to find the right web space value for your site.
Following the steps above, the new deployment slot will appear under the original site as shown here. You can then swap the deployment slots using the portal, REST API, or the Switch-AzureWebsiteSlot cmdlet.

Resources