Skip to content

Commit 98c97e3

Browse files
authored
feat(logs): alert_definitins, policy order and dashboard fix (IBM-Cloud#6526)
* Support order and enable in ibm_logs_policy * fix(policy) address review comment * support alertsdef resource and datasource * fix(alerts): alerts resource and datasource * fix(alerts): alerts resource and datasource * update alert definitions docs * fix logs policy docs * fix alerts testcases
1 parent 6c9bad9 commit 98c97e3

26 files changed

+14624
-282
lines changed

examples/ibm-logs/README.md

Lines changed: 319 additions & 8 deletions
Large diffs are not rendered by default.

examples/ibm-logs/main.tf

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,19 @@ resource "ibm_logs_outgoing_webhook" "logs_outgoing_webhook_instance" {
113113
region_id = "eu-es"
114114
source_id = "crn:v1:staging:public:logs:eu-gb:a/223af6f4260f42ebe23e95fcddd33cb7:63a3e4be-cb73-4f52-898e-8e93484a70a5::"
115115
source_name = "IBM Cloud Event Notifications"
116+
endpoint_type = "private"
116117
}
117118
}
118119

119120
// Provision logs_policy resource instance
120121
resource "ibm_logs_policy" "logs_policy_instance" {
122+
before {
123+
id = "9fab83da-98cb-4f18-a7ba-b6f0435c9673"
124+
}
121125
name = var.logs_policy_name
122126
description = var.logs_policy_description
123127
priority = var.logs_policy_priority
128+
enabled = var.logs_policy_enabled
124129
application_rule {
125130
rule_type_id = "includes"
126131
name = "Rule Name"
@@ -224,6 +229,9 @@ resource "ibm_logs_dashboard" "logs_dashboard_instance" {
224229
updated_at = "2021-01-01T00:00:00.000Z"
225230
}
226231
}
232+
options {
233+
internal = { }
234+
}
227235
}
228236
}
229237
variables {
@@ -242,9 +250,14 @@ resource "ibm_logs_dashboard" "logs_dashboard_instance" {
242250
all = { }
243251
}
244252
values_order_direction = "desc"
253+
selection_options {
254+
selection_type = "single"
255+
}
245256
}
246257
}
247258
display_name = "Service Name"
259+
description = "description"
260+
display_type = "nothing"
248261
}
249262
filters {
250263
source {
@@ -364,6 +377,42 @@ resource "ibm_logs_view_folder" "logs_view_folder_instance" {
364377
name = var.logs_view_folder_name
365378
}
366379

380+
// Provision logs_data_access_rule resource instance
381+
resource "ibm_logs_data_access_rule" "logs_data_access_rule_instance" {
382+
display_name = var.logs_data_access_rule_display_name
383+
description = var.logs_data_access_rule_description
384+
filters {
385+
entity_type = "logs"
386+
expression = "true"
387+
}
388+
default_expression = var.logs_data_access_rule_default_expression
389+
}
390+
391+
// Provision logs_enrichment resource instance
392+
resource "ibm_logs_enrichment" "logs_enrichment_instance" {
393+
field_name = var.logs_enrichment_field_name
394+
enrichment_type {
395+
geo_ip = { }
396+
}
397+
}
398+
399+
// Provision logs_data_usage_metrics resource instance
400+
resource "ibm_logs_data_usage_metrics" "logs_data_usage_metrics_instance" {
401+
enabled = var.logs_data_usage_metrics_enabled
402+
}
403+
404+
// Provision logs_stream resource instance
405+
resource "ibm_logs_stream" "logs_stream_instance" {
406+
name = var.logs_stream_name
407+
is_active = var.logs_stream_is_active
408+
dpxl_expression = var.logs_stream_dpxl_expression
409+
compression_type = var.logs_stream_compression_type
410+
ibm_event_streams {
411+
brokers = "kafka01.example.com:9093"
412+
topic = "live.screen"
413+
}
414+
}
415+
367416
// Data source is not linked to a resource instance
368417
// Uncomment if an existing data source instance exists
369418
/*
@@ -444,6 +493,14 @@ data "ibm_logs_dashboard" "logs_dashboard_instance" {
444493
}
445494
*/
446495

496+
// Data source is not linked to a resource instance
497+
// Uncomment if an existing data source instance exists
498+
/*
499+
// Create logs_dashboard_folder data source
500+
data "ibm_logs_dashboard_folder" "logs_dashboard_folder_instance" {
501+
}
502+
*/
503+
447504
// Data source is not linked to a resource instance
448505
// Uncomment if an existing data source instance exists
449506
/*
@@ -452,6 +509,14 @@ data "ibm_logs_dashboard_folders" "logs_dashboard_folders_instance" {
452509
}
453510
*/
454511

512+
// Data source is not linked to a resource instance
513+
// Uncomment if an existing data source instance exists
514+
/*
515+
// Create logs_dashboards data source
516+
data "ibm_logs_dashboards" "logs_dashboards_instance" {
517+
}
518+
*/
519+
455520
// Data source is not linked to a resource instance
456521
// Uncomment if an existing data source instance exists
457522
/*
@@ -502,3 +567,80 @@ data "ibm_logs_view_folder" "logs_view_folder_instance" {
502567
data "ibm_logs_view_folders" "logs_view_folders_instance" {
503568
}
504569
*/
570+
571+
// Data source is not linked to a resource instance
572+
// Uncomment if an existing data source instance exists
573+
/*
574+
// Create logs_data_access_rule data source
575+
data "ibm_logs_data_access_rule" "logs_data_access_rule_instance" {
576+
logs_data_access_rule_id = var.data_logs_data_access_rule_logs_data_access_rule_id
577+
}
578+
*/
579+
580+
// Data source is not linked to a resource instance
581+
// Uncomment if an existing data source instance exists
582+
/*
583+
// Create logs_data_access_rules data source
584+
data "ibm_logs_data_access_rules" "logs_data_access_rules_instance" {
585+
logs_data_access_rules_id = var.logs_data_access_rules_logs_data_access_rules_id
586+
}
587+
*/
588+
589+
// Data source is not linked to a resource instance
590+
// Uncomment if an existing data source instance exists
591+
/*
592+
// Create logs_enrichment data source
593+
data "ibm_logs_enrichment" "logs_enrichment_instance" {
594+
}
595+
*/
596+
597+
// Data source is not linked to a resource instance
598+
// Uncomment if an existing data source instance exists
599+
/*
600+
// Create logs_enrichments data source
601+
data "ibm_logs_enrichments" "logs_enrichments_instance" {
602+
}
603+
*/
604+
605+
// Data source is not linked to a resource instance
606+
// Uncomment if an existing data source instance exists
607+
/*
608+
// Create logs_data_usage_metrics data source
609+
data "ibm_logs_data_usage_metrics" "logs_data_usage_metrics_instance" {
610+
range = var.data_logs_data_usage_metrics_range
611+
query = var.data_logs_data_usage_metrics_query
612+
}
613+
*/
614+
615+
// Data source is not linked to a resource instance
616+
// Uncomment if an existing data source instance exists
617+
/*
618+
// Create logs_stream data source
619+
data "ibm_logs_stream" "logs_stream_instance" {
620+
}
621+
*/
622+
623+
// Data source is not linked to a resource instance
624+
// Uncomment if an existing data source instance exists
625+
/*
626+
// Create logs_streams data source
627+
data "ibm_logs_streams" "logs_streams_instance" {
628+
}
629+
*/
630+
631+
// Data source is not linked to a resource instance
632+
// Uncomment if an existing data source instance exists
633+
/*
634+
// Create logs_alert_definition data source
635+
data "ibm_logs_alert_definition" "logs_alert_definition_instance" {
636+
logs_alert_definition_id = var.data_logs_alert_definition_logs_alert_definition_id
637+
}
638+
*/
639+
640+
// Data source is not linked to a resource instance
641+
// Uncomment if an existing data source instance exists
642+
/*
643+
// Create logs_alert_definitions data source
644+
data "ibm_logs_alert_definitions" "logs_alert_definitions_instance" {
645+
}
646+
*/

examples/ibm-logs/outputs.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,27 @@ output "ibm_logs_view_folder" {
5252
value = ibm_logs_view_folder.logs_view_folder_instance
5353
description = "logs_view_folder resource instance"
5454
}
55+
// This output allows logs_data_access_rule data to be referenced by other resources and the terraform CLI
56+
// Modify this output if only certain data should be exposed
57+
output "ibm_logs_data_access_rule" {
58+
value = ibm_logs_data_access_rule.logs_data_access_rule_instance
59+
description = "logs_data_access_rule resource instance"
60+
}
61+
// This output allows logs_enrichment data to be referenced by other resources and the terraform CLI
62+
// Modify this output if only certain data should be exposed
63+
output "ibm_logs_enrichment" {
64+
value = ibm_logs_enrichment.logs_enrichment_instance
65+
description = "logs_enrichment resource instance"
66+
}
67+
// This output allows logs_data_usage_metrics data to be referenced by other resources and the terraform CLI
68+
// Modify this output if only certain data should be exposed
69+
output "ibm_logs_data_usage_metrics" {
70+
value = ibm_logs_data_usage_metrics.logs_data_usage_metrics_instance
71+
description = "logs_data_usage_metrics resource instance"
72+
}
73+
// This output allows logs_stream data to be referenced by other resources and the terraform CLI
74+
// Modify this output if only certain data should be exposed
75+
output "ibm_logs_stream" {
76+
value = ibm_logs_stream.logs_stream_instance
77+
description = "logs_stream resource instance"
78+
}

examples/ibm-logs/variables.tf

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ variable "logs_policy_priority" {
9090
type = string
9191
default = "type_high"
9292
}
93+
variable "logs_policy_enabled" {
94+
description = "Flag to enable or disable a policy. This flag is supported only while updating a policy, since the policies are always enabled during creation."
95+
type = bool
96+
default = true
97+
}
9398

9499
// Resource arguments for logs_dashboard
95100
variable "logs_dashboard_href" {
@@ -161,6 +166,58 @@ variable "logs_view_folder_name" {
161166
default = "My Folder"
162167
}
163168

169+
// Resource arguments for logs_data_access_rule
170+
variable "logs_data_access_rule_display_name" {
171+
description = "Data Access Rule Display Name."
172+
type = string
173+
default = "Test Data Access Rule"
174+
}
175+
variable "logs_data_access_rule_description" {
176+
description = "Optional Data Access Rule Description."
177+
type = string
178+
default = "Data Access Rule intended for testing"
179+
}
180+
variable "logs_data_access_rule_default_expression" {
181+
description = "Default expression to use when no filter matches the query."
182+
type = string
183+
default = "<v1>true"
184+
}
185+
186+
// Resource arguments for logs_enrichment
187+
variable "logs_enrichment_field_name" {
188+
description = "The enrichment field name."
189+
type = string
190+
default = "ip"
191+
}
192+
193+
// Resource arguments for logs_data_usage_metrics
194+
variable "logs_data_usage_metrics_enabled" {
195+
description = "The \"enabled\" parameter for metrics export."
196+
type = bool
197+
default = true
198+
}
199+
200+
// Resource arguments for logs_stream
201+
variable "logs_stream_name" {
202+
description = "The name of the Event stream."
203+
type = string
204+
default = "Live Screen"
205+
}
206+
variable "logs_stream_is_active" {
207+
description = "Whether the Event stream is active."
208+
type = bool
209+
default = true
210+
}
211+
variable "logs_stream_dpxl_expression" {
212+
description = "The DPXL expression of the Event stream."
213+
type = string
214+
default = "<v1>contains(kubernetes.labels.CX_AZ, 'eu-west-1')"
215+
}
216+
variable "logs_stream_compression_type" {
217+
description = "The compression type of the stream."
218+
type = string
219+
default = "gzip"
220+
}
164221
// Data source arguments for logs_alert
165222
variable "data_logs_alert_logs_alert_id" {
166223
description = "Alert ID."
@@ -218,6 +275,8 @@ variable "data_logs_dashboard_dashboard_id" {
218275
}
219276

220277

278+
279+
221280
// Data source arguments for logs_e2m
222281
variable "data_logs_e2m_logs_e2m_id" {
223282
description = "ID of e2m to be deleted."
@@ -241,3 +300,33 @@ variable "data_logs_view_folder_logs_view_folder_id" {
241300
default = 3dc02998-0b50-4ea8-b68a-4779d716fa1f
242301
}
243302

303+
304+
// Data source arguments for logs_data_access_rule
305+
variable "data_logs_data_access_rule_logs_data_access_rule_id" {
306+
description = "Array of data access rule IDs."
307+
type = list()
308+
default = ["4f966911-4bda-407e-b069-477394effa59"]
309+
}
310+
311+
// Data source arguments for logs_data_access_rules
312+
variable "logs_data_access_rules_logs_data_access_rules_id" {
313+
description = "Array of data access rule IDs."
314+
type = list()
315+
default = ["4f966911-4bda-407e-b069-477394effa59"]
316+
}
317+
318+
319+
320+
// Data source arguments for logs_data_usage_metrics
321+
variable "data_logs_data_usage_metrics_range" {
322+
description = "Range of days to get the data usage for, by default it will use current month."
323+
type = string
324+
default = "last_week"
325+
}
326+
variable "data_logs_data_usage_metrics_query" {
327+
description = "Query to filter daily or detailed the data usage, by default it will use daily one."
328+
type = string
329+
default = "daily"
330+
}
331+
332+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20250305134146-e023c2e84762
2525
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
2626
github.com/IBM/keyprotect-go-client v0.15.1
27-
github.com/IBM/logs-go-sdk v0.4.0
27+
github.com/IBM/logs-go-sdk v0.5.0
2828
github.com/IBM/logs-router-go-sdk v1.0.8
2929
github.com/IBM/mqcloud-go-sdk v0.4.0
3030
github.com/IBM/networking-go-sdk v0.51.12

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYt
140140
github.com/IBM/keyprotect-go-client v0.5.1/go.mod h1:5TwDM/4FRJq1ZOlwQL1xFahLWQ3TveR88VmL1u3njyI=
141141
github.com/IBM/keyprotect-go-client v0.15.1 h1:m4qzqF5zOumRxKZ8s7vtK7A/UV/D278L8xpRG+WgT0s=
142142
github.com/IBM/keyprotect-go-client v0.15.1/go.mod h1:asXtHwL/4uCHA221Vd/7SkXEi2pcRHDzPyyksc1DthE=
143-
github.com/IBM/logs-go-sdk v0.4.0 h1:CyUjm19EUtcJjf4mxsj6Rc7gkZDT8JEY5rLUIz8Eoag=
144-
github.com/IBM/logs-go-sdk v0.4.0/go.mod h1:yv/GCXC4/p+MZEeXl4xjZAOMvDAVRwu61WyHZFKFXQM=
143+
github.com/IBM/logs-go-sdk v0.5.0 h1:p7z106PQFB7e+zPcmqsZ5mx3SRaidEtxGTTqsl5Ksyo=
144+
github.com/IBM/logs-go-sdk v0.5.0/go.mod h1:yv/GCXC4/p+MZEeXl4xjZAOMvDAVRwu61WyHZFKFXQM=
145145
github.com/IBM/logs-router-go-sdk v1.0.8 h1:MU1TdYNdVbvVTUXeqeYPItu6BoiSV/NMN49ySqE7WIY=
146146
github.com/IBM/logs-router-go-sdk v1.0.8/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
147147
github.com/IBM/mqcloud-go-sdk v0.4.0 h1:BuZNXA6iYEg5OEPr13CMGrhH0ew4rH/4L56b1nFtA10=

ibm/provider/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ func Provider() *schema.Provider {
11141114
"ibm_logs_data_access_rules": logs.AddLogsInstanceFields(logs.DataSourceIbmLogsDataAccessRules()),
11151115
"ibm_logs_stream": logs.AddLogsInstanceFields(logs.DataSourceIbmLogsStream()),
11161116
"ibm_logs_streams": logs.AddLogsInstanceFields(logs.DataSourceIbmLogsStreams()),
1117+
"ibm_logs_alert_definition": logs.AddLogsInstanceFields(logs.DataSourceIbmLogsAlertDefinition()),
1118+
"ibm_logs_alert_definitions": logs.AddLogsInstanceFields(logs.DataSourceIbmLogsAlertDefinitions()),
11171119

11181120
// Logs Router Service
11191121
"ibm_logs_router_tenants": logsrouting.DataSourceIBMLogsRouterTenants(),
@@ -1786,6 +1788,7 @@ func Provider() *schema.Provider {
17861788
"ibm_logs_enrichment": logs.AddLogsInstanceFields(logs.ResourceIbmLogsEnrichment()),
17871789
"ibm_logs_data_access_rule": logs.AddLogsInstanceFields(logs.ResourceIbmLogsDataAccessRule()),
17881790
"ibm_logs_stream": logs.AddLogsInstanceFields(logs.ResourceIbmLogsStream()),
1791+
"ibm_logs_alert_definition": logs.AddLogsInstanceFields(logs.ResourceIbmLogsAlertDefinition()),
17891792

17901793
// Logs Router Service
17911794
"ibm_logs_router_tenant": logsrouting.ResourceIBMLogsRouterTenant(),
@@ -2294,6 +2297,7 @@ func Validator() validate.ValidatorDict {
22942297
"ibm_logs_enrichment": logs.ResourceIbmLogsEnrichmentValidator(),
22952298
"ibm_logs_data_access_rule": logs.ResourceIbmLogsDataAccessRuleValidator(),
22962299
"ibm_logs_stream": logs.ResourceIbmLogsStreamValidator(),
2300+
"ibm_logs_alert_definition": logs.ResourceIbmLogsAlertDefinitionValidator(),
22972301

22982302
// Added for Logs Router Service
22992303
"ibm_logs_router_tenant": logsrouting.ResourceIBMLogsRouterTenantValidator(),

0 commit comments

Comments
 (0)