Skip to content

Commit cb96b22

Browse files
authored
feat: added 2 new submodules [logs_policy](https://github.com/terraform-ibm-modules/terraform-ibm-cloud-logs/tree/main/modules/logs_policy) and [webhook](https://github.com/terraform-ibm-modules/terraform-ibm-cloud-logs/tree/main/modules/webhook) that can be called independantly to the root level module. The root level module still supports all the same functionality, but now calls these submodules under the covers. (#38)
1 parent b25f0fa commit cb96b22

File tree

28 files changed

+575
-224
lines changed

28 files changed

+575
-224
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,20 @@ You need the following permissions to run this module.
131131
|------|--------|---------|
132132
| <a name="module_cbr_rule"></a> [cbr\_rule](#module\_cbr\_rule) | terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module | 1.31.0 |
133133
| <a name="module_cos_bucket_crn_parser"></a> [cos\_bucket\_crn\_parser](#module\_cos\_bucket\_crn\_parser) | terraform-ibm-modules/common-utilities/ibm//modules/crn-parser | 1.1.0 |
134+
| <a name="module_en_integration"></a> [en\_integration](#module\_en\_integration) | ./modules/webhook | n/a |
135+
| <a name="module_logs_policies"></a> [logs\_policies](#module\_logs\_policies) | ./modules/logs_policy | n/a |
134136

135137
### Resources
136138

137139
| Name | Type |
138140
|------|------|
139141
| [ibm_iam_authorization_policy.cos_policy](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
140-
| [ibm_iam_authorization_policy.en_policy](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
141142
| [ibm_iam_authorization_policy.logs_routing_policy](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
142-
| [ibm_logs_outgoing_webhook.en_integration](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/logs_outgoing_webhook) | resource |
143-
| [ibm_logs_policy.logs_policies](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/logs_policy) | resource |
144143
| [ibm_logs_router_tenant.logs_router_tenant_instances](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/logs_router_tenant) | resource |
145144
| [ibm_resource_instance.cloud_logs](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/resource_instance) | resource |
146145
| [ibm_resource_tag.cloud_logs_tag](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/resource_tag) | resource |
147146
| [random_string.random_tenant_suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
148147
| [time_sleep.wait_for_cos_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
149-
| [time_sleep.wait_for_en_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
150148

151149
### Inputs
152150

@@ -157,10 +155,10 @@ You need the following permissions to run this module.
157155
| <a name="input_data_storage"></a> [data\_storage](#input\_data\_storage) | A logs data bucket and a metrics bucket in IBM Cloud Object Storage to store your IBM Cloud Logs data for long term storage, search, analysis and alerting. | <pre>object({<br/> logs_data = optional(object({<br/> enabled = optional(bool, false)<br/> bucket_crn = optional(string)<br/> bucket_endpoint = optional(string)<br/> skip_cos_auth_policy = optional(bool, false)<br/> }), {})<br/> metrics_data = optional(object({<br/> enabled = optional(bool, false)<br/> bucket_crn = optional(string)<br/> bucket_endpoint = optional(string)<br/> skip_cos_auth_policy = optional(bool, false)<br/> }), {})<br/> }<br/> )</pre> | <pre>{<br/> "logs_data": null,<br/> "metrics_data": null<br/>}</pre> | no |
158156
| <a name="input_existing_event_notifications_instances"></a> [existing\_event\_notifications\_instances](#input\_existing\_event\_notifications\_instances) | List of Event Notifications instance details for routing critical events that occur in your IBM Cloud Logs. | <pre>list(object({<br/> en_instance_id = string<br/> en_region = string<br/> en_integration_name = optional(string)<br/> skip_en_auth_policy = optional(bool, false)<br/> }))</pre> | `[]` | no |
159157
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | The name of the IBM Cloud Logs instance to create. Defaults to 'cloud-logs-<region>' | `string` | `null` | no |
160-
| <a name="input_logs_routing_tenant_regions"></a> [logs\_routing\_tenant\_regions](#input\_logs\_routing\_tenant\_regions) | Pass a list of regions to create a tenant for that is targetted to the Cloud Logs instance created by this module. To manage platform logs that are generated by IBM Cloud® services in a region of IBM Cloud, you must create a tenant in each region that you operate. Leave the list empty if you don't want to create any tenants. NOTE: You can only have 1 tenant per region in an account. | `list(any)` | `[]` | no |
158+
| <a name="input_logs_routing_tenant_regions"></a> [logs\_routing\_tenant\_regions](#input\_logs\_routing\_tenant\_regions) | Pass a list of regions to create a tenant for that is targetted to the IBM Cloud Logs instance created by this module. To manage platform logs that are generated by IBM Cloud® services in a region of IBM Cloud, you must create a tenant in each region that you operate. Leave the list empty if you don't want to create any tenants. NOTE: You can only have 1 tenant per region in an account. | `list(any)` | `[]` | no |
161159
| <a name="input_plan"></a> [plan](#input\_plan) | The IBM Cloud Logs plan to provision. Available: standard | `string` | `"standard"` | no |
162-
| <a name="input_policies"></a> [policies](#input\_policies) | Configuration of Cloud Logs policies. | <pre>list(object({<br/> logs_policy_name = string<br/> logs_policy_description = optional(string, null)<br/> logs_policy_priority = string<br/> application_rule = optional(list(object({<br/> name = string<br/> rule_type_id = string<br/> })))<br/> subsystem_rule = optional(list(object({<br/> name = string<br/> rule_type_id = string<br/> })))<br/> log_rules = optional(list(object({<br/> severities = list(string)<br/> })))<br/> archive_retention = optional(list(object({<br/> id = string<br/> })))<br/> }))</pre> | `[]` | no |
163-
| <a name="input_region"></a> [region](#input\_region) | The IBM Cloud region where Cloud logs instance will be created. | `string` | `"us-south"` | no |
160+
| <a name="input_policies"></a> [policies](#input\_policies) | Configuration of IBM Cloud Logs policies. | <pre>list(object({<br/> logs_policy_name = string<br/> logs_policy_description = optional(string, null)<br/> logs_policy_priority = string<br/> application_rule = optional(list(object({<br/> name = string<br/> rule_type_id = string<br/> })))<br/> subsystem_rule = optional(list(object({<br/> name = string<br/> rule_type_id = string<br/> })))<br/> log_rules = optional(list(object({<br/> severities = list(string)<br/> })))<br/> archive_retention = optional(list(object({<br/> id = string<br/> })))<br/> }))</pre> | `[]` | no |
161+
| <a name="input_region"></a> [region](#input\_region) | The IBM Cloud region where IBM Cloud logs instance will be created. | `string` | `"us-south"` | no |
164162
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The id of the IBM Cloud resource group where the instance will be created. | `string` | `null` | no |
165163
| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | Tags associated with the IBM Cloud Logs instance (Optional, array of strings). | `list(string)` | `[]` | no |
166164
| <a name="input_retention_period"></a> [retention\_period](#input\_retention\_period) | The number of days IBM Cloud Logs will retain the logs data in Priority insights. Allowed values: 7, 14, 30, 60, 90. | `number` | `7` | no |
@@ -171,12 +169,12 @@ You need the following permissions to run this module.
171169

172170
| Name | Description |
173171
|------|-------------|
174-
| <a name="output_account_id"></a> [account\_id](#output\_account\_id) | The account id where cloud logs instance is provisioned. |
175-
| <a name="output_crn"></a> [crn](#output\_crn) | The CRN of the provisioned Cloud Logs instance. |
176-
| <a name="output_guid"></a> [guid](#output\_guid) | The guid of the provisioned Cloud Logs instance. |
177-
| <a name="output_ingress_endpoint"></a> [ingress\_endpoint](#output\_ingress\_endpoint) | The public ingress endpoint of the provisioned Cloud Logs instance. |
178-
| <a name="output_ingress_private_endpoint"></a> [ingress\_private\_endpoint](#output\_ingress\_private\_endpoint) | The private ingress endpoint of the provisioned Cloud Logs instance. |
179-
| <a name="output_logs_policies_details"></a> [logs\_policies\_details](#output\_logs\_policies\_details) | The details of the Cloud logs policies created. |
180-
| <a name="output_name"></a> [name](#output\_name) | The name of the provisioned Cloud Logs instance. |
181-
| <a name="output_resource_group_id"></a> [resource\_group\_id](#output\_resource\_group\_id) | The resource group where Cloud Logs instance resides. |
172+
| <a name="output_account_id"></a> [account\_id](#output\_account\_id) | The account id where IBM Cloud logs instance is provisioned. |
173+
| <a name="output_crn"></a> [crn](#output\_crn) | The CRN of the provisioned IBM Cloud Logs instance. |
174+
| <a name="output_guid"></a> [guid](#output\_guid) | The guid of the provisioned IBM Cloud Logs instance. |
175+
| <a name="output_ingress_endpoint"></a> [ingress\_endpoint](#output\_ingress\_endpoint) | The public ingress endpoint of the provisioned IBM Cloud Logs instance. |
176+
| <a name="output_ingress_private_endpoint"></a> [ingress\_private\_endpoint](#output\_ingress\_private\_endpoint) | The private ingress endpoint of the provisioned IBM Cloud Logs instance. |
177+
| <a name="output_logs_policies_details"></a> [logs\_policies\_details](#output\_logs\_policies\_details) | The details of the IBM Cloud logs policies created. |
178+
| <a name="output_name"></a> [name](#output\_name) | The name of the provisioned IBM Cloud Logs instance. |
179+
| <a name="output_resource_group_id"></a> [resource\_group\_id](#output\_resource\_group\_id) | The resource group where IBM Cloud Logs instance resides. |
182180
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/advanced/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Example that configures:
77

88
- COS instance and KMS encrypted COS buckets
9-
- Cloud Logs with Event Notifications integration
10-
- Cloud Logs policies
9+
- IBM Cloud Logs with Event Notifications integration
10+
- IBM Cloud Logs policies
1111
- Key Protect instance and root key
1212
- A context-based restriction (CBR) rule to only allow cloud logs to be accessible from schematics

examples/advanced/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ module "cbr_schematics_zone" {
131131
}
132132

133133
########################################################################################################################
134-
# Cloud Logs
134+
# IBM Cloud Logs
135135
########################################################################################################################
136136

137137
locals {

examples/advanced/outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@
99

1010
output "cloud_logs_crn" {
1111
value = module.cloud_logs.crn
12-
description = "The id of the provisioned Cloud Logs instance."
12+
description = "The id of the provisioned IBM Cloud Logs instance."
1313
}
1414

1515
output "cloud_logs_guid" {
1616
value = module.cloud_logs.guid
17-
description = "The guid of the provisioned Cloud Logs instance."
17+
description = "The guid of the provisioned IBM Cloud Logs instance."
1818
}
1919

2020
output "cloud_logs_name" {
2121
value = module.cloud_logs.name
22-
description = "The name of the provisioned Cloud Logs instance."
22+
description = "The name of the provisioned IBM Cloud Logs instance."
2323
}
2424

2525
output "resource_group_id" {
2626
value = module.cloud_logs.resource_group_id
27-
description = "The resource group where Cloud Logs instance resides."
27+
description = "The resource group where IBM Cloud Logs instance resides."
2828
}
2929

3030
output "cloud_logs_ingress_endpoint" {
3131
value = module.cloud_logs.ingress_endpoint
32-
description = "The public ingress endpoint of the provisioned Cloud Logs instance."
32+
description = "The public ingress endpoint of the provisioned IBM Cloud Logs instance."
3333
}
3434

3535
output "cloud_logs_ingress_private_endpoint" {
3636
value = module.cloud_logs.ingress_private_endpoint
37-
description = "The private ingress endpoint of the provisioned Cloud Logs instance."
37+
description = "The private ingress endpoint of the provisioned IBM Cloud Logs instance."
3838
}
3939

4040
output "cos_crn" {

examples/basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ An end-to-end basic example that will provision the following:
1010
- A new resource group if one is not passed in.
1111
- A new standard plan Cloud Object Storage instance.
1212
- Two Cloud Object Storage buckets.
13-
- A Cloud Logs instance using root module, attached to provisioned Cloud Object Storage buckets.
13+
- A IBM Cloud Logs instance using root module, attached to provisioned Cloud Object Storage buckets.

examples/basic/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module "buckets" {
5252
}
5353

5454
########################################################################################################################
55-
# Cloud Logs
55+
# IBM Cloud Logs
5656
########################################################################################################################
5757

5858
#

examples/basic/outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@
99

1010
output "cloud_logs_crn" {
1111
value = module.cloud_logs.crn
12-
description = "The id of the provisioned Cloud Logs instance."
12+
description = "The id of the provisioned IBM Cloud Logs instance."
1313
}
1414

1515
output "cloud_logs_guid" {
1616
value = module.cloud_logs.guid
17-
description = "The guid of the provisioned Cloud Logs instance."
17+
description = "The guid of the provisioned IBM Cloud Logs instance."
1818
}
1919

2020
output "cloud_logs_name" {
2121
value = module.cloud_logs.name
22-
description = "The name of the provisioned Cloud Logs instance."
22+
description = "The name of the provisioned IBM Cloud Logs instance."
2323
}
2424

2525
output "resource_group_id" {
2626
value = module.cloud_logs.resource_group_id
27-
description = "The resource group where Cloud Logs instance resides."
27+
description = "The resource group where IBM Cloud Logs instance resides."
2828
}
2929

3030
output "cloud_logs_ingress_endpoint" {
3131
value = module.cloud_logs.ingress_endpoint
32-
description = "The public ingress endpoint of the provisioned Cloud Logs instance."
32+
description = "The public ingress endpoint of the provisioned IBM Cloud Logs instance."
3333
}
3434

3535
output "cloud_logs_ingress_private_endpoint" {
3636
value = module.cloud_logs.ingress_private_endpoint
37-
description = "The private ingress endpoint of the provisioned Cloud Logs instance."
37+
description = "The private ingress endpoint of the provisioned IBM Cloud Logs instance."
3838
}
3939

4040
output "cos_crn" {

main.tf

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ resource "ibm_resource_tag" "cloud_logs_tag" {
2929
tag_type = "access"
3030
}
3131

32-
##############################################################################
33-
# Get Cloud Account ID
34-
##############################################################################
35-
3632
# If logs or metrics data is enabled, parse details from it
3733
module "cos_bucket_crn_parser" {
3834
for_each = { for index, bucket in var.data_storage : index => bucket if bucket.enabled && !bucket.skip_cos_auth_policy }
@@ -90,34 +86,13 @@ resource "time_sleep" "wait_for_cos_authorization_policy" {
9086
# EN Integration
9187
##############################################################################
9288

93-
# Create IAM Authorization Policies to allow Cloud Logs to access event notification
94-
resource "ibm_iam_authorization_policy" "en_policy" {
95-
for_each = { for idx, en in var.existing_event_notifications_instances : idx => en if !en.skip_en_auth_policy }
96-
source_service_name = "logs"
97-
source_resource_instance_id = ibm_resource_instance.cloud_logs.guid
98-
target_service_name = "event-notifications"
99-
target_resource_instance_id = each.value.en_instance_id
100-
roles = ["Event Source Manager", "Viewer"]
101-
description = "Allow Cloud Logs with instance ID ${ibm_resource_instance.cloud_logs.guid} 'Event Source Manager' and 'Viewer' role access on the Event Notification instance GUID ${each.value.en_instance_id}"
102-
}
103-
104-
resource "time_sleep" "wait_for_en_authorization_policy" {
105-
depends_on = [ibm_iam_authorization_policy.en_policy]
106-
create_duration = "30s"
107-
}
108-
109-
resource "ibm_logs_outgoing_webhook" "en_integration" {
110-
depends_on = [time_sleep.wait_for_en_authorization_policy]
111-
for_each = { for idx, en in var.existing_event_notifications_instances : idx => en }
112-
instance_id = ibm_resource_instance.cloud_logs.guid
113-
region = var.region
114-
name = each.value.en_integration_name == null ? "${local.instance_name}-en-integration-${each.key}" : each.value.en_integration_name
115-
type = "ibm_event_notifications"
116-
117-
ibm_event_notifications {
118-
event_notifications_instance_id = each.value.en_instance_id
119-
region_id = each.value.en_region
120-
}
89+
module "en_integration" {
90+
count = length(var.existing_event_notifications_instances) > 0 ? 1 : 0
91+
source = "./modules/webhook"
92+
cloud_logs_instance_id = ibm_resource_instance.cloud_logs.guid
93+
cloud_logs_instance_name = local.instance_name
94+
cloud_logs_region = var.region
95+
existing_event_notifications_instances = var.existing_event_notifications_instances
12196
}
12297

12398
##############################################################################
@@ -180,50 +155,15 @@ resource "ibm_logs_router_tenant" "logs_router_tenant_instances" {
180155
# Configure Logs Policies - TCO Optimizer
181156
##############################################################################
182157

183-
resource "ibm_logs_policy" "logs_policies" {
184-
for_each = {
185-
for policy in var.policies :
186-
policy.logs_policy_name => policy
187-
}
188-
instance_id = ibm_resource_instance.cloud_logs.guid
189-
region = ibm_resource_instance.cloud_logs.location
190-
endpoint_type = ibm_resource_instance.cloud_logs.service_endpoints
191-
name = each.value.logs_policy_name
192-
description = each.value.logs_policy_description
193-
priority = each.value.logs_policy_priority
194-
195-
dynamic "application_rule" {
196-
for_each = each.value.application_rule != null ? each.value.application_rule : []
197-
content {
198-
name = application_rule.value["name"]
199-
rule_type_id = application_rule.value["rule_type_id"]
200-
}
201-
}
202-
203-
dynamic "log_rules" {
204-
for_each = each.value.log_rules
205-
content {
206-
severities = log_rules.value["severities"]
207-
}
208-
}
209-
210-
dynamic "subsystem_rule" {
211-
for_each = each.value.subsystem_rule != null ? each.value.subsystem_rule : []
212-
content {
213-
name = subsystem_rule.value["name"]
214-
rule_type_id = subsystem_rule.value["rule_type_id"]
215-
}
216-
}
217-
218-
dynamic "archive_retention" {
219-
for_each = each.value.archive_retention != null ? each.value.archive_retention : []
220-
content {
221-
id = archive_retention.value["id"]
222-
}
223-
}
158+
module "logs_policies" {
159+
count = length(var.policies) > 0 ? 1 : 0
160+
source = "./modules/logs_policy"
161+
cloud_logs_instance_id = ibm_resource_instance.cloud_logs.guid
162+
cloud_logs_region = ibm_resource_instance.cloud_logs.location
163+
cloud_logs_service_endpoints = ibm_resource_instance.cloud_logs.service_endpoints
164+
policies = var.policies
224165
}
225166

226-
227167
##############################################################################
228168
# CBR
229169
##############################################################################

0 commit comments

Comments
 (0)