Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource: azurerm_logic_app_workflow #1266

Merged
merged 13 commits into from
Jul 17, 2018
Merged

New Resource: azurerm_logic_app_workflow #1266

merged 13 commits into from
Jul 17, 2018

Conversation

tombuildsstuff
Copy link
Contributor

@tombuildsstuff tombuildsstuff commented May 21, 2018

This PR adds support for Logic Apps. After initially making this a huge self-contained resource, I've pivoted to adding split-out resources for the Actions and Triggers. This allows us to provide better Diff's for specific actions, whilst still allowing for custom Actions and Triggers via the _custom suffixed resources.

Adds the following resources:

* **New Data Source:** `azurerm_logic_app_workflow` [GH-1266]
* **New Resource:** `azurerm_logic_app_action_custom` [GH-1266]
* **New Resource:** `azurerm_logic_app_action_http` [GH-1266]
* **New Resource:** `azurerm_logic_app_trigger_custom` [GH-1266]
* **New Resource:** `azurerm_logic_app_trigger_http_request` [GH-1266]
* **New Resource:** `azurerm_logic_app_trigger_recurrence` [GH-1266]
* **New Resource:** `azurerm_logic_app_workflow` [GH-1266]

Fixes #610

@tombuildsstuff tombuildsstuff added this to the 1.6.0 milestone May 21, 2018
@tombuildsstuff tombuildsstuff changed the title New Resource: azurerm_logic_app_workspace New Resource: azurerm_logic_app_workflow May 21, 2018
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"recurrence": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are so many other triggers than recurrence trigger. https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-actions-triggers

Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be more than 1 actions.

Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 is not enough.


"resource_group_name": resourceGroupNameSchema(),

"parameters": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two different parameters here. One is the workflow parameter, the other is the definition parameter.


_, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties)
if err != nil {
return err
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message is not consistent with other return statements. Provide more detailed info.


read, err := client.Get(ctx, resourceGroup, name)
if err != nil {
return err
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine error message here.


id, err := parseAzureResourceID(d.Id())
if err != nil {
return err

This comment was marked as outdated.


id, err := parseAzureResourceID(d.Id())
if err != nil {
return err

This comment was marked as outdated.

@tombuildsstuff
Copy link
Contributor Author

Tests pass:

screenshot 2018-07-10 at 16 05 12

@tombuildsstuff tombuildsstuff force-pushed the logic-apps branch 2 times, most recently from fb1580c to 44d75bd Compare July 13, 2018 09:51
@tombuildsstuff tombuildsstuff requested a review from a team July 15, 2018 11:42
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback given below, but I do not think anything is blocking 👍

if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this data source be returning an error here?

Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogicAppWorkflowExists(dataSourceName),
resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: should we use resource.TestCheckResourceAttrPair() for these rather than hardcoding the expectations?

Copy link
Contributor Author

@tombuildsstuff tombuildsstuff Jul 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an enhancement we should make, but across all resources (since a lot of tests follow this pattern); going to skip this for now.

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

func TestAccAzureRMLogicAppActionCustom_importBasic(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point for consideration: In AWS-land, we've been adding the import TestStep directly to the pertinent acceptance tests to reduce:

  • Indirection/missed tests with having a separate test file
  • File sprawl (relating to above)
  • Creating 2x the same resources for testing (potentially more false positives)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to that approach (we've started doing it for some resources) - but I think that's a larger project outside the scope of this PR - so I'm going to skip this for now.

read, err := client.Get(ctx, resourceGroup, logicAppName)
if err != nil {
if utils.ResponseWasNotFound(read.Response) {
d.SetId("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should print a log message when removing from state, e.g. log.Printf("[WARN] Logic App (%s) not found, removing from state", d.Id())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on reflection this should be returning an error, since this is the Create method for a sub-resource (updated)

}

if read.WorkflowProperties == nil {
return fmt.Errorf("[ERROR] Error parsing Logic App Workflow - `WorkflowProperties` is nil")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a corrective action possible here, even if that means stating that the API response was unexpected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, if this happens the API's returning data that doesn't confirm to the schema - so this is to prevent crashes

return fmt.Errorf("Not found: %s", name)
}

logicAppId := rs.Primary.Attributes["logic_app_id"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be coming from rs.Primary.ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could parse it out of that, but this is a Terraform internal ID (from {logicAppID}/{type}/{name}) so I don't think that gains us anything in this instance

return nil
}

func validateLogicAppTriggerHttpRequestRelativePath(v interface{}, k string) (ws []string, errors []error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be replaced with validation.ValidateRegexp()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so that function checks the string itself is a valid regex, rather than testing for a specific regex; whilst I thought we had a validate method for that I couldn't seem to find it (although I may have missed it)?

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
location := azureRMNormalizeLocation(d.Get("location").(string))
parameters := expandLogicAppWorkflowParameters(d)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we generally prefer to be more explicit with our expand methods if possible (making it support map[string]interface{} instead). Passing the raw *schema.ResourceData could introduce subtle maintenance issues, especially if its used across multiple resources.

return fmt.Errorf("[ERROR] Error creating Logic App Workflow %q (Resource Group %q): %+v", name, resourceGroup, err)
}

read, err := client.Get(ctx, resourceGroup, name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this SDK read here is necessary because the SDK create function does not provide the ID -- it feels extraneous to do this and should probably be avoided if possible (e.g. generate the ID from given arguments). The resource read function can catch non-existent IDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do this across the provider since the URI used for Create doesn't always match the URI used for Get, unfortunately

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here where we should provide logging message when removing resource from state.

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
```
$ 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
```
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
```
…gic_app_trigger_recurrence`

- Adding documentation for all of the resources
- Making the test check functions more generic
```
$ 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
```
@tombuildsstuff
Copy link
Contributor Author

Tests pass:

screenshot 2018-07-17 at 13 29 54

@tombuildsstuff tombuildsstuff merged commit 7a6762b into master Jul 17, 2018
@tombuildsstuff tombuildsstuff deleted the logic-apps branch July 17, 2018 11:34
tombuildsstuff added a commit that referenced this pull request Jul 17, 2018
tombuildsstuff added a commit that referenced this pull request Jul 17, 2018
@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Logic App Resource
3 participants