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: jira_add_comment #149

Merged
merged 3 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions docs/resources/automation_rule_jira_add_comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "wiz_automation_rule_jira_add_comment Resource - terraform-provider-wiz"
subcategory: ""
description: |-
Automation Rules define associations between actions and findings.
---

# wiz_automation_rule_jira_add_comment (Resource)

Automation Rules define associations between actions and findings.

## Example Usage

```terraform
resource "wiz_integration_jira" "default" {
name = "default"
jira_url = var.jira_url
jira_username = var.jira_username
jira_password = var.jira_password
scope = "All Resources, Restrict this Integration to global roles only"
}

resource "wiz_automation_rule_jira_add_comment" "example" {
name = "example"
description = "example description"
enabled = true
integration_id = wiz_integration_jira.default.id
trigger_source = "ISSUES"
trigger_type = [
"RESOLVED",
]
filters = jsonencode({
"severity" : [
"CRITICAL"
]
})
jira_project_key = "PROJ"
jira_comment = "Comment from Wiz"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `filters` (String) Value should be wrapped in jsonencode() to avoid diff detection. This is required even though the API states it is not required. Validate is performed by the UI.
- `integration_id` (String) Wiz identifier for the Integration to leverage for this action. Must be resource type integration_jira.
- `name` (String) Name of the automation rule
- `trigger_source` (String) Trigger source.
- Allowed values:
- ISSUES
- CLOUD_EVENTS
- CONTROL
- CONFIGURATION_FINDING
- `trigger_type` (List of String) Trigger type. Must be set to `CREATED` for wiz_automation_rule_jira_add_comment.
- Allowed values:
- CREATED
- UPDATED
- RESOLVED
- REOPENED

### Optional

- `description` (String) Description of the automation rule
- `enabled` (Boolean) Enabled?
- Defaults to `true`.
- `jira_add_issues_report` (Boolean) Whether or not to attach a report on all open issues as an attachment to ticket, only relevant in CONTROL triggered actions
- Defaults to `false`.
- `jira_comment` (String) Issue Jira comment
- `jira_project_key` (String) Issue project
- `project_id` (String) Wiz internal ID for a project.

### Read-Only

- `action_id` (String) Wiz internal ID for the action.
- `created_at` (String) The date/time at which the automation rule was created.
- `id` (String) Wiz internal identifier.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "wiz_integration_jira" "default" {
name = "default"
jira_url = var.jira_url
jira_username = var.jira_username
jira_password = var.jira_password
scope = "All Resources, Restrict this Integration to global roles only"
}

resource "wiz_automation_rule_jira_add_comment" "example" {
name = "example"
description = "example description"
enabled = true
integration_id = wiz_integration_jira.default.id
trigger_source = "ISSUES"
trigger_type = [
"RESOLVED",
]
filters = jsonencode({
"severity" : [
"CRITICAL"
]
})
jira_project_key = "PROJ"
jira_comment = "Comment from Wiz"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package acceptance

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccResourceWizAutomationRuleJiraAddComment_basic(t *testing.T) {
rName := acctest.RandomWithPrefix(ResourcePrefix)

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, TestCase(TcServiceNow)) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testResourceWizAutomationRuleJiraAddCommentBasic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"wiz_integration_jira.foo",
"name",
rName,
),
resource.TestCheckResourceAttr(
"wiz_automation_rule_jira_add_comment.foo",
"name",
rName,
),
resource.TestCheckResourceAttr(
"wiz_automation_rule_jira_add_comment.foo",
"description",
"Provider Acceptance Test",
),
resource.TestCheckResourceAttr(
"wiz_automation_rule_jira_add_comment.foo",
"enabled",
"false",
),
resource.TestCheckResourceAttr(
"wiz_automation_rule_jira_add_comment.foo",
"trigger_source",
"CONTROL",
),
resource.TestCheckResourceAttr(
"wiz_automation_rule_jira_add_comment.foo",
"trigger_type.#",
"1",
),
resource.TestCheckTypeSetElemAttr(
"wiz_automation_rule_jira_add_comment.foo",
"trigger_type.*",
"UPDATED",
),
resource.TestCheckResourceAttrPair(
"wiz_integration_jira.foo",
"id",
"wiz_automation_rule_jira_add_comment.foo",
"integration_id",
),
resource.TestCheckResourceAttrPair(
"wiz_integration_jira.foo",
"jira_project_key",
"wiz_automation_rule_jira_add_comment.foo",
os.Getenv("WIZ_INTEGRATION_JIRA_PROJECT"),
),
resource.TestCheckResourceAttrPair(
"wiz_integration_jira.foo",
"jira_comment",
"wiz_automation_rule_jira_add_comment.foo",
"Comment added via Wiz automation",
),
resource.TestCheckResourceAttrPair(
"wiz_integration_jira.foo",
"jira_add_issues_report",
"wiz_automation_rule_jira_add_comment.foo",
"false",
),
),
},
},
})
}

func testResourceWizAutomationRuleJiraAddCommentBasic(rName string) string {
return fmt.Sprintf(`
resource "wiz_integration_jira" "foo" {
name = "%s"
scope = "All Resources, Restrict this Integration to global roles only"
}

resource "wiz_automation_rule_jira_add_comment" "foo" {
name = "%s"
description = "Provider Acceptance Test"
enabled = false
integration_id = wiz_integration_jira.foo.id
trigger_source = "CONTROL"
trigger_type = [
"UPDATED",
]
filters = jsonencode({
"severity": [
"CRITICAL"
]
})
jira_project_key = "%s"
jira_comment = "Comment added via Wiz automation"
jira_add_issues_report = false
}
`, rName, rName, os.Getenv("WIZ_INTEGRATION_JIRA_PROJECT"))
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ yLyKQXhw2W2Xs0qLeC1etA+jTGDK4UfLeC0SF7FSi8o5LL21L8IzApar2pR/
"wiz_automation_rule_aws_sns": resourceWizAutomationRuleAwsSns(),
"wiz_automation_rule_servicenow_create_ticket": resourceWizAutomationRuleServiceNowCreateTicket(),
"wiz_automation_rule_servicenow_update_ticket": resourceWizAutomationRuleServiceNowUpdateTicket(),
"wiz_automation_rule_jira_add_comment": resourceWizAutomationRuleJiraAddComment(),
"wiz_automation_rule_jira_create_ticket": resourceWizAutomationRuleJiraCreateTicket(),
"wiz_cicd_scan_policy": resourceWizCICDScanPolicy(),
"wiz_cloud_config_rule": resourceWizCloudConfigurationRule(),
Expand Down
Loading