Azure API manager using terraform - azure

I am new to Terraform and was wondering if we can use Terraform to implement a kind of disaster recovery for Azure API manager.
I know there is disaster recovery implementation by Microsoft for API manager but I wanted to explore if I can just recreate the whole thing using Terraform.
I am able to recreate the API manager using Terraform with the same configuration/APIs etc.
The only thing which is unclear to me how to back up and recreate the same subscriptions/products in API manager using Terraform.
For example, if someone deletes the API manager, I want to recreate it using Terraform and import all the existing products/subscriptions (keys).
Any ideas?

Similar to using ARM Templates, you can use Terraform to deploy Azure APIM as well. You refer the azurerm provider docs for more information.
But for all runtime data like users & subscriptions, you will have to consider setting up a backup/restore system utilizing the built-in feature.
After deploying APIM using terraform, you will have to restore the runtime data separately. Also, depending on your Recovery Time Objective, you will have to take frequent backups.
PS: Logic Apps are a great way to setup automatic backups. There is an official sample that you can refer to for this.

Related

Is there a maximum limit on Workspaces in a Terraform Cloud Organization?

I am building a small server-less application on aws. It is a SaaS for business purposes so I am looking at ways to cater for multi-tenancy.
So far my proof-of-concepts have been single tenant and deployed via terraform.
I am thinking of using the Terraform Cloud Workspace API to create a workspace for each tenant on sign up. The work spaces would be configured to auto-apply from my production github branch.
I'm concerned that this isn't the intended usage of Terraform Cloud and that I may run into issues as the application scales.
Does anyone have any insight into the upper-limits of Terraform Cloud? I have read through some of Hashicorp's documentation but I can't find anything specific to this.

Is there a way to get Azure CLI creation commands that match existing resources?

I'm looking for a way to automatically generate new instances of my manually created Azure resources. The resources already exist and destroying everything + rebuilding with an IaC framework is not an option at this stage. The existing infrastructure is rather simple (a few VMs, networks, network interfaces, disks, etc), nothing too fancy, and should serve as a blueprint for future deployments. I'd be happy with either generating a list of CLI commands that lead to the desired infrastructure or generating code for the Azure Resource Manager for the same purpose. I heard there are native tools to achieve this but could not find anything.
Is there a way to achieve this or do I have to go the error-prone way of manually writing the code, hoping I don't have any mismatch between the configuration of my coded infrastructure and my current infrastructure?
you can use Azure Portal to export the templates and check see if you ready to use Bicep - decompile to refactor variables/parameters practices, and use it as blueprint repository for future deployments (e.g starter- templates etc etc)

What features in Azure services cannot be scripted in Terraform or require embedding ARM in Terraform?

When working with Terraform, what features of Azure services are there that cannot be scripted in Terraform or require embedding ARM?
Currently, there is no resource to create Data Sync Group in Azure using Terraform
An ARM template configures the Azure PaaS resources to send their diagnostic data to Log Analytics. There is no functionality for this in Terraform when used with Azure
There is a zone to zone disaster recovery for Azure VM but terraform only provides single instance and target availability set in the azure site recovery
Almost all the new features added in Azure cannot be created using Terraform
The landscape for both Azure and Terraform is constantly changing, so it would not make much sense to list what is supported/not supported in a Stack Overflow context.
I have been working with Terraform in Azure for more than 5 years, and the AzureRM provider is being updated almost on a biweekly basis. In general, it is very much up to date - not only with new resources and data sources that are being added constantly but also updates on existing components functionality and when the Azure API changes. This provider rocks!
Take a look at the changelog here to get an overview of the intense activity on the AzureRM provider: https://github.com/hashicorp/terraform-provider-azurerm/blob/main/CHANGELOG.md
I believe that instead of asking what is not supported, take a look at the landscape you want to create, and see if the components exist in the documentation, which is very good IMO. I think that the latest AzureRM provider (2.91.0) has around 950+ resources and data sources.
Documentation: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Usually, when something does not exist there will be an issue in the Github repo. E.g. to follow the example that #RamaroAdapa-MT mentions, you can find the issue here (by a simple Google search):
https://github.com/hashicorp/terraform-provider-azurerm/issues/6425
Looking through that, you can see the the reason is actually not a Terraform AzureRM provider issue, but lack of support in the Azure API:
https://github.com/Azure/azure-rest-api-specs/issues/11061

How to update and redeploy ARM template

I am new to Azure as well as Devops, ARM template etc..I have deployed an ARM template for key valut with a name "ABC" via DevOPs. Now I would like to change some parameters. I don't have access to do it via portal and I am forced to use only ARM template. How can this be achieved via devops? Should I delete that resource and start from the scratch or any SOP to update resource parameters via ARM templates. For example I want to enable "“enabledForDeployment” for already deployed kay-vault. Thanks.
generally speaking you just re-run the same template with the changes you've introduced to the template. there are many ways of deploying the template (az cli, powershell, built-in steps, various sdk's).
just keep in mind, some properties are settable only at creation time, so effectively read only, you wouldn't be able to update those after the resource is created, some resource providers do not play well with idempotent behavior and this will also lead to issues when you try to redeploy the same template, some providers offer dodgy behavior when you need to use a completely different api call to update something compared to creating it.
So there's no single answer, but for what you are doing, just updating the template and running it again should work just fine.
You can do it through PowerShell,
Update a resource in an Azure Resource Manager template

Copy Azure Resources to client azure account

We are working on following within Azure portal
Azure Functions
Data Factory
Logic Apps
Storage account (not files)
Now as we are done with development, we need to deploy these azure resources in client's UAT environment
I looked around (might be missing something) and found that deployment of Azure resources is not straightforward.
In Azure, it is like another subscription, correct?
So found this blog, which works with different PowerShell scripts to copies from one subscription to another
This is the right approach? & it cover everything required for resources to execute flawless (I still need to go thru scripts) for e.g. permissions, Data Factory datasets, etc?
Any other way to deploy (kind of export & import)?
Basically what you need is to create a reusable arm template, your question lacks some details yet ARM templates are the way of automated deployment in Azure, on a high-level
start by authoring your arm template to deploy the vanilla required resources look here
https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites/functions
https://learn.microsoft.com/en-us/azure/templates/microsoft.datafactory/factories
https://learn.microsoft.com/en-us/azure/templates/microsoft.logic/integrationaccounts
https://learn.microsoft.com/en-us/azure/templates/microsoft.datalakeanalytics/accounts/storageaccounts
you can combine all of them in one big template using ARM template dependency and other functions
look here
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions
after you finish ARM templates can be used in many ways including PowerShell, direct API calls or even you can create a deployment in Azure and save it to be reused with a click
look here, also if there will be a high volume of users consider adding it to market place.
https://learn.microsoft.com/en-us/azure/azure-resource-manager/
after finishing your implementation of vanilla resources you can then move into adding any customization you might have.
this is the right and best way to do "afaik"
also look here to see all of your existing resources in an arm template view
https://resources.azure.com/
my understanding of Azure is that almost everything with some few exceptions has an ARM template representation
hope this would help.

Resources