Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_logic_app_action_http: add run_after #7079

Merged
merged 1 commit into from May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions azurerm/internal/services/logic/logic_app_action_http_resource.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
},
},
},
},
},
}
}
Expand All @@ -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())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to set this to an empty array if this is unset?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test result shows that is not necessary. Also in the previous case where we didn't set it at all, it still works for the first level action (which is right after the trigger).


logicAppId := d.Get("logic_app_id").(string)
name := d.Get("name").(string)
err = resourceLogicAppActionUpdate(d, meta, logicAppId, name, action, "azurerm_logic_app_action_http")
Expand Down Expand Up @@ -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
}

Expand Down
26 changes: 26 additions & 0 deletions azurerm/internal/services/logic/logic_apps.go
Expand Up @@ -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)
Expand Down
Expand Up @@ -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(`
Expand Down Expand Up @@ -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" {
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/logic_app_action_http.html.markdown
Expand Up @@ -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:
Expand Down