Reputation: 2503
I would like fetch url of logicapps, but getting errors.
How to modify Terraform code so that output works? I'm not how to reference to Logic App instance and what is correct way to get url.
logicapp-main.tf
resource "azurerm_resource_group" "example" {
name = "workflow-resources"
location = "West Europe"
}
resource "azurerm_logic_app_workflow" "example" {
name = "workflow1"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_logic_app_trigger_http_request" "example" {
name = "some-http-trigger"
logic_app_id = azurerm_logic_app_workflow.example.id#
schema = <<SCHEMA
{
"type": "object",
"properties": {
"Message": {
"type": "string"
}
}
}
SCHEMA
}
output "logic_app_get_url" {
value = some-http-trigger.logic_app_get_url
description = "fetch url"
}
Error:
Error: Reference to undeclared resource
│
│ on logicapp-main.tf line 91, in output "logic_app_get_url":
│ 91: value = some-http-trigger.logic_app_get_url
│
│ A managed resource "some-http-trigger" "logic_app_get_url" has not been declared in the root module.
Upvotes: 0
Views: 2139
Reputation: 3
Following on from wagner-bertolini-junior's comment, we had trouble getting the correct resource_id using the form provided with a resource group template deployment of consumption logic app (not shown). The following brought us success.
data "azurerm_logic_app_workflow" "example" {
name = "logic_app_name"
resource_group_name = "resource_group_name"
}
#https://learn.microsoft.com/en-us/azure/templates/microsoft.logic/2016-06-01/workflows/triggers?wt.mc_id=searchAPI_azureportal_inproduct_rmskilling&sessionId=d1280442e1e8406f83560d61eb837d81&pivots=deployment-language-terraform
data "azapi_resource_action" "callback_url_data" {
type = "Microsoft.Logic/workflows/triggers@2016-06-01"
action = "listCallbackUrl"
resource_id = "${data.azurerm_logic_app_workflow.example.id}/triggers/When_an_HTTP_request_is_received"
response_export_values = ["*"]
}
Upvotes: 0
Reputation: 21
If you are looking for a callback url for a trigger in Logic App Standard then please see below.
Microsoft changed the way workflows are deployed under Logic App Standard. The documentation is pretty poor so sharing this to help others struggling to find the magic combo.
The result requires a POST to the API so I used Terraform AZ API resource action to send the same using Terraform.
data "azapi_resource_action" "callback_url_data" {
type = "Microsoft.Web/sites/hostruntime/webhooks/api/workflows/triggers@2022-03-01"
action = "listCallbackUrl"
resource_id = "/subscriptions/<subscriptionid>/resourceGroups/<logicapp_resourcegroup>/providers/Microsoft.Web/sites/<logicapp_name>/hostruntime/runtime/webhooks/workflow/api/management/workflows/<workflow_name>/triggers/<trigger_name>"
response_export_values = ["*"]
}
output "callback_url" {
value = jsondecode(data.azapi_resource_action.callback_url_data.output).value
}
References
Azure API / App Service / Workflow Triggers - List Callback Url
Upvotes: 2
Reputation: 5506
Please do modify the output block in the above shared terraform code to fetch the callback url of the logic app.
output "url" {
value = azurerm_logic_app_trigger_http_request.example.callback_url
}
Here is the modified Terraform Code:
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "workflow-resources"
location = "West Europe"
}
resource "azurerm_logic_app_workflow" "example" {
name = "workflow1"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_logic_app_trigger_http_request" "example" {
name = "some-http-trigger"
logic_app_id = azurerm_logic_app_workflow.example.id
schema = <<SCHEMA
{
"type": "object",
"properties": {
"hello": {
"type": "string"
}
}
}
SCHEMA
}
output "url" {
value = azurerm_logic_app_trigger_http_request.example.callback_url
}
Here is the sample output for reference :
Upvotes: 1