From 70762ae1303798dda4afac06202c6eafc4f01804 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Jul 2018 10:25:53 +0200 Subject: [PATCH] New Data Source: `azurerm_logic_app_workflow` ``` $ acctests azurerm TestAccDataSourceAzureRMLogicAppWorkflow_ === RUN TestAccDataSourceAzureRMLogicAppWorkflow_basic --- PASS: TestAccDataSourceAzureRMLogicAppWorkflow_basic (69.73s) === RUN TestAccDataSourceAzureRMLogicAppWorkflow_tags --- PASS: TestAccDataSourceAzureRMLogicAppWorkflow_tags (67.28s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 137.042s ``` --- azurerm/data_source_logic_app_workflow.go | 108 ++++++++++++++++++ .../data_source_logic_app_workflow_test.go | 80 +++++++++++++ azurerm/provider.go | 1 + azurerm/resource_arm_logic_app_workflow.go | 4 - .../resource_arm_logic_app_workflow_test.go | 2 +- website/azurerm.erb | 6 +- .../docs/d/logic_app_workflow.html.markdown | 50 ++++++++ .../docs/r/logic_app_workflow.html.markdown | 2 +- 8 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 azurerm/data_source_logic_app_workflow.go create mode 100644 azurerm/data_source_logic_app_workflow_test.go create mode 100644 website/docs/d/logic_app_workflow.html.markdown diff --git a/azurerm/data_source_logic_app_workflow.go b/azurerm/data_source_logic_app_workflow.go new file mode 100644 index 000000000000..650b2ac0084f --- /dev/null +++ b/azurerm/data_source_logic_app_workflow.go @@ -0,0 +1,108 @@ +package azurerm + +import ( + "fmt" + + "github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2016-06-01/logic" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmLogicAppWorkflow() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmLogicAppWorkflowRead, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "resource_group_name": resourceGroupNameForDataSourceSchema(), + + "location": locationForDataSourceSchema(), + + // TODO: should Parameters be split out into their own object to allow validation on the different sub-types? + "parameters": { + Type: schema.TypeMap, + Computed: true, + }, + + "workflow_schema": { + Type: schema.TypeString, + Computed: true, + }, + + "workflow_version": { + Type: schema.TypeString, + Computed: true, + }, + + "tags": tagsForDataSourceSchema(), + + "access_endpoint": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} +func dataSourceArmLogicAppWorkflowRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).logicWorkflowsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + 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.SetId(*resp.ID) + + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + if props := resp.WorkflowProperties; props != nil { + parameters := flattenLogicAppDataSourceWorkflowParameters(props.Parameters) + if err := d.Set("parameters", parameters); err != nil { + return fmt.Errorf("Error flattening `parameters`: %+v", err) + } + + d.Set("access_endpoint", props.AccessEndpoint) + + if definition := props.Definition; definition != nil { + if v, ok := definition.(map[string]interface{}); ok { + schema := v["$schema"].(string) + version := v["contentVersion"].(string) + d.Set("workflow_schema", schema) + d.Set("workflow_version", version) + } + } + } + + flattenAndSetTags(d, resp.Tags) + + return nil +} + +func flattenLogicAppDataSourceWorkflowParameters(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/data_source_logic_app_workflow_test.go b/azurerm/data_source_logic_app_workflow_test.go new file mode 100644 index 000000000000..2e44b44f9f95 --- /dev/null +++ b/azurerm/data_source_logic_app_workflow_test.go @@ -0,0 +1,80 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) { + dataSourceName := "data.azurerm_logic_app_workflow.test" + ri := acctest.RandInt() + location := testLocation() + config := testAccDataSourceAzureRMLogicAppWorkflow_basic(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppWorkflowExists(dataSourceName), + resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMLogicAppWorkflow_tags(t *testing.T) { + dataSourceName := "data.azurerm_logic_app_workflow.test" + ri := acctest.RandInt() + location := testLocation() + config := testAccDataSourceAzureRMLogicAppWorkflow_tags(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppWorkflowExists(dataSourceName), + resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(dataSourceName, "tags.Source", "AcceptanceTests"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMLogicAppWorkflow_basic(rInt int, location string) string { + resource := testAccAzureRMLogicAppWorkflow_empty(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_logic_app_workflow" "test" { + name = "${azurerm_logic_app_workflow.test.name}" + resource_group_name = "${azurerm_logic_app_workflow.test.resource_group_name}" +} +`, resource) +} + +func testAccDataSourceAzureRMLogicAppWorkflow_tags(rInt int, location string) string { + resource := testAccAzureRMLogicAppWorkflow_tags(rInt, location) + return fmt.Sprintf(` +%s + +data "azurerm_logic_app_workflow" "test" { + name = "${azurerm_logic_app_workflow.test.name}" + resource_group_name = "${azurerm_logic_app_workflow.test.resource_group_name}" +} +`, resource) +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 36b80bd890ad..c97d99def37a 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -94,6 +94,7 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), "azurerm_kubernetes_cluster": dataSourceArmKubernetesCluster(), + "azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(), "azurerm_managed_disk": dataSourceArmManagedDisk(), "azurerm_network_interface": dataSourceArmNetworkInterface(), "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), diff --git a/azurerm/resource_arm_logic_app_workflow.go b/azurerm/resource_arm_logic_app_workflow.go index 2a0e2b25d8fc..2a03fa4c87fd 100644 --- a/azurerm/resource_arm_logic_app_workflow.go +++ b/azurerm/resource_arm_logic_app_workflow.go @@ -11,10 +11,6 @@ import ( var logicAppResourceName = "azurerm_logic_app" -// azurerm_logic_app_action_custom -// azurerm_logic_app_trigger_custom -// azurerm_logic_app_condition_custom? - func resourceArmLogicAppWorkflow() *schema.Resource { return &schema.Resource{ Create: resourceArmLogicAppWorkflowCreate, diff --git a/azurerm/resource_arm_logic_app_workflow_test.go b/azurerm/resource_arm_logic_app_workflow_test.go index c3db8442df56..4976f40949c8 100644 --- a/azurerm/resource_arm_logic_app_workflow_test.go +++ b/azurerm/resource_arm_logic_app_workflow_test.go @@ -79,7 +79,7 @@ func testCheckAzureRMLogicAppWorkflowExists(name string) resource.TestCheckFunc resp, err := client.Get(ctx, resourceGroup, workflowName) if err != nil { - return fmt.Errorf("Bad: Get on diskClient: %+v", err) + return fmt.Errorf("Bad: Get on logicWorkflowsClient: %+v", err) } if resp.StatusCode == http.StatusNotFound { diff --git a/website/azurerm.erb b/website/azurerm.erb index 08cfd0f04b80..79136d1caebd 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -91,7 +91,11 @@ > azurerm_kubernetes_cluster - + + > + azurerm_logic_app_workflow + + > azurerm_managed_disk diff --git a/website/docs/d/logic_app_workflow.html.markdown b/website/docs/d/logic_app_workflow.html.markdown new file mode 100644 index 000000000000..320c6daa149b --- /dev/null +++ b/website/docs/d/logic_app_workflow.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_logic_app_workflow" +sidebar_current: "docs-azurerm-data-source-logic-app-workflow" +description: |- + Gets information about a Logic App Workflow. +--- + +# Data Source: azurerm_logic_app_workflow + +Gets information about a Logic App Workflow. + +## Example Usage + +```hcl +data "azurerm_logic_app_workflow" "test" { + name = "workflow1" + resource_group_name = "my-resource-group" +} + +output "access_endpoint" { + value = "${data.azurerm_logic_app_workflow.test.access_endpoint}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Logic App Workflow. + +* `resource_group_name` - (Required) The name of the Resource Group in which the Logic App Workflow exists. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Logic App Workflow ID. + +* `location` - The Azure location where the Logic App Workflow exists. + +* `workflow_schema` - The Schema used for this Logic App Workflow. + +* `workflow_version` - The version of the Schema used for this Logic App Workflow. Defaults to `1.0.0.0`. + +* `parameters` - A map of Key-Value pairs. + +* `tags` - A mapping of tags assigned to the resource. + +* `access_endpoint` - The Access Endpoint for the Logic App Workflow diff --git a/website/docs/r/logic_app_workflow.html.markdown b/website/docs/r/logic_app_workflow.html.markdown index 9fb3abc75b2c..d44085fd7684 100644 --- a/website/docs/r/logic_app_workflow.html.markdown +++ b/website/docs/r/logic_app_workflow.html.markdown @@ -35,7 +35,7 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the Logic App Workflow exists. Changing this forces a new resource to be created. -* `workflow_schema` - (Optional) Specifies the Schema to use for this Logic App Workflow. Defaults to `https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#`. Changing this forces a new resource to be create.d +* `workflow_schema` - (Optional) Specifies the Schema to use for this Logic App Workflow. Defaults to `https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#`. Changing this forces a new resource to be created. * `workflow_version` - (Optional) Specifies the version of the Schema used for this Logic App Workflow. Defaults to `1.0.0.0`. Changing this forces a new resource to be create.d