From aa9062e05e4be90931d923ad756157d284b3ce4b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 May 2018 18:38:35 -0700 Subject: [PATCH] New Resource: `azurerm_logic_app_workflow` Tests pass: ``` $ acctests azurerm TestAccAzureRMLogicAppWorkflow_ === RUN TestAccAzureRMLogicAppWorkflow_empty --- PASS: TestAccAzureRMLogicAppWorkflow_empty (97.38s) === RUN TestAccAzureRMLogicAppWorkflow_tags --- PASS: TestAccAzureRMLogicAppWorkflow_tags (83.56s) === RUN TestAccAzureRMLogicAppWorkflow_actionHTTP --- PASS: TestAccAzureRMLogicAppWorkflow_actionHTTP (75.25s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 256.212s ``` Fixes #610 --- azurerm/config.go | 17 + azurerm/import_arm_logic_app_workflow_test.go | 71 +++ azurerm/provider.go | 2 + azurerm/resource_arm_logic_app_workflow.go | 469 ++++++++++++++++++ .../resource_arm_logic_app_workflow_test.go | 199 ++++++++ website/azurerm.erb | 11 +- .../docs/r/logic_app_workflow.html.markdown | 112 +++++ 7 files changed, 880 insertions(+), 1 deletion(-) create mode 100644 azurerm/import_arm_logic_app_workflow_test.go create mode 100644 azurerm/resource_arm_logic_app_workflow.go create mode 100644 azurerm/resource_arm_logic_app_workflow_test.go create mode 100644 website/docs/r/logic_app_workflow.html.markdown diff --git a/azurerm/config.go b/azurerm/config.go index 6228100b58fd..d35b5585020c 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -25,9 +25,16 @@ import ( "github.com/Azure/azure-sdk-for-go/services/iothub/mgmt/2017-07-01/devices" keyVault "github.com/Azure/azure-sdk-for-go/services/keyvault/2016-10-01/keyvault" "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault" + "github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2016-06-01/logic" + "github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2017-05-01-preview/insights" "github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2018-03-01/insights" + "github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-04-30-preview/mysql" "github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql" + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network" + "github.com/Azure/azure-sdk-for-go/services/operationalinsights/mgmt/2015-11-01-preview/operationalinsights" + "github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement" + "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-04-30-preview/postgresql" "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql" "github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization" "github.com/Azure/azure-sdk-for-go/services/preview/dns/mgmt/2018-03-01-preview/dns" @@ -149,6 +156,9 @@ type ArmClient struct { keyVaultClient keyvault.VaultsClient keyVaultManagementClient keyVault.BaseClient + // Logic + logicWorkflowsClient logic.WorkflowsClient + // Monitor monitorAlertRulesClient insights.AlertRulesClient @@ -391,6 +401,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) { client.registerEventGridClients(endpoint, c.SubscriptionID, auth, sender) client.registerEventHubClients(endpoint, c.SubscriptionID, auth, sender) client.registerKeyVaultClients(endpoint, c.SubscriptionID, auth, keyVaultAuth, sender) + client.registerLogicClients(endpoint, c.SubscriptionID, auth, sender) client.registerMonitorClients(endpoint, c.SubscriptionID, auth, sender) client.registerNetworkingClients(endpoint, c.SubscriptionID, auth, sender) client.registerOperationalInsightsClients(endpoint, c.SubscriptionID, auth, sender) @@ -726,6 +737,12 @@ func (c *ArmClient) registerKeyVaultClients(endpoint, subscriptionId string, aut c.keyVaultManagementClient = keyVaultManagementClient } +func (c *ArmClient) registerLogicClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { + workflowsClient := logic.NewWorkflowsClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&workflowsClient.Client, auth) + c.logicWorkflowsClient = workflowsClient +} + func (c *ArmClient) registerMonitorClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { arc := insights.NewAlertRulesClientWithBaseURI(endpoint, subscriptionId) setUserAgent(&arc.Client) diff --git a/azurerm/import_arm_logic_app_workflow_test.go b/azurerm/import_arm_logic_app_workflow_test.go new file mode 100644 index 000000000000..a13e595e173d --- /dev/null +++ b/azurerm/import_arm_logic_app_workflow_test.go @@ -0,0 +1,71 @@ +package azurerm + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMLogicAppWorkflow_importEmpty(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMLogicAppWorkflow_empty(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorklowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: "azurerm_logic_app_workflow.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMLogicAppWorkflow_importTags(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMLogicAppWorkflow_tags(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorklowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: "azurerm_logic_app_workflow.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMLogicAppWorkflow_importActionHTTP(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMLogicAppWorkflow_actionHTTP(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorklowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: "azurerm_logic_app_workflow.test", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 235e6f607d7f..e6ae51c3571a 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -175,6 +175,7 @@ func Provider() terraform.ResourceProvider { "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), + "azurerm_logic_app_workflow": resourceArmLogicAppWorkflow(), "azurerm_managed_disk": resourceArmManagedDisk(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_metric_alertrule": resourceArmMetricAlertRule(), @@ -355,6 +356,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider "Microsoft.EventHub": {}, "Microsoft.KeyVault": {}, "microsoft.insights": {}, + "Microsoft.Logic": {}, "Microsoft.ManagedIdentity": {}, "Microsoft.Network": {}, "Microsoft.OperationalInsights": {}, diff --git a/azurerm/resource_arm_logic_app_workflow.go b/azurerm/resource_arm_logic_app_workflow.go new file mode 100644 index 000000000000..57b7400d5117 --- /dev/null +++ b/azurerm/resource_arm_logic_app_workflow.go @@ -0,0 +1,469 @@ +package azurerm + +import ( + "fmt" + "log" + + "strings" + + "github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2016-06-01/logic" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmLogicAppWorkflow() *schema.Resource { + return &schema.Resource{ + Create: resourceArmLogicAppWorkflowCreateUpdate, + Read: resourceArmLogicAppWorkflowRead, + Update: resourceArmLogicAppWorkflowCreateUpdate, + Delete: resourceArmLogicAppWorkflowDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "location": locationSchema(), + + "resource_group_name": resourceGroupNameSchema(), + + "parameters": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + }, + + "trigger": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "recurrence": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "frequency": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "Month", + "Week", + "Day", + "Hour", + "Minute", + "Hour", + "Second", + }, true), + }, + "interval": { + Type: schema.TypeInt, + Required: true, + }, + }, + }, + }, + }, + }, + }, + + "action": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "http": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "method": { + Type: schema.TypeString, + Required: true, + }, + "uri": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + + "function": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "function_id": { + Type: schema.TypeString, + Required: true, + }, + "body": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + }, + }, + }, + + "tags": tagsSchema(), + + "access_endpoint": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmLogicAppWorkflowCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).logicWorkflowsClient + ctx := meta.(*ArmClient).StopContext + + log.Printf("[INFO] preparing arguments for Logic App Workflow creation.") + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + location := azureRMNormalizeLocation(d.Get("location").(string)) + definition := expandLogicAppWorkflowDefinition(d) + parameters := expandLogicAppWorkflowParameters(d) + tags := d.Get("tags").(map[string]interface{}) + + properties := logic.Workflow{ + Location: utils.String(location), + WorkflowProperties: &logic.WorkflowProperties{ + Definition: definition, + Parameters: parameters, + }, + Tags: expandTags(tags), + } + + _, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties) + if err != nil { + return err + } + + read, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("[ERROR] Cannot read Logic App Workflow %q (Resource Group %q) ID", name, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmLogicAppWorkflowRead(d, meta) +} + +func resourceArmLogicAppWorkflowRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).logicWorkflowsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["workflows"] + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("[ERROR] Error making Read request on Logic App Workflow %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + if props := resp.WorkflowProperties; props != nil { + parameters := flattenLogicAppWorkflowParameters(props.Parameters) + if err := d.Set("parameters", parameters); err != nil { + return fmt.Errorf("Error flattening `parameters`: %+v", err) + } + + triggers, err := flattenLogicAppWorkflowTriggers(props.Definition) + if err != nil { + return fmt.Errorf("Error flattening `trigger`: %+v", err) + } + if err := d.Set("trigger", triggers); err != nil { + return fmt.Errorf("Error setting `trigger`: %+v", err) + } + + actions, err := flattenLogicAppWorkflowActions(props.Definition) + if err != nil { + return fmt.Errorf("Error flattening `action`: %+v", err) + } + if err := d.Set("action", actions); err != nil { + return fmt.Errorf("Error setting `action`: %+v", err) + } + + d.Set("access_endpoint", props.AccessEndpoint) + } + + flattenAndSetTags(d, resp.Tags) + + return nil +} + +func resourceArmLogicAppWorkflowDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).logicWorkflowsClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["workflows"] + + resp, err := client.Delete(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp) { + return nil + } + + return fmt.Errorf("Error issuing delete request for Logic App Workflow %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + return nil +} + +func expandLogicAppWorkflowDefinition(d *schema.ResourceData) interface{} { + triggers := expandLogicAppWorkflowTriggers(d) + actions := expandLogicAppWorkflowActions(d) + + definition := map[string]interface{}{ + // these could potentially be user-configurable in future? + "$schema": "http://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json", + "contentVersion": "1.0.0.0", + "actions": actions, + "triggers": triggers, + } + return definition +} + +func expandLogicAppWorkflowActions(d *schema.ResourceData) interface{} { + output := make(map[string]interface{}, 0) + input := d.Get("action").([]interface{}) + + for _, trigger := range input { + triggerVal := trigger.(map[string]interface{}) + + https := triggerVal["http"].([]interface{}) + for _, http := range https { + httpVal := http.(map[string]interface{}) + + name := httpVal["name"].(string) + method := httpVal["method"].(string) + uri := httpVal["uri"].(string) + + output[name] = map[string]interface{}{ + "type": "http", + "inputs": map[string]interface{}{ + "method": method, + "uri": uri, + }, + } + } + + functions := triggerVal["function"].([]interface{}) + for _, function := range functions { + functionVal := function.(map[string]interface{}) + + name := functionVal["name"].(string) + functionId := functionVal["function_id"].(string) + body := functionVal["body"].(string) + + output[name] = map[string]interface{}{ + "type": "function", + "inputs": map[string]interface{}{ + "body": body, + "function": map[string]interface{}{ + "id": functionId, + }, + }, + } + } + } + + return output +} + +func flattenLogicAppWorkflowActions(input interface{}) ([]interface{}, error) { + definition, ok := input.(map[string]interface{}) + if !ok { + return []interface{}{}, nil + } + + actionsVal, ok := definition["actions"] + if !ok { + return []interface{}{}, nil + } + + httpOutputs := make([]interface{}, 0) + functionOutputs := make([]interface{}, 0) + + actions := actionsVal.(map[string]interface{}) + for name, val := range actions { + v := val.(map[string]interface{}) + actionType := v["type"].(string) + + if strings.EqualFold(actionType, "http") { + inputs := v["inputs"].(map[string]interface{}) + method := inputs["method"].(string) + uri := inputs["uri"].(string) + output := map[string]interface{}{ + "name": name, + "method": method, + "uri": uri, + } + httpOutputs = append(httpOutputs, output) + } else if strings.EqualFold(actionType, "function") { + inputs := v["input"].(map[string]interface{}) + body := inputs["body"].(string) + function := inputs["function"].(map[string]interface{}) + functionId := function["id"].(string) + output := map[string]interface{}{ + "name": name, + "function_id": functionId, + "body": body, + } + functionOutputs = append(functionOutputs, output) + } else { + return nil, fmt.Errorf("Unsupported Action Type %q", actionType) + } + } + + output := map[string]interface{}{ + "http": httpOutputs, + "function": functionOutputs, + } + + return []interface{}{output}, nil +} + +func expandLogicAppWorkflowTriggers(d *schema.ResourceData) interface{} { + output := make(map[string]interface{}, 0) + + input := d.Get("trigger").([]interface{}) + for _, triggerVal := range input { + val := triggerVal.(map[string]interface{}) + + recurrenceInput := val["recurrence"].([]interface{}) + for _, recurrenceVal := range recurrenceInput { + v := recurrenceVal.(map[string]interface{}) + name := v["name"].(string) + frequency := v["frequency"].(string) + interval := v["interval"].(int) + output[name] = map[string]interface{}{ + "type": "recurrence", + "recurrence": map[string]interface{}{ + "frequency": frequency, + "interval": interval, + }, + } + } + } + + return output +} + +func flattenLogicAppWorkflowTriggers(input interface{}) ([]interface{}, error) { + definition, ok := input.(map[string]interface{}) + if !ok { + return []interface{}{}, nil + } + + triggersVal, ok := definition["triggers"] + if !ok { + return []interface{}{}, nil + } + + recurrenceOutputs := make([]interface{}, 0) + + triggers := triggersVal.(map[string]interface{}) + for name, val := range triggers { + v := val.(map[string]interface{}) + triggerType := v["type"].(string) + + if strings.EqualFold(triggerType, "recurrence") { + recurrence := v["recurrence"].(map[string]interface{}) + + frequency := recurrence["frequency"].(string) + interval := int(recurrence["interval"].(float64)) + output := map[string]interface{}{ + "name": name, + "frequency": frequency, + "interval": interval, + } + recurrenceOutputs = append(recurrenceOutputs, output) + } else { + return nil, fmt.Errorf("Unsupported Trigger Type %q", triggerType) + } + } + + output := map[string]interface{}{ + "recurrence": recurrenceOutputs, + } + + return []interface{}{output}, nil +} + +func expandLogicAppWorkflowParameters(d *schema.ResourceData) map[string]*logic.WorkflowParameter { + output := make(map[string]*logic.WorkflowParameter, 0) + input := d.Get("parameters").(map[string]interface{}) + + for k, v := range input { + output[k] = &logic.WorkflowParameter{ + Type: logic.ParameterTypeString, + Value: v.(string), + } + } + + return output +} + +func flattenLogicAppWorkflowParameters(input map[string]*logic.WorkflowParameter) map[string]interface{} { + output := make(map[string]interface{}, 0) + + for k, v := range input { + if v != nil { + output[k] = v.Value.(string) + } + } + + return output +} diff --git a/azurerm/resource_arm_logic_app_workflow_test.go b/azurerm/resource_arm_logic_app_workflow_test.go new file mode 100644 index 000000000000..48794cf29098 --- /dev/null +++ b/azurerm/resource_arm_logic_app_workflow_test.go @@ -0,0 +1,199 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMLogicAppWorkflow_empty(t *testing.T) { + resourceName := "azurerm_logic_app_workflow.test" + ri := acctest.RandInt() + config := testAccAzureRMLogicAppWorkflow_empty(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorklowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppWorklowExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "action.0.http.#", "0"), + resource.TestCheckResourceAttr(resourceName, "action.0.function.#", "0"), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(resourceName, "trigger.#", "1"), + resource.TestCheckResourceAttr(resourceName, "trigger.0.recurrence.#", "0"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccAzureRMLogicAppWorkflow_tags(t *testing.T) { + resourceName := "azurerm_logic_app_workflow.test" + ri := acctest.RandInt() + config := testAccAzureRMLogicAppWorkflow_tags(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorklowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppWorklowExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Source", "AcceptanceTests"), + ), + }, + }, + }) +} + +func TestAccAzureRMLogicAppWorkflow_actionHTTP(t *testing.T) { + resourceName := "azurerm_logic_app_workflow.test" + ri := acctest.RandInt() + config := testAccAzureRMLogicAppWorkflow_actionHTTP(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorklowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppWorklowExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "action.#", "1"), + resource.TestCheckResourceAttr(resourceName, "action.0.http.#", "1"), + resource.TestCheckResourceAttr(resourceName, "action.0.http.0.name", "example"), + resource.TestCheckResourceAttr(resourceName, "action.0.http.0.method", "GET"), + resource.TestCheckResourceAttr(resourceName, "action.0.http.0.uri", "http://example.com/foo"), + resource.TestCheckResourceAttr(resourceName, "action.0.function.#", "0"), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(resourceName, "trigger.#", "1"), + resource.TestCheckResourceAttr(resourceName, "trigger.0.recurrence.#", "0"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func testCheckAzureRMLogicAppWorklowExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + workflowName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Logic App Workflow: %s", workflowName) + } + + client := testAccProvider.Meta().(*ArmClient).logicWorkflowsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := client.Get(ctx, resourceGroup, workflowName) + if err != nil { + return fmt.Errorf("Bad: Get on diskClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Logic App Workflow %q (resource group %q) does not exist", workflowName, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMLogicAppWorklowDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).logicWorkflowsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_logic_app_workflow" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(ctx, resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Logic App Workflow still exists: \n%#v", resp) + } + } + + return nil +} + +func testAccAzureRMLogicAppWorkflow_empty(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) +} + +func testAccAzureRMLogicAppWorkflow_tags(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}" + + tags { + "Source" = "AcceptanceTests" + } +} +`, rInt, location, rInt) +} + +func testAccAzureRMLogicAppWorkflow_actionHTTP(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}" + + action { + http { + name = "example" + method = "GET" + uri = "http://example.com/foo" + } + } +} +`, rInt, location, rInt) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 1a68078a90e5..581129bd18ed 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -538,7 +538,16 @@ - > + > + Logic App Resources + + + + > Management Resources