'How to create or import an Azure API Connection (Microsoft.Web) using Terraform?

My requirement is to create a Logic App that will receive some inputs from other resources like Azure Data Factory and send out an email. I created this setup using the Azure portal and Logic app designer. When I added a Send an Email (V2) I was asked for an Office 365 account login and everything works as expected.

Now I'm trying to achieve all of this through Terraform. I can import the existing Logic app workflow to an AzureRM resource azurerm_logic_app_workflow but that doesn't import the API connection. I'm unsure on how to import the existing API connection into Terraform (or even to create a new API connection in Terraform).

Please advise.



Solution 1:[1]

It is not possible to create Azure API App from Terraform at the moment.

https://github.com/terraform-providers/terraform-provider-azurerm/issues/443.

There is workaround how to create Azure API App with AZ CLI as https://github.com/Azure/azure-cli/issues/2866#issuecomment-317544291 shows :

az resource create -g yugangw2 -n yugangw2-api12 --resource-type Microsoft.web/sites  --is-full-object -p "{\"kind\":\"api\", \"location\":\"West US\", \"properties\":{  \"serverFarmId\":\"/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272xxxxxx/resourcegroups/yugangw2/providers/Microsoft.Web/serverfarms/yugangw2-plan\"}}"

It seems there is no real difference between App Service and API Service (different icons).

So you could just use azurerm_app_service for both API and Web Apps.

Solution 2:[2]

I think what you are looking for is.

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_connection

Unfortunately, it does seem to be capable of referencing MS managed api connections, at least not that I've found so far.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kangcheng Jin-MSFT
Solution 2 azender01