From 4b30512b9f8721ea0bff2205fbd217f76ac8f79a Mon Sep 17 00:00:00 2001 From: nickel-tyler <154907002+nickel-tyler@users.noreply.github.com> Date: Tue, 28 May 2024 08:31:05 -0500 Subject: [PATCH] azurerm_logic_app_trigger_custom - adding exported attribute callback_url (#25979) * add callback url for relevant trigger types * fix * remove rg tags because linter doesn't like it even though it's valid hcl * review fixes --- .../logic_app_trigger_custom_resource.go | 16 +++++--- .../logic_app_trigger_custom_resource_test.go | 41 +++++++++++++++++++ ...logic_app_trigger_http_request_resource.go | 2 +- ..._app_trigger_http_request_resource_test.go | 2 +- .../logic_app_trigger_recurrence_resource.go | 4 +- internal/services/logic/logic_apps.go | 41 +++++++++++++++---- .../r/logic_app_trigger_custom.html.markdown | 4 ++ ...gic_app_trigger_http_request.html.markdown | 2 +- 8 files changed, 92 insertions(+), 20 deletions(-) diff --git a/internal/services/logic/logic_app_trigger_custom_resource.go b/internal/services/logic/logic_app_trigger_custom_resource.go index 57ceed41d670..711b65fd808f 100644 --- a/internal/services/logic/logic_app_trigger_custom_resource.go +++ b/internal/services/logic/logic_app_trigger_custom_resource.go @@ -9,6 +9,7 @@ import ( "log" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-sdk/resource-manager/logic/2019-05-01/workflows" "github.com/hashicorp/go-azure-sdk/resource-manager/logic/2019-05-01/workflowtriggers" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -54,6 +55,10 @@ func resourceLogicAppTriggerCustom() *pluginsdk.Resource { ValidateFunc: validation.StringIsJSON, DiffSuppressFunc: pluginsdk.SuppressJsonDiff, }, + "callback_url": { + Type: pluginsdk.TypeString, + Computed: true, + }, }, } } @@ -88,9 +93,7 @@ func resourceLogicAppTriggerCustomRead(d *pluginsdk.ResourceData, meta interface return err } - workflowId := workflows.NewWorkflowID(id.SubscriptionId, id.ResourceGroupName, id.WorkflowName) - - t, app, err := retrieveLogicAppTrigger(d, meta, workflowId, id.TriggerName) + t, app, url, err := retrieveLogicAppTrigger(d, meta, *id) if err != nil { return err } @@ -101,16 +104,17 @@ func resourceLogicAppTriggerCustomRead(d *pluginsdk.ResourceData, meta interface return nil } - action := *t + trigger := *t d.Set("name", id.TriggerName) d.Set("logic_app_id", app.Id) + d.Set("callback_url", pointer.From(url)) // Azure returns an additional field called evaluatedRecurrence in the trigger body which // is a copy of the recurrence specified in the body property and breaks the diff suppress logic - delete(action, "evaluatedRecurrence") + delete(trigger, "evaluatedRecurrence") - body, err := json.Marshal(action) + body, err := json.Marshal(trigger) if err != nil { return fmt.Errorf("serializing `body` for %s: %+v", id.ID(), err) } diff --git a/internal/services/logic/logic_app_trigger_custom_resource_test.go b/internal/services/logic/logic_app_trigger_custom_resource_test.go index b8222fc2132d..c893767141f8 100644 --- a/internal/services/logic/logic_app_trigger_custom_resource_test.go +++ b/internal/services/logic/logic_app_trigger_custom_resource_test.go @@ -31,6 +31,22 @@ func TestAccLogicAppTriggerCustom_basic(t *testing.T) { }) } +func TestAccLogicAppTriggerCustom_callbackUrl(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_custom", "test") + r := LogicAppTriggerCustomResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.nonEmptyCallback(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("callback_url").IsNotEmpty(), + ), + }, + data.ImportStep(), + }) +} + func TestAccLogicAppTriggerCustom_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_custom", "test") r := LogicAppTriggerCustomResource{} @@ -76,6 +92,31 @@ BODY `, template, data.RandomInteger) } +func (LogicAppTriggerCustomResource) nonEmptyCallback(data acceptance.TestData) string { + template := LogicAppTriggerCustomResource{}.template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_trigger_custom" "test" { + name = "request-%d" + logic_app_id = azurerm_logic_app_workflow.test.id + + body = < **NOTE:** `callback_url` is populated for [Triggers with a type of](https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-actions-triggers#trigger-types-list) HTTPWebhook, Request, or ApiConnectionWebhook. For all other Trigger types, `callback_url` will be empty and should not be referenced. + ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: diff --git a/website/docs/r/logic_app_trigger_http_request.html.markdown b/website/docs/r/logic_app_trigger_http_request.html.markdown index acfcd4976e1c..1053f3c04c3a 100644 --- a/website/docs/r/logic_app_trigger_http_request.html.markdown +++ b/website/docs/r/logic_app_trigger_http_request.html.markdown @@ -68,7 +68,7 @@ In addition to the Arguments listed above - the following Attributes are exporte * `id` - The ID of the HTTP Request Trigger within the Logic App Workflow. -* `callback_url` - The URL for the workflow trigger +* `callback_url` - The URL of the Trigger within the Logic App Workflow. For use with certain resources like [monitor_action_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_action_group) and [security_center_automation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/security_center_automation). ## Timeouts