Remove-AzDeployment does not remove the resources created - azure

I am creating a StorageAccount & Containers using ARM script
I use New-AzDeployment to create the resources. The resources are created properly. I want to remove the deployment
When I run Remove-AzDeployment -Name ; the deployment is removed, however the resources are not deleted.
How do I ensure that the resources are also deleted. I am using the new Az Module in powershell instead of the old Azure Module

The Remove-AzDeployment cmdlet is used to remove a deployment from the deployment history. It won't remove resources deployed in this particular deployment.
You can remove resources from the resource group using Remove-AzResource, like this:
Get-AzResource -ResourceGroupName $ResourceGroupName | Remove-AzResource -Force

Related

Manage Microsoft.ClassicCompute/domainNames with Az PowerShell module

I have a classic Compute resource. I need to move some old deployment code that used Azure.Service module to Az and I was wondering, is there a way to manage that with Az or something up to date?
I have to upload some .cspkg and some .cscfg files. There is more to it, but basically, this was done using this cmdlet and the related ones, Set, Get etc.
I used Az.Resources' cmdlet New-AzResource to create it:
New-AzResource `
-Location 'location' `
-ResourceGroupName 'rgName' `
-ResourceType 'Microsoft.ClassicCompute/domainNames' `
-ResourceName 'rName' `
-ApiVersion '2018-06-01'
What cmdlets could I use to manage this resource?
In your case, you could use Az.CloudService module commands, to upload some .cspkg and some .cscfg files, use New-AzCloudService with parameters -PackageUrl and -ConfigurationUrl(or -Configuration).
The command New-AzCloudService can Create or update a cloud service, i.e. New, Set operations, to do Get operation, use Get-AzCloudService command.
Anyway, see here for all the commands to manage Microsoft.ClassicCompute/domainNames i.e. Cloud service, use them depends on your requirement.
Update:
In this case, looks you could not migrate your commands to Az module, Az.CloudService is for the new Cloud Service(extended support) which is ARM(Azure Resource Manager) based, and it is in the preview version, see Deploy a Cloud Service (extended support) using Azure PowerShell, some features might not be supported, I think the error was caused by this.
What you are using is Cloud Service(classic), it is ASM(Azure Service Management) based, the new Az module is just for ARM resources.
So in your case, you may need to continue to use Azure.Service module, or you can migrate the ASM to ARM i.e. Cloud Service(classic) to Cloud Service(extended support), see Migration to Azure Resource Manager, but not recommend you to use it in the production environment as it is in preview.

IS there a way to Extract function app name from arm template file of CI Build during deplopyment to azure (CD) process

In azure devops CI pipelines i am deploying arm template for resource creation .In the release process how do i extract the resources created names from artifact so that i can refer to correct resource for deployment on azure
You could leverage the outputs section of an ARM template for this.
These values are recorded in the deployment created which you could fetch, either using the Get-AzResourceGroupDeployment cmdlet or az group deployment show command as documented in this section.
Assuming that you use New-AzureRmResourceGroupDeployment cmdlet here is what I do to get the json output.
$jsonOutput = New-AzureRmResourceGroupDeployment -Name $DeploymentName `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFileToDeploy `
-TemplateParameterObject $TemplateParameters `
-Force -Verbose `
-ErrorVariable ErrorMessages -DeploymentDebugLogLevel
Thereafter, I use either the $jsonOuput.Outputs which contain template outputs or the $jsonOutput.Parameters which in my case contains the resource names and other stuff.

Why is Azure CLI reporting ResourceGroupNotFound when trying to run New-AzResourceGroupDeployment?

I'm trying to create an Application Insights resource following the directions provided here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/powershell
However, when I execute the command from the docs:
New-AzResourceGroupDeployment -ResourceGroupName Fabrikam -TemplateFile .\template1.json -appName myNewApp
Replacing Fabrikam my Resource Group Name, it throws ResourceGroupNotFound. If I list the Resource Groups with:
az group list
I can clearly see the Resource Group in the list, so I know I'm in the right subscription context.
Any thing obvious that I'm missing?
I've uploaded my version of template1.json already to the CLI storage.
I can clearly see the Resource Group in the list, so I know I'm in the right subscription context.
No, if you can use az group list to see the group, it just means the azure CLI context is in the right subscription. The New-AzResourceGroupDeployment is azure powershell, they are different, you need to use Get-AzResourceGroup to list groups.
To check if you are in the correct subscription, just use Get-AzContext. If you want to set the subscription for the powershell context, just use Set-AzContext -Subscription "<subscription-id>".
I've uploaded my version of template1.json already to the CLI storage.
I suppose you mean you upload the template to the azure storage. If so, you could not use this parameter -TemplateFile, you need to use -TemplateUri and -TemplateParameterUri, you need to generate the SAS urls for your template files(if your container is not public), then specify the two parameters, see this link.
Actually, you can use New-AzResource to create the app insight directly, no need to use the template in the doc.
Sample:
New-AzResource -ResourceName "<appinsight-name>" -ResourceGroupName <resourcegroup-name> -ResourceType "Microsoft.Insights/components" -Location "East US" -PropertyObject #{"Application_Type"="web"}

how to get the list of azure logic apps present in a particular azure resource group using azure powershell commands

Say for Suppose i have Logic App 1 ,Logic App 2 ,Logic App 3 etc got created in an Azure Resource Group X. Then Using Azure Powershell Command, I want to get this list of logic apps present under 'X' Azure Resource Group
You should try
Get-AzureRmResource -ResourceType "Microsoft.Logic/workflows" -ResourceGroupName resourcegroupname
It works fine on my side.
This PowerShell Core command should work; replace "myresourcegroup" with the name of the resource group you want to search. In Azure Cloud Shell you can access PowerShell Core by running pwsh.
Find-AzureRmResource -ResourceType "Microsoft.Logic/workflows" -ResourceGroupNameContains "myresourcegroup"

Conditionally deploy a resource in resource manager

I have an ARM template to deploy/update the full Azure infrastructure for my application.
Our build server should run the template, and add/update/delete resources that are add/changed/deleted. To make this work, I have chosen for the "Complete" deployment mode.
To test the ARM template, I have to following power shell script:
param(
$tenantId = "",
$subscriptionId = ""
)
Clear-Host
Login-AzureRmAccount -TenantId $tenantId -SubscriptionId $subscriptionId
New-AzureRmResourceGroupDeployment `
-Name "x" `
-ResourceGroupName "rg-test" `
-TemplateFile $PSScriptRoot/resource-template.json `
-TemplateParameterFile $PSScriptRoot/parameters-test.json `
-Mode Complete
This powershell script is only used to test the template, because a vsts release step will be responsible for the execution of the ARM template into the resource group.
We want to use 1 template to deploy everything (to keep it simple, just a Web Service plan and a web app service), but we have resources that doesn't need to be deployed in some environments. Different environments will use different pricing plans, and some of them will need a Deployment Slot, others won't (to save costs).
I have read about the nested templates, and at first it seemed to solve my problem... but it doesn't.
I cannot use the nested templates in a "Complete deployment".
Does anyone know another way, to flag if a resource needs to be deployed or not, is not the "nested-template"-approach and works for the full deployment type?
We could create different parameter files for different environments (dev, test, or production), and then we could customize the deployment by providing values that are tailored for a particular environment. Besides, as we know, we could use nested templates for conditional deployment, but only the root-level template is allowed Complete for the deployment mode. If you have to use Complete mode, you may need to write script to dynamically generate your templates for different environments based on your requirements and business logic.

Resources