-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_logic_app_trigger_custom
- Loading branch information
1 parent
0193c1d
commit 4d77253
Showing
7 changed files
with
295 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package azurerm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMLogicAppTriggerCustom_importBasic(t *testing.T) { | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMLogicAppTriggerCustom_basic(ri, testLocation()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
{ | ||
ResourceName: "azurerm_logic_app_trigger_custom.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"encoding/json" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/structure" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
func resourceArmLogicAppTriggerCustom() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmLogicAppTriggerCustomCreateUpdate, | ||
Read: resourceArmLogicAppTriggerCustomRead, | ||
Update: resourceArmLogicAppTriggerCustomCreateUpdate, | ||
Delete: resourceArmLogicAppTriggerCustomDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"logic_app_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: azure.ValidateResourceID, | ||
}, | ||
|
||
"body": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.ValidateJsonString, | ||
DiffSuppressFunc: structure.SuppressJsonDiff, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmLogicAppTriggerCustomCreateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
logicAppId := d.Get("logic_app_id").(string) | ||
name := d.Get("name").(string) | ||
bodyRaw := d.Get("body").(string) | ||
|
||
var body map[string]interface{} | ||
err := json.Unmarshal([]byte(bodyRaw), &body) | ||
if err != nil { | ||
return fmt.Errorf("Error unmarshalling JSON for Custom Trigger %q: %+v", name, err) | ||
} | ||
|
||
err = resourceLogicAppTriggerUpdate(d, meta, logicAppId, name, body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return resourceArmLogicAppTriggerCustomRead(d, meta) | ||
} | ||
|
||
func resourceArmLogicAppTriggerCustomRead(d *schema.ResourceData, meta interface{}) error { | ||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
logicAppName := id.Path["workflows"] | ||
name := id.Path["triggers"] | ||
|
||
t, app, err := retrieveLogicAppTrigger(meta, resourceGroup, logicAppName, name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if t == nil { | ||
log.Printf("[DEBUG] Logic App %q (Resource Group %q) does not contain Trigger %q - removing from state", logicAppName, resourceGroup, name) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
action := *t | ||
|
||
d.Set("name", name) | ||
d.Set("logic_app_id", app.ID) | ||
|
||
body, err := json.Marshal(action) | ||
if err != nil { | ||
return fmt.Errorf("Error serializing `body` for Trigger %q: %+v", name, err) | ||
} | ||
|
||
if err := d.Set("body", string(body)); err != nil { | ||
return fmt.Errorf("Error flattening `body` for Trigger %q: %+v", name, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceArmLogicAppTriggerCustomDelete(d *schema.ResourceData, meta interface{}) error { | ||
id, err := parseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resourceGroup := id.ResourceGroup | ||
logicAppName := id.Path["workflows"] | ||
name := id.Path["triggers"] | ||
|
||
err = resourceLogicAppTriggerRemove(d, meta, resourceGroup, logicAppName, name) | ||
if err != nil { | ||
return fmt.Errorf("Error removing Trigger %q from Logic App %q (Resource Group %q): %+v", name, logicAppName, resourceGroup, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMLogicAppTriggerCustom_basic(t *testing.T) { | ||
resourceName := "azurerm_logic_app_trigger_custom.test" | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMLogicAppTriggerCustom_basic(ri, testLocation()) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMLogicAppTriggerExists(resourceName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAzureRMLogicAppTriggerCustom_basic(rInt int, location string) string { | ||
template := testAccAzureRMLogicAppTriggerCustom_template(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
resource "azurerm_logic_app_trigger_custom" "test" { | ||
name = "recurrence-%d" | ||
logic_app_id = "${azurerm_logic_app_workflow.test.id}" | ||
body = <<BODY | ||
{ | ||
"recurrence": { | ||
"frequency": "Day", | ||
"interval": 1 | ||
}, | ||
"type": "Recurrence" | ||
} | ||
BODY | ||
} | ||
`, template, rInt) | ||
} | ||
|
||
func testAccAzureRMLogicAppTriggerCustom_template(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_logic_app_workflow" "test" { | ||
name = "acctestlaw-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
} | ||
`, rInt, location, rInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_logic_app_trigger_custom" | ||
sidebar_current: "docs-azurerm-resource-logic-app-trigger-custom" | ||
description: |- | ||
Manages a Custom Trigger within a Logic App Workflow | ||
--- | ||
|
||
# azurerm_logic_app_trigger_custom | ||
|
||
Manages a Custom Trigger within a Logic App Workflow | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "azurerm_resource_group" "test" { | ||
name = "workflow-resources" | ||
location = "East US" | ||
} | ||
resource "azurerm_logic_app_workflow" "test" { | ||
name = "workflow1" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
} | ||
resource "azurerm_logic_app_trigger_custom" "test" { | ||
name = "example-trigger" | ||
logic_app_id = "${azurerm_logic_app_workflow.test.id}" | ||
body = <<BODY | ||
{ | ||
"recurrence": { | ||
"frequency": "Day", | ||
"interval": 1 | ||
}, | ||
"type": "Recurrence" | ||
} | ||
BODY | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) Specifies the name of the HTTP Trigger to be created within the Logic App Workflow. Changing this forces a new resource to be created. | ||
|
||
-> **NOTE:** This name must be unique across all Triggers within the Logic App Workflow. | ||
|
||
* `logic_app_id` - (Required) Specifies the ID of the Logic App Workflow. Changing this forces a new resource to be created. | ||
|
||
* `body` - (Required) Specifies the JSON Blob defining the Body of this Custom Trigger. | ||
|
||
-> **NOTE:** To make the Trigger more readable, you may wish to consider using HEREDOC syntax (as shown above) or [the `local_file` resource](https://www.terraform.io/docs/providers/local/d/file.html) to load the schema from a file on disk. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ID of the Trigger within the Logic App Workflow. | ||
|
||
## Import | ||
|
||
Logic App Custom Triggers can be imported using the `resource id`, e.g. | ||
|
||
```shell | ||
terraform import azurerm_logic_app_trigger_custom.custom1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Logic/workflows/workflow1/triggers/custom1 | ||
``` | ||
|
||
-> **NOTE:** This ID is unique to Terraform and doesn't directly match to any other resource. To compose this ID, you can take the ID Logic App Workflow and append `/triggers/{name of the trigger}`. |