Delete azure resource by service type - azure

I want to delete azure resource by service or group type. ( for example delete resource related to Virtual Machine, App Service with Application Insights or Storage etc.)
Planning to build the tool using C# or Power shell script. Please provide recommended reusable approach.

this is too generic. there can be none, best you can do is do filtering based on the resource type (so delete all of the resources of the same type, you can add resource group\tag as a filter). But in essence this is not possible. you would have to create a database where you store relationships between different resources and resource types.
Also, how do you solve conflicts? If you delete 1 thing and another thing depends on it? what if its not a hard dependency? etc.

Related

Is there a way to automatically retreive Azure Resource Naming restriction

I'm working on a method/program that will automatically name resources according to restrictions and recommended abbrevation.
At the moment I add the restrictions in a table but it's alot of labor and annoying to maintain. Are there an API I'm missing that would allow me to retreive naming restrictions for resources in Azure?
Currently I'm using below docs:
Naming rules and restrictions for Azure resources
Recommended abbreviations for Azure resource types
Adding as an answer from our comment discussion, We don't have any REST API to pull the resource naming restriction and recommended abbreviations.
Alternatively,You can use this Azure naming tool and also you can run this as a standalone container on your local machine that is running with docker or deploy it on azure app service container as well.
Thanks to VenkateshDodda-MSFT:s comment i managed to find this file:
AzNamingTool/repository/resourcetypes.json
This contains what I was searching for. All the rules in one file that I can use to build my logic around.
Thanks!

Are my Function Apps dependent on Storage Accounts? I want to move my Function Apps to a new Resource Group

Goal: Move all the necessary, and only the necessary, function apps and their dependencies from one resource group to another. This resource group they are currently in contains an App Configuration, 2 App Services (Function Apps), their Application Insights, a Storage account, and an App Service Plan.
The resource group I want to move them into already has things like Storage accounts, other Function apps, Logic apps, etc.
I have tried consulting the docs, maybe I am consulting the wrong ones. I am still puzzled about the dependencies Function Apps may have, and why this resource group needed to spin up a Storage account and what azure-webjobs-host and what the files populating within it mean or do.
Q1: How can I move them to the new resource group? I am thinking of using their ARM templates, but am vague on details.
Q2: Do I need to bring their Storage account with them?
Q3: Could I instead integrate them with the Storage account in their new resource group, after I moved them? How?
Q4: Can I simply delete Function Apps' Application Insights if I have no further use for them?
Q5: Any good resources or knowledge you want to share about Logic Apps / Function Apps being dependent on other resource types?
Thank you.
Are my Function Apps dependent on Storage Accounts?
Yes, function app on azure needs you to specified a storage account. This is because triggers other than httptrigger needs storage emulator.(This is built-in feature.)
How can I move them to the new resource group?
If you dont have too many function apps to move, just click 'Move' -> 'Move to another resource group' in the overview of your resource group and then select the function app you want to move.
Do I need to bring their Storage account with them?
No. No matter built-in feature or your function app need to deal with some storage accounts, it just needs you to offer connection string to link to.
Could I instead integrate them with the Storage account in their new
resource group, after I moved them? How?
Yes.(If you are talking about built-in feature.) But you need to change this value:
And the value is getting from this place:
Can I simply delete Function Apps' Application Insights if I have no
further use for them?
Yes, you can. It is just a way to monitor your function app. You can delete or re-create it whenever you want.
Any good resources or knowledge you want to share about Logic Apps /
Function Apps being dependent on other resource types?
One thing I want to remind. Please keep your resources in the same region if you dont have some special requirement. This is not only because of some built-in restrictions, but it can also help you save costs. (For resources in Azure, data transmission between resources located in different regions requires additional bandwidth fees.)

What is similar to Azure "Resource Group" in Oracle Cloud infrastructure?

I'm fairly new to OCI.
What is a similar or close concept in Oracle Cloud Infrastructure similar to Microsoft Azure "Resource Groups"?
In Azure when a resource group is deleted all resources in that group will also be deleted along with it. But "Compartments" in Oracle cloud infrastructure is not the exact same concept, because in order to delete a compartment, each resource should be deleted first and then the compartment should be deleted. Is it possible to delete a compartment along with its resources without deleting resources one by one?
I see two options here:
You may use instance pools. Deleting an instance pool will delete all
of its resources, but that only includes instances, boot volumes and
block volumes. Networking and other resources wouldn't be impacted. Instance Pool only works for compute instances having the same configuration, so this is not a generic solution for your question.
Resource Manager can be used to create a stack with all the resources
you need. When you destroy a stack by launching a destroy job, it will delete all the resources that are part of the stack. But resource manager requires you to
create Terraform config files, which can be applied through the OCI
Console. This also means that you cannot create any components of the stack
manually using the GUI, you have to keep using the Resource Manager even if you would like to update any resources of the stack.
Compartments in Oracle Cloud Infrastructure is similar to Azure Resource groups.
As per the doc, It is not possible to delete all the resources in compartment at a time similar to Azure.

multi-region deployment in Azure using ARM

I am performing multi-region deployment in Azure using ARM. The only approach I could find so far is by using copy operation as explained here
However, in the beginning of the post author wrote that some of you might think that it’s not such great idea, and I can appreciate that.
Why is that? What could be alternative to copy function? What is ‘official’ recommendation from MSFT to implement multi-region deployment in ARM?
I don't know of a single best practice recommendation here but there are a few other things you can think about for the scenario. If you think of a resource group as a management boundary, then having everything in the same resource group may not be ideal. For example if you wanted to tear down one region and rebuild it, this is much more complicated within a single resource group. If you wanted to simply add a new region, while you could do this with the same template and an incremental deployment, it's faster and maybe cleaner in a separate deployment. If you wanted to assign permissions based on region, again more complicated.
OTOH, if you deploy each region into it's own resource group, this becomes much easier to manage. The only difference is then that the copy loops aren't needed in the template and you do multiple deployments of the same template (to each region).
Again, no hard/fast rule, but some ways to think about it...

Why are Azure Resource Groups associated with a specific region?

I'm new to Azure architecture and am trying to understand why Azure Resource Groups, which are logical deployment buckets for applications built on Azure, are associated with a region when they are defined.
At first I thought it was to provide global distribution for disaster recovery or geographic redundancy, but then I realized that a single Resource Group can contain web apps in different regions, which can provide those features via Traffic Manager. I suppose that using separate Resource Groups would help better identify which resources are in which region, but other than for organizational purposes, I can't understand what the region definition for Resource Groups implies.
(edit: removed general advice query to be more focused)
The main reason for specifying the location of a resource group is to specify a location for data/metadata for the deployment to be stored in... It also makes the API consistent (think of the paths in REST API calls) but the primary reason is storage during deployment.
The location of the resources in the group is independent/not related to the location of the group itself.
When creating a resource group, you need to provide a location for that resource group. You may be wondering, "Why does a resource group need a location? And, if the resources can have different locations than the resource group, why does the resource group location matter at all?" The resource group stores metadata about the resources. Therefore, when you specify a location for the resource group, you are specifying where that metadata is stored. For compliance reasons, you may need to ensure that your data is stored in a particular region.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview
The meta data (definition) of the Azure resource group needs to be stored somewhere. hence the location. However, resources inside a resource group are location independent and can be placed in a different region\location.
Do note that dependencies between resources can exist. A Virtual machine in West Europe obviously needs a storage account in West Europe as well, but a SQL database in the same resource group can exist in West US.
Resource groups are basically for you to decide which resources in your application you want to manage together and by manage I mean you want to deploy, manage, and monitor them as a group so at a high level you do not see them as separate components.
In general in a big ecosystem, Azure resource groups are the ones that you do not see those components(resources) in them as separate entities, instead you see them as related and interdependent parts of a single entity so you put them in one Resource Group so that using the Azure Resource Group Manager tool You can deploy, update or delete all of the resources for your application in a single, coordinated operation.
You use a template for deployment and that template can work for different environments such as testing, staging and production. You can clarify billing for your organization by viewing the rolled-up costs for the entire group.
You can find more details on Azure Resource Manager here which I believe will help you better understand the idea behind the Azure Resource Groups:
https://azure.microsoft.com/en-us/documentation/articles/resource-group-overview/
Everything in Azure relates to a physical location/Datacenter, and ARM is no different. A little while ago, not every Datacenter supported ARM, so the reason for choosing made even more sense. Now, like any other Azure resource, the decision is for the user to make, often based on their required proximity to the end user and/or legal geographic requirements.
It appears there is no obvious way to determine what region a resource group is in after it has been created. This has caused me grief per the discussion here, when I ran into problems with CDN metadata conflicts. I had to start over. Now I name my resource groups with the region. e.g.: my-resourcegroup-westus

Resources