-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data sources for PagerDuty and email notification channels (#147)
* Add data sources for PagerDuty and email notification channels Part of: #138 * ci: Add extra verification checks * docs: Add documentation for missing data sources * fix(docs): Add line break Co-authored-by: Ryan Moe <ryan.moe@ibm.com> Co-authored-by: Fede Barcelona <fede_rico_94@hotmail.com>
- Loading branch information
1 parent
f824943
commit 50bad8a
Showing
7 changed files
with
309 additions
and
1 deletion.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
sysdig/data_source_sysdig_monitor_notification_channel_email.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package sysdig | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceSysdigMonitorNotificationChannelEmail() *schema.Resource { | ||
timeout := 5 * time.Minute | ||
|
||
return &schema.Resource{ | ||
ReadContext: dataSourceSysdigMonitorNotificationChannelEmailRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(timeout), | ||
}, | ||
|
||
Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ | ||
"recipients": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Computed: true, | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
func dataSourceSysdigMonitorNotificationChannelEmailRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client, err := meta.(SysdigClients).sysdigMonitorClient() | ||
|
||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
nc, err := client.GetNotificationChannelByName(ctx, d.Get("name").(string)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
err = monitorNotificationChannelEmailToResourceData(&nc, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(strconv.Itoa(nc.ID)) | ||
|
||
return nil | ||
} |
54 changes: 54 additions & 0 deletions
54
sysdig/data_source_sysdig_monitor_notification_channel_email_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package sysdig_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/draios/terraform-provider-sysdig/sysdig" | ||
) | ||
|
||
func TestAccNotificationChannelEmailDataSource(t *testing.T) { | ||
rText := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
if v := os.Getenv("SYSDIG_MONITOR_API_TOKEN"); v == "" { | ||
t.Fatal("SYSDIG_MONITOR_API_TOKEN must be set for acceptance tests") | ||
} | ||
}, | ||
ProviderFactories: map[string]func() (*schema.Provider, error){ | ||
"sysdig": func() (*schema.Provider, error) { | ||
return sysdig.Provider(), nil | ||
}, | ||
}, | ||
|
||
Steps: []resource.TestStep{ | ||
{ | ||
Config: notificationChannelEmail(rText), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair("data.sysdig_monitor_notification_channel_email.nc_email", "id", "sysdig_monitor_notification_channel_email.nc_email", "id"), | ||
resource.TestCheckResourceAttrPair("data.sysdig_monitor_notification_channel_email.nc_email", "name", "sysdig_monitor_notification_channel_email.nc_email", "name"), | ||
resource.TestCheckTypeSetElemAttr("data.sysdig_monitor_notification_channel_email.nc_email", "recipients.*", "root@localhost.com"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func notificationChannelEmail(name string) string { | ||
return fmt.Sprintf(` | ||
resource "sysdig_monitor_notification_channel_email" "nc_email" { | ||
name = "%s" | ||
recipients = ["root@localhost.com"] | ||
} | ||
data "sysdig_monitor_notification_channel_email" "nc_email" { | ||
name = sysdig_monitor_notification_channel_email.nc_email.name | ||
} | ||
`, name) | ||
} |
59 changes: 59 additions & 0 deletions
59
sysdig/data_source_sysdig_monitor_notification_channel_pagerduty.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package sysdig | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceSysdigMonitorNotificationChannelPagerduty() *schema.Resource { | ||
timeout := 5 * time.Minute | ||
|
||
return &schema.Resource{ | ||
ReadContext: dataSourceSysdigMonitorNotificationChannelPagerdutyRead, | ||
|
||
Timeouts: &schema.ResourceTimeout{ | ||
Read: schema.DefaultTimeout(timeout), | ||
}, | ||
|
||
Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ | ||
"account": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"service_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"service_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
func dataSourceSysdigMonitorNotificationChannelPagerdutyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client, err := meta.(SysdigClients).sysdigMonitorClient() | ||
|
||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
nc, err := client.GetNotificationChannelByName(ctx, d.Get("name").(string)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
err = monitorNotificationChannelPagerdutyToResourceData(&nc, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(strconv.Itoa(nc.ID)) | ||
|
||
return nil | ||
} |
60 changes: 60 additions & 0 deletions
60
sysdig/data_source_sysdig_monitor_notification_channel_pagerduty_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package sysdig_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/draios/terraform-provider-sysdig/sysdig" | ||
) | ||
|
||
func TestAccNotificationChannelPagerdutyDataSource(t *testing.T) { | ||
rText := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
if v := os.Getenv("SYSDIG_MONITOR_API_TOKEN"); v == "" { | ||
t.Fatal("SYSDIG_MONITOR_API_TOKEN must be set for acceptance tests") | ||
} | ||
}, | ||
ProviderFactories: map[string]func() (*schema.Provider, error){ | ||
"sysdig": func() (*schema.Provider, error) { | ||
return sysdig.Provider(), nil | ||
}, | ||
}, | ||
|
||
Steps: []resource.TestStep{ | ||
{ | ||
Config: notificationChannelPagerduty(rText), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "name", "sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "name"), | ||
resource.TestCheckResourceAttrPair("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "account", "sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "account"), | ||
resource.TestCheckResourceAttrPair("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "service_key", "sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "service_key"), | ||
resource.TestCheckResourceAttrPair("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "service_name", "sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "service_name"), | ||
resource.TestCheckResourceAttr("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "account", "account"), | ||
resource.TestCheckResourceAttr("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "service_key", "XXXXXXXXXX"), | ||
resource.TestCheckResourceAttr("data.sysdig_monitor_notification_channel_pagerduty.nc_pagerduty", "service_name", "sysdig"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func notificationChannelPagerduty(name string) string { | ||
return fmt.Sprintf(` | ||
resource "sysdig_monitor_notification_channel_pagerduty" "nc_pagerduty" { | ||
name = "%s" | ||
account = "account" | ||
service_key = "XXXXXXXXXX" | ||
service_name = "sysdig" | ||
} | ||
data "sysdig_monitor_notification_channel_pagerduty" "nc_pagerduty" { | ||
name = sysdig_monitor_notification_channel_pagerduty.nc_pagerduty.name | ||
} | ||
`, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
subcategory: "Sysdig Monitor" | ||
layout: "sysdig" | ||
page_title: "Sysdig: sysdig_monitor_notification_channel_email" | ||
description: |- | ||
Retrieves information about a Monitor notification channel of type Email | ||
--- | ||
|
||
# Data Source: sysdig_monitor_notification_channel_email | ||
|
||
Retrieves information about a Monitor notification channel of type Email | ||
|
||
`~> **Note:** Sysdig Terraform Provider is under rapid development at this point. If you experience any issue or discrepancy while using it, please make sure you have the latest version. If the issue persists, or you have a Feature Request to support an additional set of resources, please open a [new issue](https://github.com/sysdiglabs/terraform-provider-sysdig/issues/new) in the GitHub repository.` | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "sysdig_monitor_notification_channel_email" "nc_email" { | ||
name = "some notification channel name" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the Notification Channel to retrieve. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The Notification Channel ID. | ||
* `name` - The Notification Channel Name. | ||
* `recipients` - List of recipients that will receive the message. | ||
* `enabled` - Whether the Notification Channel is active or not. | ||
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered. | ||
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a | ||
user. | ||
* `version` - The version of the Notification Channel. | ||
* `send_test_notification` - Whether the Notification Channel has enabled the test notification. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
subcategory: "Sysdig Monitor" | ||
layout: "sysdig" | ||
page_title: "Sysdig: sysdig_monitor_notification_channel_pagerduty" | ||
description: |- | ||
Retrieves information about a Monitor notification channel of type Pagerduty | ||
--- | ||
|
||
# Data Source: sysdig_monitor_notification_channel_pagerduty | ||
|
||
Retrieves information about a Monitor notification channel of type Pagerduty | ||
|
||
`~> **Note:** Sysdig Terraform Provider is under rapid development at this point. If you experience any issue or discrepancy while using it, please make sure you have the latest version. If the issue persists, or you have a Feature Request to support an additional set of resources, please open a [new issue](https://github.com/sysdiglabs/terraform-provider-sysdig/issues/new) in the GitHub repository.` | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "sysdig_monitor_notification_channel_pagerduty" "nc_pagerduty" { | ||
name = "some notification channel name" | ||
} | ||
``` | ||
|
||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the Notification Channel to retrieve. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The Notification Channel ID. | ||
* `name` - The Notification Channel Name. | ||
* `account` - Pagerduty account. | ||
* `service_key` - Service Key for the Pagerduty account. | ||
* `service_name` - Service name for the Pagerduty account. | ||
* `enabled` - Whether the Notification Channel is active or not. | ||
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered. | ||
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a | ||
user. | ||
* `version` - The version of the Notification Channel. | ||
* `send_test_notification` - Whether the Notification Channel has enabled the test notification. |