From ed93948a8c7b5c5113af8b5bc78ec99e70b077bf Mon Sep 17 00:00:00 2001 From: Diego Bonfigli Date: Thu, 3 Aug 2023 18:54:35 +0200 Subject: [PATCH] feat(notification channel): add notification channels types --- .github/workflows/test.yml | 1 + ...urce_sysdig_secure_notification_channel.go | 22 +- sysdig/internal/client/v2/model.go | 31 +-- sysdig/provider.go | 104 +++++----- ...tor_notification_channel_custom_webhook.go | 185 +++++++++++++++++ ...otification_channel_custom_webhook_test.go | 147 +++++++++++++ ...sdig_monitor_notification_channel_email.go | 9 +- ...monitor_notification_channel_email_test.go | 2 +- ...onitor_notification_channel_google_chat.go | 163 +++++++++++++++ ...r_notification_channel_google_chat_test.go | 68 ++++++ ...notification_channel_ibm_cloud_function.go | 196 ++++++++++++++++++ ...ication_channel_ibm_cloud_function_test.go | 122 +++++++++++ ...fication_channel_ibm_event_notification.go | 163 +++++++++++++++ ...ion_channel_ibm_event_notification_test.go | 79 +++++++ ...ig_monitor_notification_channel_msteams.go | 6 +- ...nitor_notification_channel_msteams_test.go | 13 +- ...g_monitor_notification_channel_opsgenie.go | 9 +- ...itor_notification_channel_opsgenie_test.go | 2 +- ..._monitor_notification_channel_pagerduty.go | 9 +- ...tor_notification_channel_pagerduty_test.go | 2 +- ...cation_channel_prometheus_alert_manager.go | 171 +++++++++++++++ ...n_channel_prometheus_alert_manager_test.go | 114 ++++++++++ ...sdig_monitor_notification_channel_slack.go | 27 ++- ...monitor_notification_channel_slack_test.go | 2 +- ...sysdig_monitor_notification_channel_sns.go | 10 +- ...g_monitor_notification_channel_sns_test.go | 2 +- ...monitor_notification_channel_team_email.go | 154 ++++++++++++++ ...or_notification_channel_team_email_test.go | 80 +++++++ ..._monitor_notification_channel_victorops.go | 9 +- ...tor_notification_channel_victorops_test.go | 2 +- ...ig_monitor_notification_channel_webhook.go | 7 +- ...nitor_notification_channel_webhook_test.go | 2 +- ...sdig_secure_notification_channel_common.go | 9 +- ...ysdig_secure_notification_channel_email.go | 8 +- ..._secure_notification_channel_email_test.go | 2 +- ...dig_secure_notification_channel_msteams.go | 2 +- ...ecure_notification_channel_msteams_test.go | 2 +- ...ig_secure_notification_channel_opsgenie.go | 8 +- ...cure_notification_channel_opsgenie_test.go | 2 +- ...g_secure_notification_channel_pagerduty.go | 8 +- ...ure_notification_channel_pagerduty_test.go | 2 +- ...cation_channel_prometheus_alert_manager.go | 172 +++++++++++++++ ...n_channel_prometheus_alert_manager_test.go | 114 ++++++++++ ...ysdig_secure_notification_channel_slack.go | 6 +- ..._secure_notification_channel_slack_test.go | 2 +- ..._sysdig_secure_notification_channel_sns.go | 9 +- ...ig_secure_notification_channel_sns_test.go | 2 +- ..._secure_notification_channel_team_email.go | 154 ++++++++++++++ ...re_notification_channel_team_email_test.go | 76 +++++++ ...g_secure_notification_channel_victorops.go | 8 +- ...ure_notification_channel_victorops_test.go | 2 +- ...dig_secure_notification_channel_webhook.go | 13 +- ...ecure_notification_channel_webhook_test.go | 2 +- website/docs/index.md | 36 ++-- ...tor_notification_channel_custom_webhook.md | 77 +++++++ .../r/monitor_notification_channel_email.md | 12 +- ...onitor_notification_channel_google_chat.md | 62 ++++++ ...fication_channel_ibm_event_notification.md | 62 ++++++ ...nitor_notification_channel_ibm_function.md | 85 ++++++++ .../r/monitor_notification_channel_msteams.md | 10 +- .../monitor_notification_channel_opsgenie.md | 6 +- ...cation_channel_prometheus_alert_manager.md | 70 +++++++ .../r/monitor_notification_channel_sns.md | 10 +- ...monitor_notification_channel_team_email.md | 62 ++++++ .../monitor_notification_channel_victorops.md | 12 +- .../r/monitor_notification_channel_webhook.md | 4 +- .../r/secure_notification_channel_email.md | 12 +- .../r/secure_notification_channel_opsgenie.md | 6 +- ...cation_channel_prometheus_alert_manager.md | 70 +++++++ .../docs/r/secure_notification_channel_sns.md | 10 +- .../secure_notification_channel_team_email.md | 62 ++++++ .../secure_notification_channel_victorops.md | 12 +- .../r/secure_notification_channel_webhook.md | 6 +- 73 files changed, 2984 insertions(+), 218 deletions(-) create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_custom_webhook.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_custom_webhook_test.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_google_chat.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_google_chat_test.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function_test.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification_test.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager_test.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_team_email.go create mode 100644 sysdig/resource_sysdig_monitor_notification_channel_team_email_test.go create mode 100644 sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager.go create mode 100644 sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager_test.go create mode 100644 sysdig/resource_sysdig_secure_notification_channel_team_email.go create mode 100644 sysdig/resource_sysdig_secure_notification_channel_team_email_test.go create mode 100644 website/docs/r/monitor_notification_channel_custom_webhook.md create mode 100644 website/docs/r/monitor_notification_channel_google_chat.md create mode 100644 website/docs/r/monitor_notification_channel_ibm_event_notification.md create mode 100644 website/docs/r/monitor_notification_channel_ibm_function.md create mode 100644 website/docs/r/monitor_notification_channel_prometheus_alert_manager.md create mode 100644 website/docs/r/monitor_notification_channel_team_email.md create mode 100644 website/docs/r/secure_notification_channel_prometheus_alert_manager.md create mode 100644 website/docs/r/secure_notification_channel_team_email.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 628753d5f..e203a0721 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: "973d1834-9731-4c39-8f04-6e860c7e4174" 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 fa231044d..a041e160a 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 c3602081d..7edc91319 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/provider.go b/sysdig/provider.go index 9f5d3d3dd..b7fb68d4e 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 000000000..dc21e1acf --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_custom_webhook.go @@ -0,0 +1,185 @@ +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 { + d.SetId("") + 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 000000000..5411fa20e --- /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 e9a73872a..13c6dab76 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) } @@ -91,8 +91,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 25dde3d5a..cb4cb7ef5 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 000000000..bebdcc732 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_google_chat.go @@ -0,0 +1,163 @@ +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 { + d.SetId("") + 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 000000000..e71c1e58b --- /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 000000000..e956d38ec --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_cloud_function.go @@ -0,0 +1,196 @@ +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 { + d.SetId("") + 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 000000000..25013b45c --- /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 000000000..2a6e9fe08 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification.go @@ -0,0 +1,163 @@ +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 { + d.SetId("") + 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 000000000..d04f542b5 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_ibm_event_notification_test.go @@ -0,0 +1,79 @@ +//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: func() { + if v := os.Getenv("SYSDIG_IBM_MONITOR_API_KEY"); v == "" { + t.Fatal("SYSDIG_IBM_MONITOR_API_KEY must be set for acceptance tests") + } + }, + ProviderFactories: map[string]func() (*schema.Provider, error){ + "sysdig": func() (*schema.Provider, error) { + return sysdig.Provider(), nil + }, + }, + Steps: []resource.TestStep{ + { + Config: 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 a9f954cff..d8899b4d2 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) } @@ -93,8 +92,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 f345ba896..b57116bfa 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 90f7c81a6..c226cae3c 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) } @@ -96,8 +96,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 4c496082d..9fca3e88c 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 42a78a618..faa846f25 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) } @@ -97,8 +97,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 f31cc4b92..5174f63d5 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 000000000..2dc7e1c7d --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_prometheus_alert_manager.go @@ -0,0 +1,171 @@ +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 { + d.SetId("") + 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 000000000..da8f9ea7d --- /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 1576cb213..e0e04063b 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,7 +75,11 @@ func resourceSysdigMonitorNotificationChannelSlackRead(ctx context.Context, d *s return diag.FromErr(err) } - id, _ := strconv.Atoi(d.Id()) + id, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + nc, err := client.GetNotificationChannelById(ctx, id) if err != nil { @@ -92,8 +96,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 +112,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 +133,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 f91970d79..fbdfd5bfd 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 298d35915..a7e9ca4ed 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) } @@ -90,8 +90,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 +150,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 c83669cd6..9a5477d56 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 000000000..a7d1aed59 --- /dev/null +++ b/sysdig/resource_sysdig_monitor_notification_channel_team_email.go @@ -0,0 +1,154 @@ +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 { + d.SetId("") + 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 000000000..411294930 --- /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 f0496ed73..164b9d8e8 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) } @@ -92,8 +92,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 6228ad5e7..a432e12c2 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 8b22a9760..c8e33df00 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" @@ -93,8 +94,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 +132,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 f989d7c2d..10a7d71a0 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 5b9e358a5..8baa07183 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 ca6ae52b6..f24208cb4 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 { @@ -79,6 +79,7 @@ func resourceSysdigSecureNotificationChannelEmailRead(ctx context.Context, d *sc if err != nil { d.SetId("") + return diag.FromErr(err) } err = secureNotificationChannelEmailToResourceData(&nc, d) @@ -128,6 +129,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 ccc748590..0f0d92b16 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 9553e3052..26058c099 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" ) @@ -142,6 +141,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 c2926baf6..885de1d2c 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 369e28195..bd790f1c2 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 { @@ -84,6 +84,7 @@ func resourceSysdigSecureNotificationChannelOpsGenieRead(ctx context.Context, d if err != nil { d.SetId("") + return diag.FromErr(err) } err = secureNotificationChannelOpsGenieToResourceData(&nc, d) @@ -133,6 +134,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 e55597729..5a1e97f5c 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 8f2ad9386..9b1efcbc5 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 { @@ -85,6 +85,7 @@ func resourceSysdigSecureNotificationChannelPagerdutyRead(ctx context.Context, d if err != nil { d.SetId("") + return diag.FromErr(err) } err = secureNotificationChannelPagerdutyToResourceData(&nc, d) @@ -134,6 +135,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 2a79f999c..5609692ac 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 000000000..a7fb6ea71 --- /dev/null +++ b/sysdig/resource_sysdig_secure_notification_channel_prometheus_alert_manager.go @@ -0,0 +1,172 @@ +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 { + d.SetId("") + 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 000000000..f900d26f5 --- /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 4902a1fc4..866808979 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 { @@ -150,6 +147,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 1561e1e61..dccd9e82b 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 8c66c4658..9b4cbe107 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 { @@ -79,6 +78,7 @@ func resourceSysdigSecureNotificationChannelSNSRead(ctx context.Context, d *sche if err != nil { d.SetId("") + return diag.FromErr(err) } err = secureNotificationChannelSNSToResourceData(&nc, d) @@ -128,6 +128,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 d15716416..d1f4651c6 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 000000000..8af3689e0 --- /dev/null +++ b/sysdig/resource_sysdig_secure_notification_channel_team_email.go @@ -0,0 +1,154 @@ +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 { + d.SetId("") + 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 000000000..a60093943 --- /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 01e3a54d2..3fdd4e324 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 { @@ -81,6 +80,7 @@ func resourceSysdigSecureNotificationChannelVictorOpsRead(ctx context.Context, d if err != nil { d.SetId("") + 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 f3145b98d..a08fde137 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 01de6ff22..31c538ee4 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 { @@ -77,6 +81,7 @@ func resourceSysdigSecureNotificationChannelWebhookRead(ctx context.Context, d * if err != nil { d.SetId("") + return diag.FromErr(err) } err = secureNotificationChannelWebhookToResourceData(&nc, d) @@ -138,6 +143,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 +154,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 4370cf7a7..292ccf295 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 563af3f7e..2b641a650 100644 --- a/website/docs/index.md +++ b/website/docs/index.md @@ -17,7 +17,7 @@ optional. For either options, the corresponding **URL** and **API Token** must be configured. See options below. -Sysdig provider can also be used to interact with [IBM Cloud Monitoring](https://cloud.ibm.com/docs/monitoring?topic=monitoring-getting-started). For more details check `IBM Cloud Monitoring Authentication` example and configuration reference below. +Sysdig provider can also be used to interact with [IBM Cloud Monitoring](https://cloud.ibm.com/docs/monitoring?topic=monitoring-getting-started). For more details check `IBM Cloud Monitoring Authentication` example and configuration reference below. Use the navigation to the left to read about the available resources. @@ -41,7 +41,7 @@ terraform { ```terraform provider "sysdig" { sysdig_monitor_url = "https://app.sysdigcloud.com" - sysdig_monitor_api_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + sysdig_monitor_api_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -58,13 +58,13 @@ provider "sysdig" { ```terraform provider "sysdig" { - + sysdig_secure_url="https://secure.sysdig.com" sysdig_secure_api_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - + sysdig_monitor_url = "https://app.sysdigcloud.com" sysdig_monitor_api_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - + extra_headers = { "Proxy-Authorization": "Basic xxxxxxxxxxxxxxxx" } @@ -114,9 +114,9 @@ optional. When Monitor resources are to be created, this authentication must be in place. * `sysdig_monitor_url` - (Required) This is the target Sysdig Monitor base API - endpoint. It's intended to be used with OnPrem installations. + endpoint. It's intended to be used with OnPrem installations.
By default, it points to `https://app.sysdigcloud.com`. [Find your Sysdig Saas region url](https://docs.sysdig.com/en/docs/administration/saas-regions-and-ip-ranges/#saas-regions-and-ip-ranges) (Sysdig Monitor endpoint)
- It can also be sourced from the `SYSDIG_MONITOR_URL` environment variable.
Notice: it should not be ended with a + It can also be sourced from the `SYSDIG_MONITOR_URL` environment variable.
Notice: it should not be ended with a slash.

* `sysdig_monitor_api_token` - (Required) The Sysdig Monitor API token. @@ -136,7 +136,7 @@ When Secure resources are to be created, this authentication must be in place. * `sysdig_secure_url` - (Required) This is the target Sysdig Secure base API endpoint. It's intended to be used with OnPrem installations. -
By default, it points to `https://secure.sysdig.com`. +
By default, it points to `https://secure.sysdig.com`.
[Find your Sysdig Saas region url](https://docs.sysdig.com/en/docs/administration/saas-regions-and-ip-ranges/#saas-regions-and-ip-ranges) (Secure endpoint)
It can also be sourced from the `SYSDIG_SECURE_URL` environment variable.
Notice: it should not be ended with a slash.

@@ -147,7 +147,7 @@ When Secure resources are to be created, this authentication must be in place.
Required if any `sysdig_secure_*` resource or data source is used.

* `sysdig_secure_insecure_tls` - (Optional) Defines if the HTTP client can ignore - the use of invalid HTTPS certificates in the Secure API. It can be useful for + the use of invalid HTTPS certificates in the Secure API. It can be useful for on-prem installations. It can also be sourced from the `SYSDIG_SECURE_INSECURE_TLS` environment variable. By default, this is false.

@@ -159,13 +159,13 @@ When IBM Cloud Monitoring resources are to be created, this authentication must * `sysdig_monitor_url` - (Required) This is the target IBM Cloud Monitoring API endpoint. It can also be sourced from the `SYSDIG_MONITOR_URL` environment variable. [Find your IBM Cloud Monitoring region url](https://cloud.ibm.com/docs/monitoring?topic=monitoring-endpoints#endpoints_monitoring).
Notice: it should not be ended with a slash.

-* `ibm_monitor_iam_url` - (Required) This is the target IAM endpoint used to issue IBM IAM token by consuming `ibm_monitor_api_key`. +* `ibm_monitor_iam_url` - (Required) This is the target IAM endpoint used to issue IBM IAM token by consuming `ibm_monitor_api_key`. Provider will handle token expiration and refresh it when needed.
It can also be configured from the `SYSDIG_IBM_MONITOR_IAM_URL` environment variable.

* `ibm_monitor_instance_id` (Required) This is the target instance ID (GUID format) of IBM instance which is hosting IBM Cloud Monitoring.
It can also be configured from the `SYSDIG_IBM_MONITOR_INSTANCE_ID` environment variable.

-* `ibm_monitor_api_key` (Required) An API key is a unique code that is passed to an IBM IAM service to generate IAM token used for making HTTP request against IBM endpoints. +* `ibm_monitor_api_key` (Required) An API key is a unique code that is passed to an IBM IAM service to generate IAM token used for making HTTP request against IBM endpoints. This argument can be used to specify any kind of IBM API keys (User API key, Service ID, ...).
It can also be configured from the `SYSDIG_IBM_MONITOR_API_KEY` environment variable.

@@ -173,10 +173,10 @@ When IBM Cloud Monitoring resources are to be created, this authentication must the use of invalid HTTPS certificates in the IBM Monitoring Cloud API.
It can also be sourced from the `SYSDIG_MONITOR_INSECURE_TLS` environment variable. By default, this is false.

-* `sysdig_monitor_team_id` - (Optional) Use this argument to specify team in which you will be logged in. +* `sysdig_monitor_team_id` - (Optional) Use this argument to specify team in which you will be logged in. If not specified, default team will be used. This argument has precedence over `sysdig_monitor_team_name` if both are specified.
It can also be configured from the `SYSDIG_MONITOR_TEAM_ID` environment variable.

-* `sysdig_monitor_team_name` - (Optional) This argument is the alternative way of specifying team in which you will be logged in. +* `sysdig_monitor_team_name` - (Optional) This argument is the alternative way of specifying team in which you will be logged in. It has exactly the same meaning as `sysdig_monitor_team_id`, but instead of specifying team ID you are specifying a team name.
It can also be configured from the `SYSDIG_MONITOR_TEAM_NAME` environment variable.

@@ -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` @@ -235,7 +243,7 @@ When IBM Workload Protection resources are to be created, this authentication mu > - `sysdig_monitor_alert_anomaly` > - `sysdig_monitor_alert_group_outlier` > - `sysdig_secure_posture_zone` -> +> > And data sources: > - `sysdig_monitor_notification_channel_pagerduty` > - `sysdig_monitor_notification_channel_email` 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 000000000..fea5dc78a --- /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 ee7ff1f84..8fd73dd3e 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 000000000..858e9dcb9 --- /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 000000000..1c75c1bf9 --- /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 availabe 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 000000000..cbb0ce08b --- /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 8f17ad0ba..626c0a2ed 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 1aa29bee8..42d8249d3 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 000000000..dd5007c8e --- /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 2767e37b7..58842c1e8 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 000000000..d3d44b667 --- /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 d03686871..172a0a3e0 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 ae729b7bc..7ac96b63c 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 5aac28488..d903b9fe7 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 0cbe3481b..cc8e938a0 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 000000000..7bde01e27 --- /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 c0c1877a3..95bd3aca9 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 000000000..aa3f0a8ff --- /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 dd44bb902..8c47c3d76 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 583b0a340..874a6ca40 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: