Skip to content

Commit

Permalink
New Resource: azurerm_logic_app_workflow (#1266)
Browse files Browse the repository at this point in the history
* Vendoring the Logic App SDK

* 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

* Upgrading Logic Apps to v18.0.0 of the Azure SDK for Go

* Moving Actions and Triggers out to separate objects

```
$ acctests azurerm TestAccAzureRMLogicAppWorkflow_
=== RUN   TestAccAzureRMLogicAppWorkflow_importEmpty
--- PASS: TestAccAzureRMLogicAppWorkflow_importEmpty (71.95s)
=== RUN   TestAccAzureRMLogicAppWorkflow_importTags
--- PASS: TestAccAzureRMLogicAppWorkflow_importTags (69.51s)
=== RUN   TestAccAzureRMLogicAppWorkflow_empty
--- PASS: TestAccAzureRMLogicAppWorkflow_empty (66.77s)
=== RUN   TestAccAzureRMLogicAppWorkflow_tags
--- PASS: TestAccAzureRMLogicAppWorkflow_tags (81.51s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	289.789s
```

* New Resource: `azurerm_logic_app_action_http`

Tests pass:
```
$ acctests azurerm TestAccAzureRMLogicAppActionHttp_

=== RUN   TestAccAzureRMLogicAppActionHttp_basic
--- PASS: TestAccAzureRMLogicAppActionHttp_basic (65.75s)
=== RUN   TestAccAzureRMLogicAppActionHttp_headers
--- PASS: TestAccAzureRMLogicAppActionHttp_headers (61.97s)
=== RUN   TestAccAzureRMLogicAppActionHttp_disappears
--- PASS: TestAccAzureRMLogicAppActionHttp_disappears (77.38s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	205.136s
```

* New Resources: `azurerm_logic_app_trigger_http_request` / `azurerm_logic_app_trigger_recurrence`

- Adding documentation for all of the resources
- Making the test check functions more generic

* New Resource: `azurerm_logic_app_action_custom`

* New Resource: `azurerm_logic_app_trigger_custom`

* Adding an example of how to use a logic app

* 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
```

* Fixing issues raised during code review

* Adding a customizeDiff for http requests

* Returning an error rather than removing the state
  • Loading branch information
tombuildsstuff committed Jul 17, 2018
1 parent 42e85b3 commit 7a6762b
Show file tree
Hide file tree
Showing 57 changed files with 16,740 additions and 3 deletions.
11 changes: 11 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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/2018-03-01/insights"
"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
Expand Down Expand Up @@ -149,6 +150,9 @@ type ArmClient struct {
keyVaultClient keyvault.VaultsClient
keyVaultManagementClient keyVault.BaseClient

// Logic
logicWorkflowsClient logic.WorkflowsClient

// Monitor
monitorAlertRulesClient insights.AlertRulesClient

Expand Down Expand Up @@ -397,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)
Expand Down Expand Up @@ -732,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)
Expand Down
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) {
return fmt.Errorf("Logic App Workflow %q was not found in Resource Group %q", name, resourceGroup)
}

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)
}
29 changes: 29 additions & 0 deletions azurerm/import_arm_logic_app_action_custom_test.go
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 TestAccAzureRMLogicAppActionCustom_importBasic(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMLogicAppActionCustom_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_action_custom.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
50 changes: 50 additions & 0 deletions azurerm/import_arm_logic_app_action_http_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package azurerm

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMLogicAppActionHttp_importBasic(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMLogicAppActionHttp_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_action_http.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMLogicAppActionHttp_importHeaders(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMLogicAppActionHttp_headers(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: "azurerm_logic_app_action_http.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
29 changes: 29 additions & 0 deletions azurerm/import_arm_logic_app_trigger_custom_test.go
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,
},
},
})
}
Loading

0 comments on commit 7a6762b

Please sign in to comment.