From 4063a6df3d2e600b398b8b814130af9af5b2d080 Mon Sep 17 00:00:00 2001 From: nickel-tyler Date: Wed, 15 May 2024 08:49:55 -0500 Subject: [PATCH 1/4] add callback url for relevant trigger types --- .../logic_app_trigger_custom_resource.go | 20 +++++-- .../logic_app_trigger_custom_resource_test.go | 58 +++++++++++++++++++ ...logic_app_trigger_http_request_resource.go | 2 +- ..._app_trigger_http_request_resource_test.go | 3 +- .../logic_app_trigger_recurrence_resource.go | 4 +- ...ic_app_trigger_recurrence_resource_test.go | 6 ++ internal/services/logic/logic_apps.go | 45 +++++++++++--- .../r/logic_app_trigger_custom.html.markdown | 4 ++ ...gic_app_trigger_http_request.html.markdown | 2 +- 9 files changed, 124 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..fd7bfe5ae96a 100644 --- a/internal/services/logic/logic_app_trigger_custom_resource.go +++ b/internal/services/logic/logic_app_trigger_custom_resource.go @@ -54,6 +54,10 @@ func resourceLogicAppTriggerCustom() *pluginsdk.Resource { ValidateFunc: validation.StringIsJSON, DiffSuppressFunc: pluginsdk.SuppressJsonDiff, }, + "callback_url": { + Type: pluginsdk.TypeString, + Computed: true, + }, }, } } @@ -88,9 +92,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 +103,22 @@ 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) + if url != nil { + d.Set("callback_url", url) + } else { + d.Set("callback_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..21cbe1175cf6 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,38 @@ 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.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("callback_url").IsEmpty(), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLogicAppTriggerCustom_callbackUrl2(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 +108,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 From 8193e1afd824f3bffb1de40803e250c3d6390482 Mon Sep 17 00:00:00 2001 From: nickel-tyler Date: Wed, 15 May 2024 08:57:49 -0500 Subject: [PATCH 2/4] fix --- internal/services/logic/logic_apps.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/services/logic/logic_apps.go b/internal/services/logic/logic_apps.go index e6e4f8d77cc7..c9849b2b70e7 100644 --- a/internal/services/logic/logic_apps.go +++ b/internal/services/logic/logic_apps.go @@ -241,11 +241,7 @@ func IsCallbackType(tType string) bool { valid := validation.StringInSlice(cTypes, false) _, errors := valid(tType, "callback_url") - if len(errors) == 0 { - return true - } - - return false + return len(errors) == 0 } func retreiveLogicAppTriggerCallbackUrl(d *pluginsdk.ResourceData, meta interface{}, id workflowtriggers.TriggerId) (*string, error) { From f378549669e7acb154b3ca11dbe453d8cbfe7d6a Mon Sep 17 00:00:00 2001 From: nickel-tyler Date: Thu, 16 May 2024 12:03:51 -0500 Subject: [PATCH 3/4] remove rg tags because linter doesn't like it even though it's valid hcl --- .../logic/logic_app_trigger_custom_resource_test.go | 1 - .../logic/logic_app_trigger_http_request_resource_test.go | 1 - .../logic/logic_app_trigger_recurrence_resource_test.go | 6 ------ 3 files changed, 8 deletions(-) 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 21cbe1175cf6..5cd71f84dc65 100644 --- a/internal/services/logic/logic_app_trigger_custom_resource_test.go +++ b/internal/services/logic/logic_app_trigger_custom_resource_test.go @@ -155,7 +155,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { diff --git a/internal/services/logic/logic_app_trigger_http_request_resource_test.go b/internal/services/logic/logic_app_trigger_http_request_resource_test.go index b43a052f090e..8856d9705787 100644 --- a/internal/services/logic/logic_app_trigger_http_request_resource_test.go +++ b/internal/services/logic/logic_app_trigger_http_request_resource_test.go @@ -243,7 +243,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { diff --git a/internal/services/logic/logic_app_trigger_recurrence_resource_test.go b/internal/services/logic/logic_app_trigger_recurrence_resource_test.go index ce49d0a46fcc..02d7c064d852 100644 --- a/internal/services/logic/logic_app_trigger_recurrence_resource_test.go +++ b/internal/services/logic/logic_app_trigger_recurrence_resource_test.go @@ -270,7 +270,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { @@ -297,7 +296,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { @@ -325,7 +323,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { @@ -354,7 +351,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { @@ -395,7 +391,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { @@ -428,7 +423,6 @@ provider "azurerm" { resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - tags = { Contact = "jimbo" } } resource "azurerm_logic_app_workflow" "test" { From d2057697c8f17c2d8d7e6188effb125610e07fc9 Mon Sep 17 00:00:00 2001 From: nickel-tyler Date: Tue, 28 May 2024 08:05:12 -0500 Subject: [PATCH 4/4] review fixes --- .../logic/logic_app_trigger_custom_resource.go | 8 ++------ .../logic_app_trigger_custom_resource_test.go | 16 ---------------- .../r/logic_app_trigger_custom.html.markdown | 2 +- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/internal/services/logic/logic_app_trigger_custom_resource.go b/internal/services/logic/logic_app_trigger_custom_resource.go index fd7bfe5ae96a..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" @@ -107,12 +108,7 @@ func resourceLogicAppTriggerCustomRead(d *pluginsdk.ResourceData, meta interface d.Set("name", id.TriggerName) d.Set("logic_app_id", app.Id) - - if url != nil { - d.Set("callback_url", url) - } else { - d.Set("callback_url", "") - } + 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 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 5cd71f84dc65..c893767141f8 100644 --- a/internal/services/logic/logic_app_trigger_custom_resource_test.go +++ b/internal/services/logic/logic_app_trigger_custom_resource_test.go @@ -35,22 +35,6 @@ 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.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("callback_url").IsEmpty(), - ), - }, - data.ImportStep(), - }) -} - -func TestAccLogicAppTriggerCustom_callbackUrl2(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), diff --git a/website/docs/r/logic_app_trigger_custom.html.markdown b/website/docs/r/logic_app_trigger_custom.html.markdown index 7f1c2d06051e..884d35360ede 100644 --- a/website/docs/r/logic_app_trigger_custom.html.markdown +++ b/website/docs/r/logic_app_trigger_custom.html.markdown @@ -63,7 +63,7 @@ In addition to the Arguments listed above - the following Attributes are exporte * `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). --> **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. +-> **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