diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 628753d5..0580bc83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,6 +105,7 @@ jobs: SYSDIG_IBM_MONITOR_INSTANCE_ID: ${{ secrets.TERRAFORM_IBM_MONITOR_INSTANCE_ID }} SYSDIG_IBM_MONITOR_IAM_URL: "https://iam.cloud.ibm.com" SYSDIG_MONITOR_URL: "https://eu-gb.monitoring.cloud.ibm.com" + IBM_EVENT_NOTIFICATION_INSTANCE_ID: ${{ secrets.IBM_EVENT_NOTIFICATION_INSTANCE_ID }} test-ibm-secure: name: IBM Secure Acceptance Tests diff --git a/sysdig/data_source_sysdig_secure_notification_channel.go b/sysdig/data_source_sysdig_secure_notification_channel.go index fa231044..a041e160 100644 --- a/sysdig/data_source_sysdig_secure_notification_channel.go +++ b/sysdig/data_source_sysdig_secure_notification_channel.go @@ -12,14 +12,20 @@ import ( ) const ( - NOTIFICATION_CHANNEL_TYPE_EMAIL = "EMAIL" - NOTIFICATION_CHANNEL_TYPE_AMAZON_SNS = "SNS" - NOTIFICATION_CHANNEL_TYPE_OPSGENIE = "OPSGENIE" - NOTIFICATION_CHANNEL_TYPE_VICTOROPS = "VICTOROPS" - NOTIFICATION_CHANNEL_TYPE_WEBHOOK = "WEBHOOK" - NOTIFICATION_CHANNEL_TYPE_SLACK = "SLACK" - NOTIFICATION_CHANNEL_TYPE_PAGERDUTY = "PAGER_DUTY" - NOTIFICATION_CHANNEL_TYPE_MS_TEAMS = "MS_TEAMS" + NOTIFICATION_CHANNEL_TYPE_EMAIL = "EMAIL" + NOTIFICATION_CHANNEL_TYPE_AMAZON_SNS = "SNS" + NOTIFICATION_CHANNEL_TYPE_OPSGENIE = "OPSGENIE" + NOTIFICATION_CHANNEL_TYPE_VICTOROPS = "VICTOROPS" + NOTIFICATION_CHANNEL_TYPE_WEBHOOK = "WEBHOOK" + NOTIFICATION_CHANNEL_TYPE_SLACK = "SLACK" + NOTIFICATION_CHANNEL_TYPE_PAGERDUTY = "PAGER_DUTY" + NOTIFICATION_CHANNEL_TYPE_MS_TEAMS = "MS_TEAMS" + NOTIFICATION_CHANNEL_TYPE_GCHAT = "GCHAT" + NOTIFICATION_CHANNEL_TYPE_PROMETHEUS_ALERT_MANAGER = "PROMETHEUS_ALERT_MANAGER" + NOTIFICATION_CHANNEL_TYPE_TEAM_EMAIL = "TEAM_EMAIL" + NOTIFICATION_CHANNEL_TYPE_CUSTOM_WEBHOOK = "POWER_WEBHOOK" + NOTIFICATION_CHANNEL_TYPE_IBM_EVENT_NOTIFICATION = "IBM_EVENT_NOTIFICATIONS" + NOTIFICATION_CHANNEL_TYPE_IBM_FUNCTION = "IBM_FUNCTION" NOTIFICATION_CHANNEL_TYPE_SLACK_TEMPLATE_KEY_V1 = "SLACK_SECURE_EVENT_NOTIFICATION_TEMPLATE_METADATA_v1" NOTIFICATION_CHANNEL_TYPE_SLACK_TEMPLATE_KEY_V2 = "SLACK_SECURE_EVENT_NOTIFICATION_TEMPLATE_METADATA_v2" diff --git a/sysdig/internal/client/v2/model.go b/sysdig/internal/client/v2/model.go index 5ff906a2..e7f5db0d 100644 --- a/sysdig/internal/client/v2/model.go +++ b/sysdig/internal/client/v2/model.go @@ -105,18 +105,25 @@ type NotificationChannelTemplateConfiguration struct { } type NotificationChannelOptions struct { - EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email - SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS - APIKey string `json:"apiKey,omitempty"` // Type: VictorOps - RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps - Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack - Channel string `json:"channel,omitempty"` // Type: Slack - Account string `json:"account,omitempty"` // Type: PagerDuty - ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty - ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty - AdditionalHeaders map[string]interface{} `json:"additionalHeaders,omitempty"` // Type: Webhook - Region string `json:"region,omitempty"` // Type: OpsGenie - TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` + EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email + SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS + APIKey string `json:"apiKey,omitempty"` // Type: VictorOps, ibm event function + RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps + Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook, Slack, google chat, prometheus alert manager, custom webhook + Channel string `json:"channel,omitempty"` // Type: Slack + Account string `json:"account,omitempty"` // Type: PagerDuty + ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty + ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty + AdditionalHeaders map[string]interface{} `json:"additionalHeaders,omitempty"` // Type: Webhook, prometheus alert manager, custom webhook, ibm function + Region string `json:"region,omitempty"` // Type: OpsGenie + AllowInsecureConnections *bool `json:"allowInsecureConnections,omitempty"` // Type: prometheus alert manager, custom webhook + TeamId int `json:"teamId,omitempty"` // Type: team email + HttpMethod string `json:"httpMethod,omitempty"` // Type: custom webhook + MonitorTemplate string `json:"monitorTemplate,omitempty"` // Type: custom webhook + InstanceId string `json:"instanceId,omitempty"` // Type: ibm event notification + IbmFunctionType string `json:"ibmFunctionType,omitempty"` // Type: ibm event function + CustomData map[string]interface{} `json:"customData,omitempty"` // Type: ibm function + TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` NotifyOnOk bool `json:"notifyOnOk"` NotifyOnResolve bool `json:"notifyOnResolve"` diff --git a/sysdig/internal/client/v2/notification_channels.go b/sysdig/internal/client/v2/notification_channels.go index 713dfbfa..44ee8a9c 100644 --- a/sysdig/internal/client/v2/notification_channels.go +++ b/sysdig/internal/client/v2/notification_channels.go @@ -2,6 +2,7 @@ package v2 import ( "context" + "errors" "fmt" "net/http" ) @@ -11,6 +12,8 @@ const ( GetNotificationChannel = "%s/api/notificationChannels/%d" ) +var NotificationChannelNotFound = errors.New("notification channel not found") + type NotificationChannelInterface interface { Base GetNotificationChannelById(ctx context.Context, id int) (NotificationChannel, error) @@ -27,6 +30,9 @@ func (client *Client) GetNotificationChannelById(ctx context.Context, id int) (N } defer response.Body.Close() + if response.StatusCode == http.StatusNotFound { + return NotificationChannel{}, NotificationChannelNotFound + } if response.StatusCode != http.StatusOK { return NotificationChannel{}, client.ErrorFromResponse(response) } diff --git a/sysdig/provider.go b/sysdig/provider.go index 9f5d3d3d..b7fb68d4 100644 --- a/sysdig/provider.go +++ b/sysdig/provider.go @@ -105,55 +105,63 @@ func Provider() *schema.Provider { "sysdig_custom_role": resourceSysdigCustomRole(), "sysdig_team_service_account": resourceSysdigTeamServiceAccount(), - "sysdig_secure_custom_policy": resourceSysdigSecureCustomPolicy(), - "sysdig_secure_managed_policy": resourceSysdigSecureManagedPolicy(), - "sysdig_secure_managed_ruleset": resourceSysdigSecureManagedRuleset(), - "sysdig_secure_policy": resourceSysdigSecurePolicy(), - "sysdig_secure_notification_channel_email": resourceSysdigSecureNotificationChannelEmail(), - "sysdig_secure_notification_channel_sns": resourceSysdigSecureNotificationChannelSNS(), - "sysdig_secure_notification_channel_opsgenie": resourceSysdigSecureNotificationChannelOpsGenie(), - "sysdig_secure_notification_channel_victorops": resourceSysdigSecureNotificationChannelVictorOps(), - "sysdig_secure_notification_channel_webhook": resourceSysdigSecureNotificationChannelWebhook(), - "sysdig_secure_notification_channel_slack": resourceSysdigSecureNotificationChannelSlack(), - "sysdig_secure_notification_channel_pagerduty": resourceSysdigSecureNotificationChannelPagerduty(), - "sysdig_secure_notification_channel_msteams": resourceSysdigSecureNotificationChannelMSTeams(), - "sysdig_secure_rule_container": resourceSysdigSecureRuleContainer(), - "sysdig_secure_rule_filesystem": resourceSysdigSecureRuleFilesystem(), - "sysdig_secure_rule_network": resourceSysdigSecureRuleNetwork(), - "sysdig_secure_rule_process": resourceSysdigSecureRuleProcess(), - "sysdig_secure_rule_syscall": resourceSysdigSecureRuleSyscall(), - "sysdig_secure_rule_falco": resourceSysdigSecureRuleFalco(), - "sysdig_secure_team": resourceSysdigSecureTeam(), - "sysdig_secure_list": resourceSysdigSecureList(), - "sysdig_secure_macro": resourceSysdigSecureMacro(), - "sysdig_secure_vulnerability_exception": resourceSysdigSecureVulnerabilityException(), - "sysdig_secure_vulnerability_exception_list": resourceSysdigSecureVulnerabilityExceptionList(), - "sysdig_secure_cloud_account": resourceSysdigSecureCloudAccount(), - "sysdig_secure_scanning_policy": resourceSysdigSecureScanningPolicy(), - "sysdig_secure_scanning_policy_assignment": resourceSysdigSecureScanningPolicyAssignment(), + "sysdig_secure_custom_policy": resourceSysdigSecureCustomPolicy(), + "sysdig_secure_managed_policy": resourceSysdigSecureManagedPolicy(), + "sysdig_secure_managed_ruleset": resourceSysdigSecureManagedRuleset(), + "sysdig_secure_policy": resourceSysdigSecurePolicy(), + "sysdig_secure_notification_channel_email": resourceSysdigSecureNotificationChannelEmail(), + "sysdig_secure_notification_channel_sns": resourceSysdigSecureNotificationChannelSNS(), + "sysdig_secure_notification_channel_opsgenie": resourceSysdigSecureNotificationChannelOpsGenie(), + "sysdig_secure_notification_channel_victorops": resourceSysdigSecureNotificationChannelVictorOps(), + "sysdig_secure_notification_channel_webhook": resourceSysdigSecureNotificationChannelWebhook(), + "sysdig_secure_notification_channel_slack": resourceSysdigSecureNotificationChannelSlack(), + "sysdig_secure_notification_channel_pagerduty": resourceSysdigSecureNotificationChannelPagerduty(), + "sysdig_secure_notification_channel_prometheus_alert_manager": resourceSysdigSecureNotificationChannelPrometheusAlertManager(), + "sysdig_secure_notification_channel_team_email": resourceSysdigSecureNotificationChannelTeamEmail(), + "sysdig_secure_notification_channel_msteams": resourceSysdigSecureNotificationChannelMSTeams(), + "sysdig_secure_rule_container": resourceSysdigSecureRuleContainer(), + "sysdig_secure_rule_filesystem": resourceSysdigSecureRuleFilesystem(), + "sysdig_secure_rule_network": resourceSysdigSecureRuleNetwork(), + "sysdig_secure_rule_process": resourceSysdigSecureRuleProcess(), + "sysdig_secure_rule_syscall": resourceSysdigSecureRuleSyscall(), + "sysdig_secure_rule_falco": resourceSysdigSecureRuleFalco(), + "sysdig_secure_team": resourceSysdigSecureTeam(), + "sysdig_secure_list": resourceSysdigSecureList(), + "sysdig_secure_macro": resourceSysdigSecureMacro(), + "sysdig_secure_vulnerability_exception": resourceSysdigSecureVulnerabilityException(), + "sysdig_secure_vulnerability_exception_list": resourceSysdigSecureVulnerabilityExceptionList(), + "sysdig_secure_cloud_account": resourceSysdigSecureCloudAccount(), + "sysdig_secure_scanning_policy": resourceSysdigSecureScanningPolicy(), + "sysdig_secure_scanning_policy_assignment": resourceSysdigSecureScanningPolicyAssignment(), - "sysdig_monitor_alert_downtime": resourceSysdigMonitorAlertDowntime(), - "sysdig_monitor_alert_metric": resourceSysdigMonitorAlertMetric(), - "sysdig_monitor_alert_event": resourceSysdigMonitorAlertEvent(), - "sysdig_monitor_alert_anomaly": resourceSysdigMonitorAlertAnomaly(), - "sysdig_monitor_alert_group_outlier": resourceSysdigMonitorAlertGroupOutlier(), - "sysdig_monitor_alert_promql": resourceSysdigMonitorAlertPromql(), - "sysdig_monitor_alert_v2_event": resourceSysdigMonitorAlertV2Event(), - "sysdig_monitor_alert_v2_metric": resourceSysdigMonitorAlertV2Metric(), - "sysdig_monitor_alert_v2_downtime": resourceSysdigMonitorAlertV2Downtime(), - "sysdig_monitor_alert_v2_prometheus": resourceSysdigMonitorAlertV2Prometheus(), - "sysdig_monitor_dashboard": resourceSysdigMonitorDashboard(), - "sysdig_monitor_notification_channel_email": resourceSysdigMonitorNotificationChannelEmail(), - "sysdig_monitor_notification_channel_opsgenie": resourceSysdigMonitorNotificationChannelOpsGenie(), - "sysdig_monitor_notification_channel_pagerduty": resourceSysdigMonitorNotificationChannelPagerduty(), - "sysdig_monitor_notification_channel_slack": resourceSysdigMonitorNotificationChannelSlack(), - "sysdig_monitor_notification_channel_sns": resourceSysdigMonitorNotificationChannelSNS(), - "sysdig_monitor_notification_channel_victorops": resourceSysdigMonitorNotificationChannelVictorOps(), - "sysdig_monitor_notification_channel_webhook": resourceSysdigMonitorNotificationChannelWebhook(), - "sysdig_monitor_notification_channel_msteams": resourceSysdigMonitorNotificationChannelMSTeams(), - "sysdig_monitor_team": resourceSysdigMonitorTeam(), - "sysdig_monitor_cloud_account": resourceSysdigMonitorCloudAccount(), - "sysdig_secure_posture_zone": resourceSysdigSecurePostureZone(), + "sysdig_monitor_alert_downtime": resourceSysdigMonitorAlertDowntime(), + "sysdig_monitor_alert_metric": resourceSysdigMonitorAlertMetric(), + "sysdig_monitor_alert_event": resourceSysdigMonitorAlertEvent(), + "sysdig_monitor_alert_anomaly": resourceSysdigMonitorAlertAnomaly(), + "sysdig_monitor_alert_group_outlier": resourceSysdigMonitorAlertGroupOutlier(), + "sysdig_monitor_alert_promql": resourceSysdigMonitorAlertPromql(), + "sysdig_monitor_alert_v2_event": resourceSysdigMonitorAlertV2Event(), + "sysdig_monitor_alert_v2_metric": resourceSysdigMonitorAlertV2Metric(), + "sysdig_monitor_alert_v2_downtime": resourceSysdigMonitorAlertV2Downtime(), + "sysdig_monitor_alert_v2_prometheus": resourceSysdigMonitorAlertV2Prometheus(), + "sysdig_monitor_dashboard": resourceSysdigMonitorDashboard(), + "sysdig_monitor_notification_channel_email": resourceSysdigMonitorNotificationChannelEmail(), + "sysdig_monitor_notification_channel_opsgenie": resourceSysdigMonitorNotificationChannelOpsGenie(), + "sysdig_monitor_notification_channel_pagerduty": resourceSysdigMonitorNotificationChannelPagerduty(), + "sysdig_monitor_notification_channel_slack": resourceSysdigMonitorNotificationChannelSlack(), + "sysdig_monitor_notification_channel_sns": resourceSysdigMonitorNotificationChannelSNS(), + "sysdig_monitor_notification_channel_victorops": resourceSysdigMonitorNotificationChannelVictorOps(), + "sysdig_monitor_notification_channel_webhook": resourceSysdigMonitorNotificationChannelWebhook(), + "sysdig_monitor_notification_channel_msteams": resourceSysdigMonitorNotificationChannelMSTeams(), + "sysdig_monitor_notification_channel_google_chat": resourceSysdigMonitorNotificationChannelGoogleChat(), + "sysdig_monitor_notification_channel_prometheus_alert_manager": resourceSysdigMonitorNotificationChannelPrometheusAlertManager(), + "sysdig_monitor_notification_channel_team_email": resourceSysdigMonitorNotificationChannelTeamEmail(), + "sysdig_monitor_notification_channel_custom_webhook": resourceSysdigMonitorNotificationChannelCustomWebhook(), + "sysdig_monitor_notification_channel_ibm_event_notification": resourceSysdigMonitorNotificationChannelIBMEventNotification(), + "sysdig_monitor_notification_channel_ibm_function": resourceSysdigMonitorNotificationChannelIBMFunction(), + "sysdig_monitor_team": resourceSysdigMonitorTeam(), + "sysdig_monitor_cloud_account": resourceSysdigMonitorCloudAccount(), + "sysdig_secure_posture_zone": resourceSysdigSecurePostureZone(), }, DataSourcesMap: map[string]*schema.Resource{ "sysdig_secure_trusted_cloud_identity": dataSourceSysdigSecureTrustedCloudIdentity(), diff --git a/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook.go b/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook.go new file mode 100644 index 00000000..8b462738 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook.go @@ -0,0 +1,187 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceSysdigMonitorNotificationChannelCustomWebhook() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigMonitorNotificationChannelCustomWebhookCreate, + UpdateContext: resourceSysdigMonitorNotificationChannelCustomWebhookUpdate, + ReadContext: resourceSysdigMonitorNotificationChannelCustomWebhookRead, + DeleteContext: resourceSysdigMonitorNotificationChannelCustomWebhookDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ + "url": { + Type: schema.TypeString, + Required: true, + }, + "http_method": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"POST", "PUT", "PATCH", "DELETE"}, false), + }, + "template": { + Type: schema.TypeString, + Required: true, + }, + "allow_insecure_connections": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "additional_headers": { + Type: schema.TypeMap, + Optional: true, + }, + }), + } +} + +func resourceSysdigMonitorNotificationChannelCustomWebhookCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + clients := meta.(SysdigClients) + client, err := getMonitorNotificationChannelClient(clients) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := monitorNotificationChannelCustomWebhookFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigMonitorNotificationChannelCustomWebhookRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelCustomWebhookRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = monitorNotificationChannelCustomWebhookToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelCustomWebhookUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := monitorNotificationChannelCustomWebhookFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, _ = strconv.Atoi(d.Id()) + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelCustomWebhookDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func monitorNotificationChannelCustomWebhookFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = monitorNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_CUSTOM_WEBHOOK + nc.Options.Url = d.Get("url").(string) + nc.Options.HttpMethod = d.Get("http_method").(string) + nc.Options.MonitorTemplate = d.Get("template").(string) + nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + allowInsecureConnections := d.Get("allow_insecure_connections").(bool) + nc.Options.AllowInsecureConnections = &allowInsecureConnections + return +} + +func monitorNotificationChannelCustomWebhookToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = monitorNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("url", nc.Options.Url) + _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + _ = d.Set("http_method", nc.Options.HttpMethod) + _ = d.Set("template", nc.Options.MonitorTemplate) + if nc.Options.AllowInsecureConnections != nil { + _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) + } + + return +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook_test.go b/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook_test.go new file mode 100644 index 00000000..5411fa20 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook_test.go @@ -0,0 +1,147 @@ +//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccMonitorNotificationChannelCustomWebhook(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: sysdigOrIBMMonitorPreCheck(t), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: monitorNotificationChannelCustomWebhookWithName(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelCustomWebhookWithNameWithAdditionalheaders(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook2", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelCustomWebhookSharedWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook3", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelCustomWebhookSharedWithAllowInsecureConnections(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook4", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelCustomWebhookSharedWithAdditionalHeaders(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook5", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func monitorNotificationChannelCustomWebhookWithName(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook1" { + name = "Example Channel %s - Custom Webhook" + enabled = true + url = "https://example.com/" + http_method = "POST" + template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false +}`, name) +} + +func monitorNotificationChannelCustomWebhookWithNameWithAdditionalheaders(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook2" { + name = "Example Channel %s - Custom Webhook With Additional Headers" + enabled = true + url = "https://example.com/" + http_method = "POST" + template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + additional_headers = { + "Webhook-Header": "TestHeader" + } + }`, name) +} + +func monitorNotificationChannelCustomWebhookSharedWithCurrentTeam(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook3" { + name = "Example Channel %s - Custom Webhook With Additional Headers" + share_with_current_team = true + enabled = true + url = "https://example.com/" + http_method = "POST" + template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + }`, name) +} + +func monitorNotificationChannelCustomWebhookSharedWithAllowInsecureConnections(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook4" { + name = "Example Channel %s - Custom Webhook With Additional Headers" + enabled = true + url = "https://example.com/" + http_method = "POST" + template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}" + allow_insecure_connections = true + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + }`, name) +} + +func monitorNotificationChannelCustomWebhookSharedWithAdditionalHeaders(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook5" { + name = "Example Channel %s - Custom Webhook With Additional Headers" + enabled = true + url = "https://example.com/" + http_method = "POST" + template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}" + additional_headers = { + "Webhook-Header": "TestHeader" + } + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + }`, name) +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_email.go b/sysdig/resource_sysdig_monitor_notification_channel_email.go index e9a73872..69f2971a 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_email.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_email.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -42,8 +43,7 @@ func resourceSysdigMonitorNotificationChannelEmail() *schema.Resource { } func resourceSysdigMonitorNotificationChannelEmailCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -76,9 +76,11 @@ func resourceSysdigMonitorNotificationChannelEmailRead(ctx context.Context, d *s id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -91,8 +93,7 @@ func resourceSysdigMonitorNotificationChannelEmailRead(ctx context.Context, d *s } func resourceSysdigMonitorNotificationChannelEmailUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_email_test.go b/sysdig/resource_sysdig_monitor_notification_channel_email_test.go index 25dde3d5..cb4cb7ef 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_email_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_email_test.go @@ -70,7 +70,7 @@ func monitorNotificationChannelEmailSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_email" "sample_email" { name = "%s" - share_with_current_team = true + share_with_current_team = true recipients = ["bar@localhost.com", "root@localhost.com"] enabled = false notify_when_ok = false diff --git a/sysdig/resource_sysdig_monitor_notification_channel_google_chat.go b/sysdig/resource_sysdig_monitor_notification_channel_google_chat.go new file mode 100644 index 00000000..6b4fdc26 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_google_chat.go @@ -0,0 +1,165 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceSysdigMonitorNotificationChannelGoogleChat() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigMonitorNotificationChannelGoogleChatCreate, + UpdateContext: resourceSysdigMonitorNotificationChannelGoogleChatUpdate, + ReadContext: resourceSysdigMonitorNotificationChannelGoogleChatRead, + DeleteContext: resourceSysdigMonitorNotificationChannelGoogleChatDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ + "url": { + Type: schema.TypeString, + Required: true, + }, + }), + } +} + +func resourceSysdigMonitorNotificationChannelGoogleChatCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := monitorNotificationChannelGoogleChatFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigMonitorNotificationChannelGoogleChatRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelGoogleChatRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = monitorNotificationChannelGoogleChatToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelGoogleChatUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := monitorNotificationChannelGoogleChatFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, err = strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return resourceSysdigMonitorNotificationChannelGoogleChatRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelGoogleChatDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func monitorNotificationChannelGoogleChatFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = monitorNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_GCHAT + nc.Options.Url = d.Get("url").(string) + return +} + +func monitorNotificationChannelGoogleChatToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = monitorNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("url", nc.Options.Url) + + return +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_google_chat_test.go b/sysdig/resource_sysdig_monitor_notification_channel_google_chat_test.go new file mode 100644 index 00000000..e71c1e58 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_google_chat_test.go @@ -0,0 +1,68 @@ +//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccMonitorNotificationChannelGoogleChat(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: sysdigOrIBMMonitorPreCheck(t), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: monitorNotificationChannelGoogleChatWithName(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_google_chat.sample_google_chat1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelGoogleChatSharedWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_google_chat.sample_google_chat2", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func monitorNotificationChannelGoogleChatWithName(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_google_chat" "sample_google_chat1" { + name = "Example Channel %s - google chat" + enabled = true + url = "https://chat.googleapis.com/v1/spaces/XXXXXX/messages?key=XXXXXXXXXXXXXXXXX" + notify_when_ok = true + notify_when_resolved = true +}`, name) +} + +func monitorNotificationChannelGoogleChatSharedWithCurrentTeam(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_google_chat" "sample_google_chat2" { + name = "Example Channel %s - google chat" + enabled = true + url = "https://chat.googleapis.com/v1/spaces/XXXXXX/messages?key=XXXXXXXXXXXXXXXXX" + notify_when_ok = true + notify_when_resolved = true + share_with_current_team = true +}`, name) +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function.go b/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function.go new file mode 100644 index 00000000..c9a171b3 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function.go @@ -0,0 +1,198 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceSysdigMonitorNotificationChannelIBMFunction() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigMonitorNotificationChannelIBMFunctionCreate, + UpdateContext: resourceSysdigMonitorNotificationChannelIBMFunctionUpdate, + ReadContext: resourceSysdigMonitorNotificationChannelIBMFunctionRead, + DeleteContext: resourceSysdigMonitorNotificationChannelIBMFunctionDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ + "ibm_function_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"WEB_ACTION", "CLOUD_FUNCTION"}, false), + }, + "url": { + Type: schema.TypeString, + Required: true, + }, + "custom_data": { + Type: schema.TypeMap, + Optional: true, + }, + "iam_api_key": { + Type: schema.TypeString, + Optional: true, + }, + "whisk_auth_token": { + Type: schema.TypeString, + Optional: true, + }, + }), + } +} + +func resourceSysdigMonitorNotificationChannelIBMFunctionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := secureNotificationChannelIBMFunctionFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigMonitorNotificationChannelIBMFunctionRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelIBMFunctionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = secureNotificationChannelIBMFunctionToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelIBMFunctionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := secureNotificationChannelIBMFunctionFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, _ = strconv.Atoi(d.Id()) + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelIBMFunctionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func secureNotificationChannelIBMFunctionFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = secureNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_IBM_FUNCTION + nc.Options.IbmFunctionType = d.Get("ibm_function_type").(string) + nc.Options.Url = d.Get("url").(string) + nc.Options.CustomData = d.Get("custom_data").(map[string]interface{}) + if nc.Options.IbmFunctionType == "CLOUD_FUNCTION" { + nc.Options.APIKey = d.Get("iam_api_key").(string) + } else { + nc.Options.APIKey = "" + } + if nc.Options.IbmFunctionType == "WEB_ACTION" { + nc.Options.AdditionalHeaders = map[string]interface{}{ + "X-Require-Whisk-Auth": d.Get("whisk_auth_token").(string), + } + } else { + nc.Options.AdditionalHeaders = map[string]interface{}{} + } + + return +} + +func secureNotificationChannelIBMFunctionToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = secureNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("ibm_function_type", nc.Options.IbmFunctionType) + _ = d.Set("url", nc.Options.Url) + _ = d.Set("custom_data", nc.Options.CustomData) + _ = d.Set("iam_api_key", nc.Options.APIKey) + if nc.Options.AdditionalHeaders != nil { + whishAuthToken, ok := nc.Options.AdditionalHeaders["X-Require-Whisk-Auth"] + if ok { + _ = d.Set("whisk_auth_token", whishAuthToken) + } + } + + return +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function_test.go b/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function_test.go new file mode 100644 index 00000000..25013b45 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function_test.go @@ -0,0 +1,122 @@ +//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccMonitorNotificationChannelIBMCloudFunction(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: sysdigOrIBMMonitorPreCheck(t), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: monitorNotificationChannelIBMCloudFunctionWebAction(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_function.sample1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelIBMCloudFunctionWebActionWithWishAuthToken(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_function.sample2", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelIBMCloudFunctionWebActionWithWishAuthTokenWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_function.sample3", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelIBMCloudFunctionWebActionWithCustomData(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_function.sample4", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelIBMCloudFunctionCloudFunction(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_function.sample5", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func monitorNotificationChannelIBMCloudFunctionWebAction(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_ibm_function" "sample1" { + name = "Example Channel %s - IBM Function" + ibm_function_type = "WEB_ACTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/web/namespaces/eeeeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/helloworld?param=true" + whisk_auth_token = "xxx" +}`, name) +} + +func monitorNotificationChannelIBMCloudFunctionWebActionWithWishAuthToken(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_ibm_function" "sample2" { + name = "Example Channel %s - IBM Function" + ibm_function_type = "WEB_ACTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/web/namespaces/eeeeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/helloworld?param=true" + whisk_auth_token = "xxx" +}`, name) +} + +func monitorNotificationChannelIBMCloudFunctionWebActionWithWishAuthTokenWithCurrentTeam(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_ibm_function" "sample3" { + name = "Example Channel %s - IBM Function" + ibm_function_type = "WEB_ACTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/web/namespaces/eeeeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/helloworld?param=true" + share_with_current_team = true +}`, name) +} + +func monitorNotificationChannelIBMCloudFunctionWebActionWithCustomData(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_ibm_function" "sample4" { + name = "Example Channel %s - IBM Function" + ibm_function_type = "WEB_ACTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/web/namespaces/eeeeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/helloworld?param=true" + custom_data = { + "data1": "value1" + "data2": "value2" + } +}`, name) +} + +func monitorNotificationChannelIBMCloudFunctionCloudFunction(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_ibm_function" "sample5" { + name = "Example Channel %s - IBM Function" + ibm_function_type = "CLOUD_FUNCTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/namespaces/13eeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/myaction" + iam_api_key = "xxx" +}`, name) +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification.go b/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification.go new file mode 100644 index 00000000..f45e5821 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification.go @@ -0,0 +1,165 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceSysdigMonitorNotificationChannelIBMEventNotification() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigMonitorNotificationChannelIBMEventNotificationCreate, + UpdateContext: resourceSysdigMonitorNotificationChannelIBMEventNotificationUpdate, + ReadContext: resourceSysdigMonitorNotificationChannelIBMEventNotificationRead, + DeleteContext: resourceSysdigMonitorNotificationChannelIBMEventNotificationDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + }, + }), + } +} + +func resourceSysdigMonitorNotificationChannelIBMEventNotificationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := monitorNotificationChannelIBMEventNotificationFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigMonitorNotificationChannelIBMEventNotificationRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelIBMEventNotificationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = monitorNotificationChannelIBMEventNotificationToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelIBMEventNotificationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := monitorNotificationChannelIBMEventNotificationFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, err = strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return resourceSysdigMonitorNotificationChannelIBMEventNotificationRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelIBMEventNotificationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func monitorNotificationChannelIBMEventNotificationFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = monitorNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_IBM_EVENT_NOTIFICATION + nc.Options.InstanceId = d.Get("instance_id").(string) + return +} + +func monitorNotificationChannelIBMEventNotificationToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = monitorNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("instance_id", nc.Options.InstanceId) + + return +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification_test.go b/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification_test.go new file mode 100644 index 00000000..75faf0c7 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification_test.go @@ -0,0 +1,75 @@ +//go:build tf_acc_ibm_monitor || tf_acc_ibm_common + +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 TestAccMonitorNotificationChannelIBMEventNotification(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + ibmEventNotificationInstanceId := os.Getenv("IBM_EVENT_NOTIFICATION_INSTANCE_ID") + if ibmEventNotificationInstanceId == "" { + t.Skip("Skipping tests on sysdig_monitor_notification_channel_ibm_event_notification resource because IBM_EVENT_NOTIFICATION_INSTANCE_ID is not set") + return + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: preCheckAnyEnv(t, SysdigIBMMonitorAPIKeyEnv), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: monitorNotificationChannelIBMEventNotificationWithName(rText(), ibmEventNotificationInstanceId), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_event_notification.sample1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelIBMEventNotificationSharedWithCurrentTeam(rText(), ibmEventNotificationInstanceId), + }, + { + ResourceName: "sysdig_monitor_notification_channel_ibm_event_notification.sample2", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func monitorNotificationChannelIBMEventNotificationWithName(name, ibmEventNotificationInstanceId string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_ibm_event_notification" "sample1" { + name = "Example Channel %s - IBM Event Notification" + enabled = true + instance_id = "%s" + notify_when_ok = true + notify_when_resolved = true +}`, name, ibmEventNotificationInstanceId) +} + +func monitorNotificationChannelIBMEventNotificationSharedWithCurrentTeam(name, ibmEventNotificationInstanceId string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_ibm_event_notification" "sample2" { + name = "Example Channel %s - IBM Event Notification" + share_with_current_team = true + enabled = true + instance_id = "%s" + notify_when_ok = true + notify_when_resolved = true +}`, name, ibmEventNotificationInstanceId) +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_msteams.go b/sysdig/resource_sysdig_monitor_notification_channel_msteams.go index a9f954cf..1f69082e 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_msteams.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_msteams.go @@ -40,8 +40,7 @@ func resourceSysdigMonitorNotificationChannelMSTeams() *schema.Resource { } func resourceSysdigMonitorNotificationChannelMSTeamsCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -78,9 +77,11 @@ func resourceSysdigMonitorNotificationChannelMSTeamsRead(ctx context.Context, d } nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -93,8 +94,7 @@ func resourceSysdigMonitorNotificationChannelMSTeamsRead(ctx context.Context, d } func resourceSysdigMonitorNotificationChannelMSTeamsUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_msteams_test.go b/sysdig/resource_sysdig_monitor_notification_channel_msteams_test.go index f345ba89..b57116bf 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_msteams_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_msteams_test.go @@ -27,11 +27,16 @@ func TestAccMonitorNotificationChannelMSTeams(t *testing.T) { { Config: monitorNotificationChannelMSTeamsWithName(rText()), }, + { + ResourceName: "sysdig_monitor_notification_channel_msteams.sample-msteams1", + ImportState: true, + ImportStateVerify: true, + }, { Config: monitorNotificationChannelMSTeamsSharedWithCurrentTeam(rText()), }, { - ResourceName: "sysdig_monitor_notification_channel_msteams.sample-msteams", + ResourceName: "sysdig_monitor_notification_channel_msteams.sample-msteams2", ImportState: true, ImportStateVerify: true, }, @@ -41,7 +46,7 @@ func TestAccMonitorNotificationChannelMSTeams(t *testing.T) { func monitorNotificationChannelMSTeamsWithName(name string) string { return fmt.Sprintf(` -resource "sysdig_monitor_notification_channel_msteams" "sample-msteams" { +resource "sysdig_monitor_notification_channel_msteams" "sample-msteams1" { name = "Example Channel %s - MS Teams" enabled = true url = "https://hooks.msteams.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" @@ -52,9 +57,9 @@ resource "sysdig_monitor_notification_channel_msteams" "sample-msteams" { func monitorNotificationChannelMSTeamsSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` -resource "sysdig_monitor_notification_channel_msteams" "sample-msteams" { +resource "sysdig_monitor_notification_channel_msteams" "sample-msteams2" { name = "Example Channel %s - MS Teams" - share_with_current_team = true + share_with_current_team = true enabled = true url = "https://hooks.msteams.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" notify_when_ok = true diff --git a/sysdig/resource_sysdig_monitor_notification_channel_opsgenie.go b/sysdig/resource_sysdig_monitor_notification_channel_opsgenie.go index 90f7c81a..09dcc159 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_opsgenie.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_opsgenie.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -47,8 +48,7 @@ func resourceSysdigMonitorNotificationChannelOpsGenie() *schema.Resource { } func resourceSysdigMonitorNotificationChannelOpsGenieCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -81,9 +81,11 @@ func resourceSysdigMonitorNotificationChannelOpsGenieRead(ctx context.Context, d id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -96,8 +98,7 @@ func resourceSysdigMonitorNotificationChannelOpsGenieRead(ctx context.Context, d } func resourceSysdigMonitorNotificationChannelOpsGenieUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_opsgenie_test.go b/sysdig/resource_sysdig_monitor_notification_channel_opsgenie_test.go index 4c496082..9fca3e88 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_opsgenie_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_opsgenie_test.go @@ -81,7 +81,7 @@ func monitorNotificationChannelOpsGenieSharedWithCurrentTeam(name string) string resource "sysdig_monitor_notification_channel_opsgenie" "sample-opsgenie-3" { name = "Example Channel %s - OpsGenie - 3" enabled = true - share_with_current_team = true + share_with_current_team = true api_key = "2349324-342354353-5324-23" notify_when_ok = false notify_when_resolved = false diff --git a/sysdig/resource_sysdig_monitor_notification_channel_pagerduty.go b/sysdig/resource_sysdig_monitor_notification_channel_pagerduty.go index 42a78a61..0ea3e61e 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_pagerduty.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_pagerduty.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -48,8 +49,7 @@ func resourceSysdigMonitorNotificationChannelPagerduty() *schema.Resource { } func resourceSysdigMonitorNotificationChannelPagerdutyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -82,9 +82,11 @@ func resourceSysdigMonitorNotificationChannelPagerdutyRead(ctx context.Context, id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -97,8 +99,7 @@ func resourceSysdigMonitorNotificationChannelPagerdutyRead(ctx context.Context, } func resourceSysdigMonitorNotificationChannelPagerdutyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_pagerduty_test.go b/sysdig/resource_sysdig_monitor_notification_channel_pagerduty_test.go index f31cc4b9..5174f63d 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_pagerduty_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_pagerduty_test.go @@ -58,7 +58,7 @@ func monitorNotificationChannelPagerdutySharedWithCurrentTeam(name string) strin return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_pagerduty" "sample-pagerduty" { name = "Example Channel %s - Pagerduty" - share_with_current_team = true + share_with_current_team = true enabled = true account = "account" service_key = "XXXXXXXXXX" diff --git a/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager.go b/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager.go new file mode 100644 index 00000000..16db59cd --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager.go @@ -0,0 +1,173 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceSysdigMonitorNotificationChannelPrometheusAlertManager() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigMonitorNotificationChannelPrometheusAlertManagerCreate, + UpdateContext: resourceSysdigMonitorNotificationChannelPrometheusAlertManagerUpdate, + ReadContext: resourceSysdigMonitorNotificationChannelPrometheusAlertManagerRead, + DeleteContext: resourceSysdigMonitorNotificationChannelPrometheusAlertManagerDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ + "url": { + Type: schema.TypeString, + Required: true, + }, + "additional_headers": { + Type: schema.TypeMap, + Optional: true, + }, + "allow_insecure_connections": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }), + } +} + +func resourceSysdigMonitorNotificationChannelPrometheusAlertManagerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := monitorNotificationChannelPrometheusAlertManagerFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigMonitorNotificationChannelPrometheusAlertManagerRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelPrometheusAlertManagerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = monitorNotificationChannelPrometheusAlertManagerToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelPrometheusAlertManagerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := monitorNotificationChannelPrometheusAlertManagerFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, _ = strconv.Atoi(d.Id()) + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelPrometheusAlertManagerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func monitorNotificationChannelPrometheusAlertManagerFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = monitorNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_PROMETHEUS_ALERT_MANAGER + nc.Options.Url = d.Get("url").(string) + nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + allowInsecureConnections := d.Get("allow_insecure_connections").(bool) + nc.Options.AllowInsecureConnections = &allowInsecureConnections + return +} + +func monitorNotificationChannelPrometheusAlertManagerToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = monitorNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("url", nc.Options.Url) + _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + + if nc.Options.AllowInsecureConnections != nil { + _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) + } + + return +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager_test.go b/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager_test.go new file mode 100644 index 00000000..da8f9ea7 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager_test.go @@ -0,0 +1,114 @@ +//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccMonitorNotificationChannelPrometheusAlertManager(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: sysdigOrIBMMonitorPreCheck(t), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: monitorNotificationChannelPrometheusAlertManagerWithName(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_prometheus_alert_manager.sample-channel1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelPrometheusAlertManagerWithNameWithAdditionalheaders(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_prometheus_alert_manager.sample-channel2", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelPrometheusAlertManagerWithNameWithAllowInsecureConnections(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_prometheus_alert_manager.sample-channel3", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelPrometheusAlertManagerSharedWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_prometheus_alert_manager.sample-channel4", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func monitorNotificationChannelPrometheusAlertManagerWithName(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_notification_channel_prometheus_alert_manager" "sample-channel1" { + name = "Example Channel %s - prometheus alert manager" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false +}`, name) +} + +func monitorNotificationChannelPrometheusAlertManagerWithNameWithAdditionalheaders(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_prometheus_alert_manager" "sample-channel2" { + name = "Example Channel %s - prometheus alert manager With Additional Headers" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + additional_headers = { + "custom-Header": "TestHeader" + } + }`, name) +} + +func monitorNotificationChannelPrometheusAlertManagerWithNameWithAllowInsecureConnections(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_prometheus_alert_manager" "sample-channel3" { + name = "Example Channel %s - prometheus alert manager with insecure connections" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + allow_insecure_connections = true + }`, name) +} + +func monitorNotificationChannelPrometheusAlertManagerSharedWithCurrentTeam(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_prometheus_alert_manager" "sample-channel4" { + name = "Example Channel %s - prometheus alert manager with share with current team" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + share_with_current_team = true + }`, name) +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_slack.go b/sysdig/resource_sysdig_monitor_notification_channel_slack.go index 1576cb21..bf440ed8 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_slack.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_slack.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -43,8 +44,7 @@ func resourceSysdigMonitorNotificationChannelSlack() *schema.Resource { } func resourceSysdigMonitorNotificationChannelSlackCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -75,11 +75,17 @@ func resourceSysdigMonitorNotificationChannelSlackRead(ctx context.Context, d *s return diag.FromErr(err) } - id, _ := strconv.Atoi(d.Id()) - nc, err := client.GetNotificationChannelById(ctx, id) + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + nc, err := client.GetNotificationChannelById(ctx, id) if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -92,8 +98,7 @@ func resourceSysdigMonitorNotificationChannelSlackRead(ctx context.Context, d *s } func resourceSysdigMonitorNotificationChannelSlackUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -109,13 +114,18 @@ func resourceSysdigMonitorNotificationChannelSlackUpdate(ctx context.Context, d } nc.Version = d.Get("version").(int) - nc.ID, _ = strconv.Atoi(d.Id()) + nc.ID, err = strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } _, err = client.UpdateNotificationChannel(ctx, nc) if err != nil { return diag.FromErr(err) } + resourceSysdigMonitorNotificationChannelSlackRead(ctx, d, meta) + return nil } @@ -125,7 +135,10 @@ func resourceSysdigMonitorNotificationChannelSlackDelete(ctx context.Context, d return diag.FromErr(err) } - id, _ := strconv.Atoi(d.Id()) + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } err = client.DeleteNotificationChannel(ctx, id) if err != nil { diff --git a/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go b/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go index f91970d7..fbdfd5bf 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go @@ -55,7 +55,7 @@ func monitorNotificationChannelSlackSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_slack" "sample-slack" { name = "Example Channel %s - Slack" - share_with_current_team = true + share_with_current_team = true enabled = true url = "https://hooks.slack.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" channel = "#sysdig" diff --git a/sysdig/resource_sysdig_monitor_notification_channel_sns.go b/sysdig/resource_sysdig_monitor_notification_channel_sns.go index 298d3591..0adf8a81 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_sns.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_sns.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/spf13/cast" @@ -41,8 +42,7 @@ func resourceSysdigMonitorNotificationChannelSNS() *schema.Resource { } func resourceSysdigMonitorNotificationChannelSNSCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -75,9 +75,11 @@ func resourceSysdigMonitorNotificationChannelSNSRead(ctx context.Context, d *sch id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -90,8 +92,7 @@ func resourceSysdigMonitorNotificationChannelSNSRead(ctx context.Context, d *sch } func resourceSysdigMonitorNotificationChannelSNSUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -151,5 +152,6 @@ func monitorNotificationChannelSNSToResourceData(nc *v2.NotificationChannel, d * } _ = d.Set("topics", nc.Options.SnsTopicARNs) + return } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_sns_test.go b/sysdig/resource_sysdig_monitor_notification_channel_sns_test.go index c83669cd..9a5477d5 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_sns_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_sns_test.go @@ -55,7 +55,7 @@ func monitorNotificationChannelAmazonSNSShareWithCurrentTeam(name string) string return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_sns" "sample-amazon-sns" { name = "Example Channel %s - Amazon SNS" - share_with_current_team = true + share_with_current_team = true enabled = true topics = ["arn:aws:sns:us-east-1:273489009834:my-alerts2", "arn:aws:sns:us-east-1:279948934544:my-alerts"] notify_when_ok = false diff --git a/sysdig/resource_sysdig_monitor_notification_channel_team_email.go b/sysdig/resource_sysdig_monitor_notification_channel_team_email.go new file mode 100644 index 00000000..5ca11564 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_team_email.go @@ -0,0 +1,156 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceSysdigMonitorNotificationChannelTeamEmail() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigMonitorNotificationChannelTeamEmailCreate, + UpdateContext: resourceSysdigMonitorNotificationChannelTeamEmailUpdate, + ReadContext: resourceSysdigMonitorNotificationChannelTeamEmailRead, + DeleteContext: resourceSysdigMonitorNotificationChannelTeamEmailDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createMonitorNotificationChannelSchema(map[string]*schema.Schema{ + "team_id": { + Type: schema.TypeInt, + Required: true, + }, + }), + } +} + +func resourceSysdigMonitorNotificationChannelTeamEmailCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := monitorNotificationChannelTeamEmailFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigMonitorNotificationChannelTeamEmailRead(ctx, d, meta) +} + +func resourceSysdigMonitorNotificationChannelTeamEmailRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = monitorNotificationChannelTeamEmailToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelTeamEmailUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := monitorNotificationChannelTeamEmailFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, _ = strconv.Atoi(d.Id()) + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigMonitorNotificationChannelTeamEmailDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func monitorNotificationChannelTeamEmailFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = monitorNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_TEAM_EMAIL + nc.Options.TeamId = d.Get("team_id").(int) + return +} + +func monitorNotificationChannelTeamEmailToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = monitorNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("team_id", nc.Options.TeamId) + + return +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_team_email_test.go b/sysdig/resource_sysdig_monitor_notification_channel_team_email_test.go new file mode 100644 index 00000000..41129493 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_team_email_test.go @@ -0,0 +1,80 @@ +//go:build tf_acc_sysdig_monitor || tf_acc_sysdig_common || tf_acc_ibm_monitor || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccMonitorNotificationChannelTeamEmail(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: sysdigOrIBMMonitorPreCheck(t), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: monitorNotificationChannelTeamEmailWithName(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_team_email.sample_team_email1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: monitorNotificationChannelTeamEmailSharedWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_team_email.sample_team_email2", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func monitorNotificationChannelTeamEmailWithName(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_team" "sample" { + name = "monitor-sample" + entrypoint { + type = "Explore" + } +} +resource "sysdig_monitor_notification_channel_team_email" "sample_team_email1" { + name = "Example Channel %s - team email" + enabled = true + team_id = sysdig_monitor_team.sample.id + notify_when_ok = true + notify_when_resolved = true +}`, name) +} + +func monitorNotificationChannelTeamEmailSharedWithCurrentTeam(name string) string { + return fmt.Sprintf(` +resource "sysdig_monitor_team" "sample" { + name = "monitor-sample" + entrypoint { + type = "Explore" + } +} +resource "sysdig_monitor_notification_channel_team_email" "sample_team_email2" { + name = "Example Channel %s - team email" + enabled = true + team_id = sysdig_monitor_team.sample.id + notify_when_ok = true + notify_when_resolved = true + share_with_current_team = true +}`, name) +} diff --git a/sysdig/resource_sysdig_monitor_notification_channel_victorops.go b/sysdig/resource_sysdig_monitor_notification_channel_victorops.go index f0496ed7..f32dfec1 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_victorops.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_victorops.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -43,8 +44,7 @@ func resourceSysdigMonitorNotificationChannelVictorOps() *schema.Resource { } func resourceSysdigMonitorNotificationChannelVictorOpsCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -77,9 +77,11 @@ func resourceSysdigMonitorNotificationChannelVictorOpsRead(ctx context.Context, id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -92,8 +94,7 @@ func resourceSysdigMonitorNotificationChannelVictorOpsRead(ctx context.Context, } func resourceSysdigMonitorNotificationChannelVictorOpsUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_victorops_test.go b/sysdig/resource_sysdig_monitor_notification_channel_victorops_test.go index 6228ad5e..a432e12c 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_victorops_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_victorops_test.go @@ -56,7 +56,7 @@ func monitorNotificationChannelVictorOpsShareWithCurrentTeam(name string) string return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_victorops" "sample-victorops" { name = "Example Channel %s - VictorOps" - share_with_current_team = true + share_with_current_team = true enabled = true api_key = "1234342-4234243-4234-2" routing_key = "My team" diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go index 8b22a976..2649e2cd 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -78,9 +79,11 @@ func resourceSysdigMonitorNotificationChannelWebhookRead(ctx context.Context, d id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -93,8 +96,7 @@ func resourceSysdigMonitorNotificationChannelWebhookRead(ctx context.Context, d } func resourceSysdigMonitorNotificationChannelWebhookUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - clients := meta.(SysdigClients) - client, err := getMonitorNotificationChannelClient(clients) + client, err := getMonitorNotificationChannelClient(meta.(SysdigClients)) if err != nil { return diag.FromErr(err) } @@ -132,6 +134,7 @@ func resourceSysdigMonitorNotificationChannelWebhookDelete(ctx context.Context, if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go index f989d7c2..10a7d71a 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go @@ -83,7 +83,7 @@ func monitorNotificationChannelWebhookSharedWithCurrentTeam(name string) string return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_webhook" "sample-webhook3" { name = "Example Channel %s - Webhook With Additional Headers" - share_with_current_team = true + share_with_current_team = true enabled = true url = "https://example.com/" notify_when_ok = false diff --git a/sysdig/resource_sysdig_secure_notification_channel_common.go b/sysdig/resource_sysdig_secure_notification_channel_common.go index 5b9e358a..8baa0718 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_common.go +++ b/sysdig/resource_sysdig_secure_notification_channel_common.go @@ -13,7 +13,8 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m }, "enabled": { Type: schema.TypeBool, - Required: true, + Optional: true, + Default: true, }, "share_with_current_team": { Type: schema.TypeBool, @@ -22,11 +23,13 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m }, "notify_when_ok": { Type: schema.TypeBool, - Required: true, + Optional: true, + Default: false, }, "notify_when_resolved": { Type: schema.TypeBool, - Required: true, + Optional: true, + Default: false, }, "version": { Type: schema.TypeInt, diff --git a/sysdig/resource_sysdig_secure_notification_channel_email.go b/sysdig/resource_sysdig_secure_notification_channel_email.go index ca6ae52b..62d8585d 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_email.go +++ b/sysdig/resource_sysdig_secure_notification_channel_email.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -63,9 +64,8 @@ func resourceSysdigSecureNotificationChannelEmailCreate(ctx context.Context, d * } d.SetId(strconv.Itoa(notificationChannel.ID)) - _ = d.Set("version", notificationChannel.Version) - return nil + return resourceSysdigSecureNotificationChannelEmailRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelEmailRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -76,9 +76,12 @@ func resourceSysdigSecureNotificationChannelEmailRead(ctx context.Context, d *sc id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) } err = secureNotificationChannelEmailToResourceData(&nc, d) @@ -128,6 +131,7 @@ func resourceSysdigSecureNotificationChannelEmailDelete(ctx context.Context, d * if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_secure_notification_channel_email_test.go b/sysdig/resource_sysdig_secure_notification_channel_email_test.go index ccc74859..0f0d92b1 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_email_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_email_test.go @@ -71,7 +71,7 @@ func secureNotificationChannelEmailSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` resource "sysdig_secure_notification_channel_email" "sample_email" { name = "%s" - share_with_current_team = true + share_with_current_team = true recipients = ["bar@localhost.com", "root@localhost.com"] enabled = false notify_when_ok = false diff --git a/sysdig/resource_sysdig_secure_notification_channel_msteams.go b/sysdig/resource_sysdig_secure_notification_channel_msteams.go index 9553e305..7b6f4fdf 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_msteams.go +++ b/sysdig/resource_sysdig_secure_notification_channel_msteams.go @@ -9,7 +9,6 @@ import ( v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -83,9 +82,11 @@ func resourceSysdigSecureNotificationChannelMSTeamsRead(ctx context.Context, d * } nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -142,6 +143,7 @@ func resourceSysdigSecureNotificationChannelMSTeamsDelete(ctx context.Context, d if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_secure_notification_channel_msteams_test.go b/sysdig/resource_sysdig_secure_notification_channel_msteams_test.go index c2926baf..885de1d2 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_msteams_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_msteams_test.go @@ -67,7 +67,7 @@ func secureNotificationChannelMSTeamsSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` resource "sysdig_secure_notification_channel_msteams" "sample-msteams" { name = "Example Channel %s - MS Teams" - share_with_current_team = true + share_with_current_team = true enabled = true url = "https://hooks.msteams.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" notify_when_ok = true diff --git a/sysdig/resource_sysdig_secure_notification_channel_opsgenie.go b/sysdig/resource_sysdig_secure_notification_channel_opsgenie.go index 369e2819..d453d2c2 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_opsgenie.go +++ b/sysdig/resource_sysdig_secure_notification_channel_opsgenie.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -68,9 +69,8 @@ func resourceSysdigSecureNotificationChannelOpsGenieCreate(ctx context.Context, } d.SetId(strconv.Itoa(notificationChannel.ID)) - _ = d.Set("version", notificationChannel.Version) - return nil + return resourceSysdigSecureNotificationChannelOpsGenieRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelOpsGenieRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -81,9 +81,12 @@ func resourceSysdigSecureNotificationChannelOpsGenieRead(ctx context.Context, d id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) } err = secureNotificationChannelOpsGenieToResourceData(&nc, d) @@ -133,6 +136,7 @@ func resourceSysdigSecureNotificationChannelOpsGenieDelete(ctx context.Context, if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_secure_notification_channel_opsgenie_test.go b/sysdig/resource_sysdig_secure_notification_channel_opsgenie_test.go index e5559772..5a1e97f5 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_opsgenie_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_opsgenie_test.go @@ -81,7 +81,7 @@ func secureNotificationChannelOpsGenieSharedWithCurrentTeam(name string) string resource "sysdig_secure_notification_channel_opsgenie" "sample-opsgenie-3" { name = "Example Channel %s - OpsGenie - 3" enabled = true - share_with_current_team = true + share_with_current_team = true api_key = "2349324-342354353-5324-23" notify_when_ok = false notify_when_resolved = false diff --git a/sysdig/resource_sysdig_secure_notification_channel_pagerduty.go b/sysdig/resource_sysdig_secure_notification_channel_pagerduty.go index 8f2ad938..10d000bb 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_pagerduty.go +++ b/sysdig/resource_sysdig_secure_notification_channel_pagerduty.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -69,9 +70,8 @@ func resourceSysdigSecureNotificationChannelPagerdutyCreate(ctx context.Context, } d.SetId(strconv.Itoa(notificationChannel.ID)) - _ = d.Set("version", notificationChannel.Version) - return nil + return resourceSysdigSecureNotificationChannelPagerdutyRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelPagerdutyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -82,9 +82,12 @@ func resourceSysdigSecureNotificationChannelPagerdutyRead(ctx context.Context, d id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) } err = secureNotificationChannelPagerdutyToResourceData(&nc, d) @@ -134,6 +137,7 @@ func resourceSysdigSecureNotificationChannelPagerdutyDelete(ctx context.Context, if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_secure_notification_channel_pagerduty_test.go b/sysdig/resource_sysdig_secure_notification_channel_pagerduty_test.go index 2a79f999..5609692a 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_pagerduty_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_pagerduty_test.go @@ -58,7 +58,7 @@ func secureNotificationChannelPagerdutySharedWithCurrentTeam(name string) string return fmt.Sprintf(` resource "sysdig_secure_notification_channel_pagerduty" "sample-pagerduty" { name = "Example Channel %s - Pagerduty" - share_with_current_team = true + share_with_current_team = true enabled = true account = "account" service_key = "XXXXXXXXXX" diff --git a/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager.go b/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager.go new file mode 100644 index 00000000..6c39bf2c --- /dev/null +++ b/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager.go @@ -0,0 +1,174 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceSysdigSecureNotificationChannelPrometheusAlertManager() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigSecureNotificationChannelPrometheusAlertManagerCreate, + UpdateContext: resourceSysdigSecureNotificationChannelPrometheusAlertManagerUpdate, + ReadContext: resourceSysdigSecureNotificationChannelPrometheusAlertManagerRead, + DeleteContext: resourceSysdigSecureNotificationChannelPrometheusAlertManagerDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createSecureNotificationChannelSchema(map[string]*schema.Schema{ + "url": { + Type: schema.TypeString, + Required: true, + }, + "additional_headers": { + Type: schema.TypeMap, + Optional: true, + }, + "allow_insecure_connections": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }), + } +} + +func resourceSysdigSecureNotificationChannelPrometheusAlertManagerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + clients := meta.(SysdigClients) + client, err := getSecureNotificationChannelClient(clients) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := secureNotificationChannelPrometheusAlertManagerFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigSecureNotificationChannelPrometheusAlertManagerRead(ctx, d, meta) +} + +func resourceSysdigSecureNotificationChannelPrometheusAlertManagerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = secureNotificationChannelPrometheusAlertManagerToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigSecureNotificationChannelPrometheusAlertManagerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := secureNotificationChannelPrometheusAlertManagerFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, _ = strconv.Atoi(d.Id()) + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigSecureNotificationChannelPrometheusAlertManagerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func secureNotificationChannelPrometheusAlertManagerFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = secureNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_PROMETHEUS_ALERT_MANAGER + nc.Options.Url = d.Get("url").(string) + nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + allowInsecureConnections := d.Get("allow_insecure_connections").(bool) + nc.Options.AllowInsecureConnections = &allowInsecureConnections + return +} + +func secureNotificationChannelPrometheusAlertManagerToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = secureNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("url", nc.Options.Url) + _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + + if nc.Options.AllowInsecureConnections != nil { + _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) + } + + return +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager_test.go b/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager_test.go new file mode 100644 index 00000000..f900d26f --- /dev/null +++ b/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager_test.go @@ -0,0 +1,114 @@ +//go:build tf_acc_sysdig_secure || tf_acc_sysdig_common || tf_acc_ibm_secure || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccSecureNotificationChannelPrometheusAlertManager(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv, SysdigIBMSecureAPIKeyEnv), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: secureNotificationChannelPrometheusAlertManagerWithName(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_prometheus_alert_manager.sample-channel1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: secureNotificationChannelPrometheusAlertManagerWithNameWithAdditionalheaders(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_prometheus_alert_manager.sample-channel2", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: secureNotificationChannelPrometheusAlertManagerWithNameWithAllowInsecureConnections(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_prometheus_alert_manager.sample-channel3", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: secureNotificationChannelPrometheusAlertManagerSharedWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_prometheus_alert_manager.sample-channel4", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func secureNotificationChannelPrometheusAlertManagerWithName(name string) string { + return fmt.Sprintf(` +resource "sysdig_secure_notification_channel_prometheus_alert_manager" "sample-channel1" { + name = "Example Channel %s - prometheus alert manager" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false +}`, name) +} + +func secureNotificationChannelPrometheusAlertManagerWithNameWithAdditionalheaders(name string) string { + return fmt.Sprintf(` + resource "sysdig_secure_notification_channel_prometheus_alert_manager" "sample-channel2" { + name = "Example Channel %s - prometheus alert manager With Additional Headers" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + additional_headers = { + "custom-Header": "TestHeader" + } + }`, name) +} + +func secureNotificationChannelPrometheusAlertManagerWithNameWithAllowInsecureConnections(name string) string { + return fmt.Sprintf(` + resource "sysdig_secure_notification_channel_prometheus_alert_manager" "sample-channel3" { + name = "Example Channel %s - prometheus alert manager with insecure connections" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + allow_insecure_connections = true + }`, name) +} + +func secureNotificationChannelPrometheusAlertManagerSharedWithCurrentTeam(name string) string { + return fmt.Sprintf(` + resource "sysdig_secure_notification_channel_prometheus_alert_manager" "sample-channel4" { + name = "Example Channel %s - prometheus alert manager with share with current team" + enabled = true + url = "https://testurl.com/xxx" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + share_with_current_team = true + }`, name) +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_slack.go b/sysdig/resource_sysdig_secure_notification_channel_slack.go index 4902a1fc..5672ad0b 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_slack.go +++ b/sysdig/resource_sysdig_secure_notification_channel_slack.go @@ -9,7 +9,6 @@ import ( v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -72,9 +71,7 @@ func resourceSysdigSecureNotificationChannelSlackCreate(ctx context.Context, d * d.SetId(strconv.Itoa(notificationChannel.ID)) - resourceSysdigSecureNotificationChannelSlackRead(ctx, d, meta) - - return nil + return resourceSysdigSecureNotificationChannelSlackRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelSlackRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -89,9 +86,11 @@ func resourceSysdigSecureNotificationChannelSlackRead(ctx context.Context, d *sc } nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } return diag.FromErr(err) } @@ -150,6 +149,7 @@ func resourceSysdigSecureNotificationChannelSlackDelete(ctx context.Context, d * if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_secure_notification_channel_slack_test.go b/sysdig/resource_sysdig_secure_notification_channel_slack_test.go index 1561e1e6..dccd9e82 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_slack_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_slack_test.go @@ -68,7 +68,7 @@ func secureNotificationChannelSlackSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` resource "sysdig_secure_notification_channel_slack" "sample-slack" { name = "Example Channel %s - Slack" - share_with_current_team = true + share_with_current_team = true enabled = true url = "https://hooks.slack.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" channel = "#sysdig" diff --git a/sysdig/resource_sysdig_secure_notification_channel_sns.go b/sysdig/resource_sysdig_secure_notification_channel_sns.go index 8c66c465..e15672e9 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_sns.go +++ b/sysdig/resource_sysdig_secure_notification_channel_sns.go @@ -2,12 +2,12 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/spf13/cast" ) @@ -63,9 +63,8 @@ func resourceSysdigSecureNotificationChannelSNSCreate(ctx context.Context, d *sc } d.SetId(strconv.Itoa(notificationChannel.ID)) - _ = d.Set("version", notificationChannel.Version) - return nil + return resourceSysdigSecureNotificationChannelSNSRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelSNSRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -76,9 +75,12 @@ func resourceSysdigSecureNotificationChannelSNSRead(ctx context.Context, d *sche id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) } err = secureNotificationChannelSNSToResourceData(&nc, d) @@ -128,6 +130,7 @@ func resourceSysdigSecureNotificationChannelSNSDelete(ctx context.Context, d *sc if err != nil { return diag.FromErr(err) } + return nil } diff --git a/sysdig/resource_sysdig_secure_notification_channel_sns_test.go b/sysdig/resource_sysdig_secure_notification_channel_sns_test.go index d1571641..d1f4651c 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_sns_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_sns_test.go @@ -56,7 +56,7 @@ func secureNotificationChannelAmazonSNSShareWithCurrentTeam(name string) string return fmt.Sprintf(` resource "sysdig_secure_notification_channel_sns" "sample-amazon-sns" { name = "Example Channel %s - Amazon SNS" - share_with_current_team = true + share_with_current_team = true enabled = true topics = ["arn:aws:sns:us-east-1:273489009834:my-alerts2", "arn:aws:sns:us-east-1:279948934544:my-alerts"] notify_when_ok = false diff --git a/sysdig/resource_sysdig_secure_notification_channel_team_email.go b/sysdig/resource_sysdig_secure_notification_channel_team_email.go new file mode 100644 index 00000000..39fe39c8 --- /dev/null +++ b/sysdig/resource_sysdig_secure_notification_channel_team_email.go @@ -0,0 +1,156 @@ +package sysdig + +import ( + "context" + "strconv" + "time" + + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceSysdigSecureNotificationChannelTeamEmail() *schema.Resource { + timeout := 5 * time.Minute + + return &schema.Resource{ + CreateContext: resourceSysdigSecureNotificationChannelTeamEmailCreate, + UpdateContext: resourceSysdigSecureNotificationChannelTeamEmailUpdate, + ReadContext: resourceSysdigSecureNotificationChannelTeamEmailRead, + DeleteContext: resourceSysdigSecureNotificationChannelTeamEmailDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(timeout), + Update: schema.DefaultTimeout(timeout), + Read: schema.DefaultTimeout(timeout), + Delete: schema.DefaultTimeout(timeout), + }, + + Schema: createSecureNotificationChannelSchema(map[string]*schema.Schema{ + "team_id": { + Type: schema.TypeInt, + Required: true, + }, + }), + } +} + +func resourceSysdigSecureNotificationChannelTeamEmailCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err := secureNotificationChannelTeamEmailFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + notificationChannel, err = client.CreateNotificationChannel(ctx, notificationChannel) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(strconv.Itoa(notificationChannel.ID)) + + return resourceSysdigSecureNotificationChannelTeamEmailRead(ctx, d, meta) +} + +func resourceSysdigSecureNotificationChannelTeamEmailRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + nc, err := client.GetNotificationChannelById(ctx, id) + if err != nil { + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + + err = secureNotificationChannelTeamEmailToResourceData(&nc, d) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigSecureNotificationChannelTeamEmailUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + teamID, err := client.CurrentTeamID(ctx) + if err != nil { + return diag.FromErr(err) + } + + nc, err := secureNotificationChannelTeamEmailFromResourceData(d, teamID) + if err != nil { + return diag.FromErr(err) + } + + nc.Version = d.Get("version").(int) + nc.ID, _ = strconv.Atoi(d.Id()) + + _, err = client.UpdateNotificationChannel(ctx, nc) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func resourceSysdigSecureNotificationChannelTeamEmailDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + client, err := getSecureNotificationChannelClient(meta.(SysdigClients)) + if err != nil { + return diag.FromErr(err) + } + + id, _ := strconv.Atoi(d.Id()) + + err = client.DeleteNotificationChannel(ctx, id) + if err != nil { + return diag.FromErr(err) + } + + return nil +} + +func secureNotificationChannelTeamEmailFromResourceData(d *schema.ResourceData, teamID int) (nc v2.NotificationChannel, err error) { + nc, err = secureNotificationChannelFromResourceData(d, teamID) + if err != nil { + return + } + + nc.Type = NOTIFICATION_CHANNEL_TYPE_TEAM_EMAIL + nc.Options.TeamId = d.Get("team_id").(int) + return +} + +func secureNotificationChannelTeamEmailToResourceData(nc *v2.NotificationChannel, d *schema.ResourceData) (err error) { + err = secureNotificationChannelToResourceData(nc, d) + if err != nil { + return + } + + _ = d.Set("team_id", nc.Options.TeamId) + + return +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_team_email_test.go b/sysdig/resource_sysdig_secure_notification_channel_team_email_test.go new file mode 100644 index 00000000..a6009394 --- /dev/null +++ b/sysdig/resource_sysdig_secure_notification_channel_team_email_test.go @@ -0,0 +1,76 @@ +//go:build tf_acc_sysdig_secure || tf_acc_sysdig_common || tf_acc_ibm_secure || tf_acc_ibm_common + +package sysdig_test + +import ( + "fmt" + "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 TestAccSecureNotificationChannelTeamEmail(t *testing.T) { + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv, SysdigIBMSecureAPIKeyEnv), + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: secureNotificationChannelTeamEmailWithName(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_team_email.sample_team_email1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: secureNotificationChannelTeamEmailSharedWithCurrentTeam(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_team_email.sample_team_email2", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func secureNotificationChannelTeamEmailWithName(name string) string { + return fmt.Sprintf(` +resource "sysdig_secure_team" "sample" { + name = "secure-sample" + all_zones = "true" +} +resource "sysdig_secure_notification_channel_team_email" "sample_team_email1" { + name = "Example Channel %s - team email" + enabled = true + team_id = sysdig_secure_team.sample.id + notify_when_ok = true + notify_when_resolved = true +}`, name) +} + +func secureNotificationChannelTeamEmailSharedWithCurrentTeam(name string) string { + return fmt.Sprintf(` +resource "sysdig_secure_team" "sample" { + name = "secure-sample" + all_zones = "true" +} +resource "sysdig_secure_notification_channel_team_email" "sample_team_email2" { + name = "Example Channel %s - team email" + enabled = true + team_id = sysdig_secure_team.sample.id + notify_when_ok = true + notify_when_resolved = true + share_with_current_team = true +}`, name) +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_victorops.go b/sysdig/resource_sysdig_secure_notification_channel_victorops.go index 01e3a54d..db96f76b 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_victorops.go +++ b/sysdig/resource_sysdig_secure_notification_channel_victorops.go @@ -2,12 +2,12 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -65,9 +65,8 @@ func resourceSysdigSecureNotificationChannelVictorOpsCreate(ctx context.Context, } d.SetId(strconv.Itoa(notificationChannel.ID)) - _ = d.Set("version", notificationChannel.Version) - return nil + return resourceSysdigSecureNotificationChannelVictorOpsRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelVictorOpsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -78,9 +77,12 @@ func resourceSysdigSecureNotificationChannelVictorOpsRead(ctx context.Context, d id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) } err = secureNotificationChannelVictorOpsToResourceData(&nc, d) diff --git a/sysdig/resource_sysdig_secure_notification_channel_victorops_test.go b/sysdig/resource_sysdig_secure_notification_channel_victorops_test.go index f3145b98..a08fde13 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_victorops_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_victorops_test.go @@ -57,7 +57,7 @@ func secureNotificationChannelVictorOpsShareWithCurrentTeam(name string) string return fmt.Sprintf(` resource "sysdig_secure_notification_channel_victorops" "sample-victorops" { name = "Example Channel %s - VictorOps" - share_with_current_team = true + share_with_current_team = true enabled = true api_key = "1234342-4234243-4234-2" routing_key = "My team" diff --git a/sysdig/resource_sysdig_secure_notification_channel_webhook.go b/sysdig/resource_sysdig_secure_notification_channel_webhook.go index 01de6ff2..283caaa6 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_secure_notification_channel_webhook.go @@ -2,10 +2,11 @@ package sysdig import ( "context" - v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" "strconv" "time" + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -35,6 +36,10 @@ func resourceSysdigSecureNotificationChannelWebhook() *schema.Resource { Type: schema.TypeString, Required: true, }, + "additional_headers": { + Type: schema.TypeMap, + Optional: true, + }, }), } } @@ -61,9 +66,8 @@ func resourceSysdigSecureNotificationChannelWebhookCreate(ctx context.Context, d } d.SetId(strconv.Itoa(notificationChannel.ID)) - _ = d.Set("version", notificationChannel.Version) - return nil + return resourceSysdigSecureNotificationChannelWebhookRead(ctx, d, meta) } func resourceSysdigSecureNotificationChannelWebhookRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -74,9 +78,12 @@ func resourceSysdigSecureNotificationChannelWebhookRead(ctx context.Context, d * id, _ := strconv.Atoi(d.Id()) nc, err := client.GetNotificationChannelById(ctx, id) - if err != nil { - d.SetId("") + if err == v2.NotificationChannelNotFound { + d.SetId("") + return nil + } + return diag.FromErr(err) } err = secureNotificationChannelWebhookToResourceData(&nc, d) @@ -138,6 +145,7 @@ func secureNotificationChannelWebhookFromResourceData(d *schema.ResourceData, te nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK nc.Options.Url = d.Get("url").(string) + nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) return } @@ -148,6 +156,7 @@ func secureNotificationChannelWebhookToResourceData(nc *v2.NotificationChannel, } _ = d.Set("url", nc.Options.Url) + _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) return } diff --git a/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go b/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go index 4370cf7a..292ccf29 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go @@ -61,7 +61,7 @@ func secureNotificationChannelWebhookSharedWithCurrentTeam(name string) string { return fmt.Sprintf(` resource "sysdig_secure_notification_channel_webhook" "sample-webhook3" { name = "Example Channel %s - Webhook With Additional Headers" - share_with_current_team = true + share_with_current_team = true enabled = true url = "https://example.com/" notify_when_ok = false diff --git a/website/docs/index.md b/website/docs/index.md index 61b9f1a1..4df33eab 100644 --- a/website/docs/index.md +++ b/website/docs/index.md @@ -228,6 +228,14 @@ When IBM Workload Protection resources are to be created, this authentication mu > - `sysdig_secure_notification_channel_victorops` > - `sysdig_monitor_notification_channel_webhook` > - `sysdig_secure_notification_channel_webhook` +> - `sysdig_monitor_notification_channel_prometheus_alert_manager` +> - `sysdig_secure_notification_channel_prometheus_alert_manager` +> - `sysdig_monitor_notification_channel_team_email` +> - `sysdig_secure_notification_channel_team_email` +> - `sysdig_monitor_notification_channel_google_chat` +> - `sysdig_monitor_notification_channel_custom_webhook` +> - `sysdig_monitor_notification_channel_ibm_function` +> - `sysdig_monitor_notification_channel_ibm_event_notification` > - `sysdig_monitor_alert_downtime` > - `sysdig_monitor_alert_event` > - `sysdig_monitor_alert_metric` diff --git a/website/docs/r/monitor_notification_channel_custom_webhook.md b/website/docs/r/monitor_notification_channel_custom_webhook.md new file mode 100644 index 00000000..fea5dc78 --- /dev/null +++ b/website/docs/r/monitor_notification_channel_custom_webhook.md @@ -0,0 +1,77 @@ +--- +subcategory: "Sysdig Monitor" +layout: "sysdig" +page_title: "Sysdig: sysdig_monitor_notification_channel_custom_webhook" +description: |- + Creates a Sysdig Monitor Notification Channel of type Custom Webhook. +--- + +# Resource: sysdig_monitor_notification_channel_custom_webhook + +Creates a Sysdig Monitor Notification Channel of type Custom Webhook. + +-> **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 +resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook" { + name = "Example Channel - Custom Webhook" + enabled = true + url = "http://localhost:8080" + http_method = "POST" + template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}" + + additional_headers = { + "custom-Header": "TestHeader" + } + + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `url` - (Required) URL to send the event. + +* `http_method` - (Required) Http method of the request to be sent. Possible values: `POST`, `PUT`, `PATCH`, `DELETE`. + +* `template` - (Required) JSON payload template to be sent in body. + +* `allow_insecure_connections` - (Optional) Whether to skip TLS verification. Default: `false`. + +* `additional_headers` - (Optional) Key value list of custom headers. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +Custom Webhook notification channels for Monitor can be imported using the ID, e.g. + +``` +$ terraform import sysdig_monitor_notification_channel_custom_webhook.example 12345 +``` diff --git a/website/docs/r/monitor_notification_channel_email.md b/website/docs/r/monitor_notification_channel_email.md index ee7ff1f8..8fd73dd3 100644 --- a/website/docs/r/monitor_notification_channel_email.md +++ b/website/docs/r/monitor_notification_channel_email.md @@ -29,20 +29,23 @@ resource "sysdig_monitor_notification_channel_email" "sample_email" { * `name` - (Required) The name of the Notification Channel. Must be unique. -* `recipients` - (Required) List of recipients that will receive +* `recipients` - (Required) List of recipients that will receive the message. * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -51,9 +54,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import Email notification channels for Monitor can be imported using the ID, e.g. diff --git a/website/docs/r/monitor_notification_channel_google_chat.md b/website/docs/r/monitor_notification_channel_google_chat.md new file mode 100644 index 00000000..858e9dcb --- /dev/null +++ b/website/docs/r/monitor_notification_channel_google_chat.md @@ -0,0 +1,62 @@ +--- +subcategory: "Sysdig Monitor" +layout: "sysdig" +page_title: "Sysdig: sysdig_monitor_notification_channel_google_chat" +description: |- + Creates a Sysdig Monitor Notification Channel of type Google Chat. +--- + +# Resource: sysdig_monitor_notification_channel_google_chat + +Creates a Sysdig Monitor Notification Channel of type Google Chat. + +-> **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 +resource "sysdig_monitor_notification_channel_google_chat" "sample-gchat" { + name = "Example Channel - google chat" + enabled = true + url = "https://chat.googleapis.com/v1/spaces/XXXXXX/messages?key=XXXXXXXXXXXXXXXXX" + notify_when_ok = false + notify_when_resolved = false + share_with_current_team = true +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `url` - (Required) URL of the Google Chat webhook. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +Google Chat notification channels for Monitor can be imported using the ID, e.g. + +``` +$ terraform import sysdig_monitor_notification_channel_google_chat.example 12345 +``` diff --git a/website/docs/r/monitor_notification_channel_ibm_event_notification.md b/website/docs/r/monitor_notification_channel_ibm_event_notification.md new file mode 100644 index 00000000..29e11921 --- /dev/null +++ b/website/docs/r/monitor_notification_channel_ibm_event_notification.md @@ -0,0 +1,62 @@ +--- +subcategory: "Sysdig Monitor" +layout: "sysdig" +page_title: "Sysdig: sysdig_monitor_notification_channel_ibm_event_notification" +description: |- + Creates a Sysdig Monitor Notification Channel of type IBM Event Notification. +--- + +# Resource: sysdig_monitor_notification_channel_ibm_event_notification + +Creates a Sysdig Monitor Notification Channel of type IBM Event Notification (only available in IBM Cloud Monitoring). + +-> **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 +resource "sysdig_monitor_notification_channel_ibm_event_notification" "sample" { + name = "Example Channel - IBM Event Notification" + enabled = true + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + notify_when_ok = false + notify_when_resolved = false + share_with_current_team = true +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `instance_id` - (Required) id of the Event Notifications Instance. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +IBM Event Notification notification channels for Monitor can be imported using the ID, e.g. + +``` +$ terraform import sysdig_monitor_notification_channel_ibm_event_notification.example 12345 +``` diff --git a/website/docs/r/monitor_notification_channel_ibm_function.md b/website/docs/r/monitor_notification_channel_ibm_function.md new file mode 100644 index 00000000..cbb0ce08 --- /dev/null +++ b/website/docs/r/monitor_notification_channel_ibm_function.md @@ -0,0 +1,85 @@ +--- +subcategory: "Sysdig Monitor" +layout: "sysdig" +page_title: "Sysdig: sysdig_monitor_notification_channel_ibm_function" +description: |- + Creates a Sysdig Monitor Notification Channel of type IBM Function. +--- + +# Resource: sysdig_monitor_notification_channel_ibm_function + +Creates a Sysdig Monitor Notification Channel of type IBM Function. + +-> **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 +resource "sysdig_monitor_notification_channel_ibm_function" "sample-ibm-function-web-action" { + name = "Example Channel - IBM Function - web action" + enabled = true + ibm_function_type = "WEB_ACTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/web/namespaces/eeeeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/helloworld?param=true" + whisk_auth_token = "xxx" + + custom_data = { + "data1": "value1" + "data2": "value2" + } + + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false +} + +resource "sysdig_monitor_notification_channel_ibm_function" "sample-ibm-function-cloud-function" { + name = "Example Channel - IBM Function - cloud function" + ibm_function_type = "CLOUD_FUNCTION" + url = "https://eu-gb.functions.cloud.ibm.com/api/v1/namespaces/13eeeeee-623b-4776-ba35-4065bcbfee7b/actions/hello-world/myaction" + iam_api_key = "xxx" +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `ibm_function_type` - (Required) Type of IBM Function. Can be `WEB_ACTION` for a Web Action (with or without X-Require-Whisk-Auth header) or `CLOUD_FUNCTION` for an IAM Secured Action. + +* `url` - (Required) URL of the IBM Function. + +* `custom_data` - (Optional) Key value list of additional parameters for the IBM Function. + +* `whisk_auth_token` - (Optional) Only if `ibm_function_type` is `WEB_ACTION`: Whisk authentication token. + +* `iam_api_key` - (Optional) Required if `ibm_function_type` is `CLOUD_FUNCTION`: API Key to call the private cloud function. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +IBM Function notification channels for Monitor can be imported using the ID, e.g. + +``` +$ terraform import sysdig_monitor_notification_channel_ibm_function.example 12345 +``` diff --git a/website/docs/r/monitor_notification_channel_msteams.md b/website/docs/r/monitor_notification_channel_msteams.md index 8f17ad0b..626c0a2e 100644 --- a/website/docs/r/monitor_notification_channel_msteams.md +++ b/website/docs/r/monitor_notification_channel_msteams.md @@ -33,15 +33,18 @@ resource "sysdig_monitor_notification_channel_msteams" "sample-msteams" { * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -50,9 +53,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import MS Teams notification channels for Monitor can be imported using the ID, e.g. diff --git a/website/docs/r/monitor_notification_channel_opsgenie.md b/website/docs/r/monitor_notification_channel_opsgenie.md index 1aa29bee..42d8249d 100644 --- a/website/docs/r/monitor_notification_channel_opsgenie.md +++ b/website/docs/r/monitor_notification_channel_opsgenie.md @@ -43,6 +43,9 @@ resource "sysdig_monitor_notification_channel_opsgenie" "sample-opsgenie" { * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -51,9 +54,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import Opsgenie notification channels for Monitor can be imported using the ID, e.g. diff --git a/website/docs/r/monitor_notification_channel_prometheus_alert_manager.md b/website/docs/r/monitor_notification_channel_prometheus_alert_manager.md new file mode 100644 index 00000000..dd5007c8 --- /dev/null +++ b/website/docs/r/monitor_notification_channel_prometheus_alert_manager.md @@ -0,0 +1,70 @@ +--- +subcategory: "Sysdig Monitor" +layout: "sysdig" +page_title: "Sysdig: sysdig_monitor_notification_channel_prometheus_alert_manager" +description: |- + Creates a Sysdig Monitor Notification Channel of type Prometheus Alert Manager. +--- + +# Resource: sysdig_monitor_notification_channel_prometheus_alert_manager + +Creates a Sysdig Monitor Notification Channel of type Prometheus Alert Manager. + +-> **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 +resource "sysdig_monitor_notification_channel_prometheus_alert_manager" "sample" { + name = "Example Channel - Prometheus Alert Manager" + enabled = true + url = "https://testurl:8080" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + + additional_headers = { + "custom-Header": "TestHeader" + } +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `url` - (Required) URL to send the event. + +* `additional_headers` - (Optional) Key value list of custom headers. + +* `allow_insecure_connections` - (Optional) Whether to skip TLS verification. Default: `false`. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +Prometheus Alert Manager notification channels for Monitor can be imported using the ID, e.g. + +``` +$ terraform import sysdig_monitor_notification_channel_prometheus_alert_manager.example 12345 +``` diff --git a/website/docs/r/monitor_notification_channel_sns.md b/website/docs/r/monitor_notification_channel_sns.md index 2767e37b..58842c1e 100644 --- a/website/docs/r/monitor_notification_channel_sns.md +++ b/website/docs/r/monitor_notification_channel_sns.md @@ -33,15 +33,18 @@ resource "sysdig_monitor_notification_channel_sns" "sample-amazon-sns" { * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -50,9 +53,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import Amazon SNS notification channels for Monitor can be imported using the ID, e.g. diff --git a/website/docs/r/monitor_notification_channel_team_email.md b/website/docs/r/monitor_notification_channel_team_email.md new file mode 100644 index 00000000..d3d44b66 --- /dev/null +++ b/website/docs/r/monitor_notification_channel_team_email.md @@ -0,0 +1,62 @@ +--- +subcategory: "Sysdig Monitor" +layout: "sysdig" +page_title: "Sysdig: sysdig_monitor_notification_channel_team_email" +description: |- + Creates a Sysdig Monitor Notification Channel of type Team Email. +--- + +# Resource: sysdig_monitor_notification_channel_team_email + +Creates a Sysdig Monitor Notification Channel of type Team 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 +resource "sysdig_monitor_notification_channel_team_email" "sample-gchat" { + name = "Example Channel - team email" + team_id = 1 + enabled = true + notify_when_ok = false + notify_when_resolved = false + share_with_current_team = true +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `team_id` - (Required) id of the team. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +Team Email notification channels for Monitor can be imported using the ID, e.g. + +``` +$ terraform import sysdig_monitor_notification_channel_team_email.example 12345 +``` diff --git a/website/docs/r/monitor_notification_channel_victorops.md b/website/docs/r/monitor_notification_channel_victorops.md index d0368687..172a0a3e 100644 --- a/website/docs/r/monitor_notification_channel_victorops.md +++ b/website/docs/r/monitor_notification_channel_victorops.md @@ -32,19 +32,22 @@ resource "sysdig_monitor_notification_channel_victorops" "sample-victorops" { * `api_key` - (Required) Key for the API. -* `routing_key` - (Required) Routing key for VictorOps. +* `routing_key` - (Required) Routing key for VictorOps. * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -53,9 +56,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import VictorOPS notification channels for Monitor can be imported using the ID, e.g. diff --git a/website/docs/r/monitor_notification_channel_webhook.md b/website/docs/r/monitor_notification_channel_webhook.md index ae729b7b..7ac96b63 100644 --- a/website/docs/r/monitor_notification_channel_webhook.md +++ b/website/docs/r/monitor_notification_channel_webhook.md @@ -33,10 +33,10 @@ resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" { * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check diff --git a/website/docs/r/secure_notification_channel_email.md b/website/docs/r/secure_notification_channel_email.md index 5aac2848..d903b9fe 100644 --- a/website/docs/r/secure_notification_channel_email.md +++ b/website/docs/r/secure_notification_channel_email.md @@ -29,20 +29,23 @@ resource "sysdig_secure_notification_channel_email" "sample_email" { * `name` - (Required) The name of the Notification Channel. Must be unique. -* `recipients` - (Required) List of recipients that will receive +* `recipients` - (Required) List of recipients that will receive the message. * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -51,9 +54,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import Email notification channels for Secure can be imported using the ID, e.g. diff --git a/website/docs/r/secure_notification_channel_opsgenie.md b/website/docs/r/secure_notification_channel_opsgenie.md index 0cbe3481..cc8e938a 100644 --- a/website/docs/r/secure_notification_channel_opsgenie.md +++ b/website/docs/r/secure_notification_channel_opsgenie.md @@ -43,6 +43,9 @@ resource "sysdig_secure_notification_channel_opsgenie" "sample-opsgenie" { * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -51,9 +54,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import Opsgenie notification channels for Secure can be imported using the ID, e.g. diff --git a/website/docs/r/secure_notification_channel_prometheus_alert_manager.md b/website/docs/r/secure_notification_channel_prometheus_alert_manager.md new file mode 100644 index 00000000..7bde01e2 --- /dev/null +++ b/website/docs/r/secure_notification_channel_prometheus_alert_manager.md @@ -0,0 +1,70 @@ +--- +subcategory: "Sysdig Secure" +layout: "sysdig" +page_title: "Sysdig: sysdig_secure_notification_channel_prometheus_alert_manager" +description: |- + Creates a Sysdig Secure Notification Channel of type Prometheus Alert Manager. +--- + +# Resource: sysdig_secure_notification_channel_prometheus_alert_manager + +Creates a Sysdig Secure Notification Channel of type Prometheus Alert Manager. + +-> **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 +resource "sysdig_secure_notification_channel_prometheus_alert_manager" "sample" { + name = "Example Channel - Prometheus Alert Manager" + enabled = true + url = "https://testurl:8080" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + + additional_headers = { + "custom-Header": "TestHeader" + } +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `url` - (Required) URL to send the event. + +* `additional_headers` - (Optional) Key value list of custom headers. + +* `allow_insecure_connections` - (Optional) Whether to skip TLS verification. Default: `false`. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +Prometheus Alert Manager notification channels for Secure can be imported using the ID, e.g. + +``` +$ terraform import sysdig_secure_notification_channel_prometheus_alert_manager.example 12345 +``` diff --git a/website/docs/r/secure_notification_channel_sns.md b/website/docs/r/secure_notification_channel_sns.md index c0c1877a..95bd3aca 100644 --- a/website/docs/r/secure_notification_channel_sns.md +++ b/website/docs/r/secure_notification_channel_sns.md @@ -33,15 +33,18 @@ resource "sysdig_secure_notification_channel_sns" "sample-amazon-sns" { * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -50,9 +53,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import SNS notification channels for Secure can be imported using the ID, e.g. diff --git a/website/docs/r/secure_notification_channel_team_email.md b/website/docs/r/secure_notification_channel_team_email.md new file mode 100644 index 00000000..aa3f0a8f --- /dev/null +++ b/website/docs/r/secure_notification_channel_team_email.md @@ -0,0 +1,62 @@ +--- +subcategory: "Sysdig Secure" +layout: "sysdig" +page_title: "Sysdig: sysdig_secure_notification_channel_team_email" +description: |- + Creates a Sysdig Secure Notification Channel of type Team Email. +--- + +# Resource: sysdig_secure_notification_channel_team_email + +Creates a Sysdig Secure Notification Channel of type Team 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 +resource "sysdig_secure_notification_channel_team_email" "sample-gchat" { + name = "Example Channel - team email" + team_id = 1 + enabled = true + notify_when_ok = false + notify_when_resolved = false + share_with_current_team = true +} +``` + +## Argument Reference + +* `name` - (Required) The name of the Notification Channel. Must be unique. + +* `team_id` - (Required) id of the team. + +* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. + +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is + no longer triggered. Default is false. + +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually + acknowledged by a user. Default is false. + +* `send_test_notification` - (Optional) Send an initial test notification to check + if the notification channel is working. Default is false. + +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - (Computed) The ID of the Notification Channel. + +* `version` - (Computed) The current version of the Notification Channel. + +## Import + +Team email notification channels for Secure can be imported using the ID, e.g. + +``` +$ terraform import sysdig_secure_notification_channel_team_email.example 12345 +``` diff --git a/website/docs/r/secure_notification_channel_victorops.md b/website/docs/r/secure_notification_channel_victorops.md index dd44bb90..8c47c3d7 100644 --- a/website/docs/r/secure_notification_channel_victorops.md +++ b/website/docs/r/secure_notification_channel_victorops.md @@ -32,19 +32,22 @@ resource "sysdig_secure_notification_channel_victorops" "sample-victorops" { * `api_key` - (Required) Key for the API. -* `routing_key` - (Required) Routing key for VictorOps. +* `routing_key` - (Required) Routing key for VictorOps. * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). + Otherwise, it will share it with all teams, which is the default behaviour. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: @@ -53,9 +56,6 @@ In addition to all arguments above, the following attributes are exported: * `version` - (Computed) The current version of the Notification Channel. -* `share_with_current_team` - (Optional) If set to `true` it will share notification channel only with current team (in which user is logged in). - Otherwise, it will share it with all teams, which is the default behaviour. - ## Import VictorOPS notification channels for Secure can be imported using the ID, e.g. diff --git a/website/docs/r/secure_notification_channel_webhook.md b/website/docs/r/secure_notification_channel_webhook.md index 583b0a34..874a6ca4 100644 --- a/website/docs/r/secure_notification_channel_webhook.md +++ b/website/docs/r/secure_notification_channel_webhook.md @@ -33,15 +33,17 @@ resource "sysdig_secure_notification_channel_webhook" "sample-webhook" { * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. -* `notify_when_ok` - (Optional) Send a new notification when the alert condition is +* `notify_when_ok` - (Optional) Send a new notification when the alert condition is no longer triggered. Default is false. -* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually +* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually acknowledged by a user. Default is false. * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `additional_headers` - (Optional) Key value list of custom headers. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: