Skip to content

Commit

Permalink
New Data Source: azurerm_logic_app_workflow
Browse files Browse the repository at this point in the history
```
$ 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
```
  • Loading branch information
tombuildsstuff committed Jul 13, 2018
1 parent bafd9da commit fb1580c
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 5 deletions.
108 changes: 108 additions & 0 deletions azurerm/data_source_logic_app_workflow.go
Original file line number Diff line number Diff line change
@@ -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
}
80 changes: 80 additions & 0 deletions azurerm/data_source_logic_app_workflow_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 0 additions & 4 deletions azurerm/resource_arm_logic_app_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_logic_app_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fb1580c

Please sign in to comment.