diff --git a/azurerm/internal/services/logic/logic_app_action_http_resource.go b/azurerm/internal/services/logic/logic_app_action_http_resource.go index ff6b2263d8dae..93c4f1861dab7 100644 --- a/azurerm/internal/services/logic/logic_app_action_http_resource.go +++ b/azurerm/internal/services/logic/logic_app_action_http_resource.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2019-05-01/logic" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" @@ -73,6 +74,29 @@ func resourceArmLogicAppActionHTTP() *schema.Resource { Type: schema.TypeString, }, }, + "run_after": { + Type: schema.TypeSet, + Optional: true, + MinItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action_name": { + Type: schema.TypeString, + Required: true, + }, + "action_result": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(logic.WorkflowStatusSucceeded), + string(logic.WorkflowStatusFailed), + string(logic.WorkflowStatusSkipped), + string(logic.WorkflowStatusTimedOut), + }, false), + }, + }, + }, + }, }, } } @@ -99,6 +123,10 @@ func resourceArmLogicAppActionHTTPCreateUpdate(d *schema.ResourceData, meta inte "type": "http", } + if v, ok := d.GetOk("run_after"); ok { + action["runAfter"] = expandLogicAppActionRunAfter(v.(*schema.Set).List()) + } + logicAppId := d.Get("logic_app_id").(string) name := d.Get("name").(string) err = resourceLogicAppActionUpdate(d, meta, logicAppId, name, action, "azurerm_logic_app_action_http") @@ -169,6 +197,17 @@ func resourceArmLogicAppActionHTTPRead(d *schema.ResourceData, meta interface{}) } } + v = action["runAfter"] + if v != nil { + runAfter, ok := v.(map[string]interface{}) + if !ok { + return fmt.Errorf("Error parsing `runAfter` for HTTP Action %q (Logic App %q / Resource Group %q)", name, logicAppName, resourceGroup) + } + if err := d.Set("run_after", flattenLogicAppActionRunAfter(runAfter)); err != nil { + return fmt.Errorf("Error setting `runAfter` for HTTP Action %q: %+v", name, err) + } + } + return nil } diff --git a/azurerm/internal/services/logic/logic_apps.go b/azurerm/internal/services/logic/logic_apps.go index 6fb95048ff447..ffc97beb54b17 100644 --- a/azurerm/internal/services/logic/logic_apps.go +++ b/azurerm/internal/services/logic/logic_apps.go @@ -16,6 +16,32 @@ import ( ) // NOTE: this file is not a recommended way of developing Terraform resources; this exists to work around the fact that this API is dynamic (by it's nature) +func flattenLogicAppActionRunAfter(input map[string]interface{}) []interface{} { + if len(input) == 0 { + return nil + } + output := []interface{}{} + for k, v := range input { + output = append(output, map[string]interface{}{ + "action_name": k, + "action_result": v.([]interface{})[0], + }) + } + + return output +} +func expandLogicAppActionRunAfter(input []interface{}) map[string]interface{} { + if len(input) == 0 { + return nil + } + output := map[string]interface{}{} + for _, v := range input { + b := v.(map[string]interface{}) + output[b["action_name"].(string)] = []string{b["action_result"].(string)} + } + + return output +} func resourceLogicAppActionUpdate(d *schema.ResourceData, meta interface{}, logicAppId string, name string, vals map[string]interface{}, resourceName string) error { return resourceLogicAppComponentUpdate(d, meta, "Action", "actions", logicAppId, name, vals, resourceName) diff --git a/azurerm/internal/services/logic/tests/logic_app_action_http_resource_test.go b/azurerm/internal/services/logic/tests/logic_app_action_http_resource_test.go index f2e533b801125..e54010523073e 100644 --- a/azurerm/internal/services/logic/tests/logic_app_action_http_resource_test.go +++ b/azurerm/internal/services/logic/tests/logic_app_action_http_resource_test.go @@ -98,6 +98,32 @@ func TestAccAzureRMLogicAppActionHttp_disappears(t *testing.T) { }) } +func TestAccAzureRMLogicAppActionHttp_runAfter(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_http", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppActionHttp_runAfterCondition(data, "Succeeded"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppActionExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMLogicAppActionHttp_runAfterCondition(data, "Failed"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppActionExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testAccAzureRMLogicAppActionHttp_basic(data acceptance.TestData) string { template := testAccAzureRMLogicAppActionHttp_template(data) return fmt.Sprintf(` @@ -145,6 +171,42 @@ resource "azurerm_logic_app_action_http" "test" { `, template, data.RandomInteger) } +func testAccAzureRMLogicAppActionHttp_runAfterCondition(data acceptance.TestData, condition string) string { + template := testAccAzureRMLogicAppActionHttp_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_action_http" "testp1" { + name = "action%dp1" + logic_app_id = azurerm_logic_app_workflow.test.id + method = "GET" + uri = "http://example.com/hello" +} + +resource "azurerm_logic_app_action_http" "testp2" { + name = "action%dp2" + logic_app_id = azurerm_logic_app_workflow.test.id + method = "GET" + uri = "http://example.com/hello" +} + +resource "azurerm_logic_app_action_http" "test" { + name = "action%d" + logic_app_id = azurerm_logic_app_workflow.test.id + method = "GET" + uri = "http://example.com/hello" + run_after { + action_name = azurerm_logic_app_action_http.testp1.name + action_result = "%s" + } + run_after { + action_name = azurerm_logic_app_action_http.testp2.name + action_result = "%s" + } +} +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, condition, condition) +} + func testAccAzureRMLogicAppActionHttp_template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/logic_app_action_http.html.markdown b/website/docs/r/logic_app_action_http.html.markdown index ac9d27e158d10..556913d01fd93 100644 --- a/website/docs/r/logic_app_action_http.html.markdown +++ b/website/docs/r/logic_app_action_http.html.markdown @@ -50,6 +50,16 @@ The following arguments are supported: * `headers` - (Optional) Specifies a Map of Key-Value Pairs that should be sent to the `uri` when this HTTP Action is triggered. +* `run_after` - (Optional) Specifies the place of the HTTP Action in the Logic App Workflow. If not specified, the HTTP Action is right after the Trigger. A `run_after` block is as defined below. + +--- + +A `run_after` block supports the following: + +* `action_name` - (Required) Specifies the name of the precedent HTTP Action. + +* `action_result` - (Required) Specifies the expected result of the precedent HTTP Action, only after which the current HTTP Action will be triggered. + ## Attributes Reference The following attributes are exported: