Skip to content

Commit

Permalink
feat(destinations): add update_original_message to destination conf…
Browse files Browse the repository at this point in the history
…igurations (#2701)
  • Loading branch information
nzur-newrelic authored Jul 9, 2024
1 parent b42dc2d commit 3d498a3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
8 changes: 8 additions & 0 deletions newrelic/resource_newrelic_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func resourceNewRelicWorkflow() *schema.Resource {
Computed: true,
Description: fmt.Sprintf("(Required) The type of the destination. One of: (%s).", strings.Join(listValidWorkflowsDestinationTypes(), ", ")),
},
// Computed
"update_original_message": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: func() (interface{}, error) { return true, nil },
Computed: true,
Description: "Update original notification message (Slack channels only)",
},
},
},
},
Expand Down
60 changes: 59 additions & 1 deletion newrelic/resource_newrelic_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,60 @@ func TestNewRelicWorkflow_WithUpdatedNotificationTriggers(t *testing.T) {
})
}

func TestNewRelicWorkflow_WithCreatedUpdateOriginalMessage(t *testing.T) {
resourceName := "newrelic_workflow.foo"
rName := generateNameForIntegrationTestResource()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
CheckDestroy: testAccNewRelicWorkflowDestroy,
Steps: []resource.TestStep{
// Test: Create workflow
{
Config: testAccNewRelicWorkflowConfigurationWithCustomDestination(testAccountID, rName, `update_original_message = true`),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicWorkflowExists(resourceName),
),
},
// Test: Update workflow
{
Config: testAccNewRelicWorkflowConfigurationWithCustomDestination(testAccountID, fmt.Sprintf("%s-updated", rName), `update_original_message = true`),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicWorkflowExists(resourceName),
),
},
},
})
}

func TestNewRelicWorkflow_WithNonCreatedUpdateOriginalMessage(t *testing.T) {
resourceName := "newrelic_workflow.foo"
rName := generateNameForIntegrationTestResource()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
CheckDestroy: testAccNewRelicWorkflowDestroy,
Steps: []resource.TestStep{
// Test: Create workflow
{
Config: testAccNewRelicWorkflowConfigurationWithCustomDestination(testAccountID, rName, ""),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicWorkflowExists(resourceName),
),
},
// Test: Update workflow
{
Config: testAccNewRelicWorkflowConfigurationWithCustomDestination(testAccountID, fmt.Sprintf("%s-updated", rName), `update_original_message = true`),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicWorkflowExists(resourceName),
),
},
},
})
}

func TestNewRelicWorkflow_BooleanFlags_DisableOnUpdate(t *testing.T) {
channelResourceName := "foo"
workflowName := acctest.RandString(10)
Expand Down Expand Up @@ -566,6 +620,10 @@ func testAccNewRelicWorkflowConfigurationWithNotificationTriggers(accountID int,
if notificationTriggers != "" {
parsedNotificationTriggers = fmt.Sprintf(`notification_triggers = %[1]s`, notificationTriggers)
}
return testAccNewRelicWorkflowConfigurationWithCustomDestination(accountID, name, parsedNotificationTriggers)
}

func testAccNewRelicWorkflowConfigurationWithCustomDestination(accountID int, name string, customDestination string) string {
return fmt.Sprintf(`
resource "newrelic_notification_destination" "foo" {
account_id = %[1]d
Expand Down Expand Up @@ -630,7 +688,7 @@ resource "newrelic_workflow" "foo" {
%[3]s
}
}
`, accountID, name, parsedNotificationTriggers)
`, accountID, name, customDestination)
}

func testAccNewRelicChannelConfigurationEmail(channelResourceName string) string {
Expand Down
11 changes: 11 additions & 0 deletions newrelic/structures_newrelic_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func expandWorkflowDestinationConfiguration(cfg map[string]interface{}) workflow
destinationConfigurationInput.ChannelId = channelID.(string)
}

if updateOriginalMessage, ok := cfg["update_original_message"]; ok {
b := updateOriginalMessage.(bool)
destinationConfigurationInput.UpdateOriginalMessage = &b
}

if notificationTriggers, ok := cfg["notification_triggers"]; ok {
for _, p := range notificationTriggers.([]interface{}) {
notificationTriggersInput = append(notificationTriggersInput, workflows.AiWorkflowsNotificationTrigger(p.(string)))
Expand Down Expand Up @@ -407,6 +412,12 @@ func flattenWorkflowDestinationConfiguration(d *workflows.AiWorkflowsDestination
destinationConfigurationResult["channel_id"] = d.ChannelId
destinationConfigurationResult["name"] = d.Name
destinationConfigurationResult["type"] = d.Type
if currentState == nil || currentState["update_original_message"] == nil {
b := true
destinationConfigurationResult["update_original_message"] = &b
} else {
destinationConfigurationResult["update_original_message"] = d.UpdateOriginalMessage
}

if currentState == nil || currentState["notification_triggers"] == nil {
destinationConfigurationResult["notification_triggers"] = d.NotificationTriggers
Expand Down
2 changes: 2 additions & 0 deletions newrelic/structures_newrelic_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ func testFlattenWorkflowsDestinationConfiguration(t *testing.T, v interface{}, c
assert.Equal(t, cv, string(configuration.Type))
case "notification_triggers":
assert.Equal(t, cv, configuration.NotificationTriggers)
case "update_original_message":
assert.Equal(t, cv, configuration.UpdateOriginalMessage)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/workflow.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ workflow.
Block's arguments:
* `channel_id` - (Required) Id of a [notification_channel](notification_channel.html) to use for notifications. Please note that you have to use a
**notification** channel, not an `alert_channel`.
* `notification_triggers` - (Optional) Issue events to notify on. The value is a list of possible issue events. See [Notification Triggers](#notification-triggers) below for details.
* `notification_triggers` - (Optional) Issue events to notify on. The value is a list of possible issue events. See [Notification Triggers](#notification-triggers) below for details.
* `update_original_message` - (Optional) Update original notification message (Slack channels only).

### Notification Triggers

Expand Down

0 comments on commit 3d498a3

Please sign in to comment.