Skip to content

Commit 43524d3

Browse files
authored
feat: added new inputs at_cos_bucket_retention_policy and cloud_log_data_bucket_retention_policy to the instances variation of the DA to allow retention to be configured on the COS buckets created by the solution. (#210)
1 parent a93e86d commit 43524d3

File tree

4 files changed

+166
-76
lines changed

4 files changed

+166
-76
lines changed

ibm_catalog.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@
244244
{
245245
"key": "cos_instance_access_tags"
246246
},
247+
{
248+
"key": "at_cos_bucket_retention_policy"
249+
},
250+
{
251+
"key": "cloud_log_data_bucket_retention_policy"
252+
},
247253
{
248254
"key": "add_bucket_name_suffix"
249255
},

solutions/instances/DA-types.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Several optional input variables in the IBM Cloud [Observability instances deplo
55
* Cloud Logs Event Notification Instances (`cloud_logs_existing_en_instances`)
66
* Cloud Logs policies (`cloud_logs_policies`)
77
* Metrics Router Routes (`metrics_router_routes`)
8+
* Activity Tracker Event Routing COS bucket retention policy (`at_cos_bucket_retention_policy`)
9+
* Cloud Logs data bucket retention policy(`cloud_log_data_bucket_retention_policy`)
810

911

1012
## Cloud Logs Event Notification Instances <a name="cloud_logs_existing_en_instances"></a>
@@ -130,3 +132,57 @@ metrics_router_routes = {
130132
}
131133
```
132134
Refer [here](https://cloud.ibm.com/docs/metrics-router?topic=metrics-router-route_rules_definitions&interface=ui) for more information about IBM Cloud Metrics Routing route.
135+
136+
## at_cos_bucket_retention_policy <a name="at_cos_bucket_retention_policy"></a>
137+
138+
The `at_cos_bucket_retention_policy` input variable allows you to provide the retention policy of the IBM Cloud Activity Tracker Event Routing COS target bucket that will be configured. Refer [here](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-immutable) for more information.
139+
140+
- Variable name: `at_cos_bucket_retention_policy`.
141+
- Type: An object representing a retention policy.
142+
- Default value: null (`null`).
143+
144+
### Options for at_cos_bucket_retention_policy
145+
146+
- `default` (optional): The number of days that an object can remain unmodified in an Object Storage bucket.
147+
- `maximum` (optional): The maximum number of days that an object can be kept unmodified in the bucket.
148+
- `minimum` (optional): The minimum number of days that an object must be kept unmodified in the bucket.
149+
- `permanent` (optional): Whether permanent retention status is enabled for the Object Storage bucket.
150+
151+
### Example at_cos_bucket_retention_policy
152+
153+
```hcl
154+
at_cos_bucket_retention_policy = {
155+
default = 90
156+
maximum = 350
157+
minimum = 90
158+
permanent = false
159+
}
160+
```
161+
162+
## cloud_log_data_bucket_retention_policy <a name="cloud_log_data_bucket_retention_policy"></a>
163+
164+
The `cloud_log_data_bucket_retention_policy` input variable allows you to provide the retention policy of the IBM Cloud Logs data bucket that will be configured. Refer [here](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-immutable) for more information.
165+
166+
- Variable name: `cloud_log_data_bucket_retention_policy`.
167+
- Type: An object representing a retention policy.
168+
- Default value: null (`null`).
169+
170+
### Options for cloud_log_data_bucket_retention_policy
171+
172+
- `default` (optional): The number of days that an object can remain unmodified in an Object Storage bucket.
173+
- `maximum` (optional): The maximum number of days that an object can be kept unmodified in the bucket.
174+
- `minimum` (optional): The minimum number of days that an object must be kept unmodified in the bucket.
175+
- `permanent` (optional): Whether permanent retention status is enabled for the Object Storage bucket.
176+
177+
178+
179+
### Example cloud_log_data_bucket_retention_policy
180+
181+
```hcl
182+
cloud_log_data_bucket_retention_policy = {
183+
default = 90
184+
maximum = 350
185+
minimum = 90
186+
permanent = false
187+
}
188+
```

solutions/instances/main.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,25 @@ locals {
9191
tag = var.cloud_log_metrics_bucket_access_tag
9292
} : null
9393

94+
bucket_retention_configs = merge(
95+
local.at_bucket_config != null ? { (local.at_cos_target_bucket_name) = var.at_cos_bucket_retention_policy } : null,
96+
local.cloud_log_data_bucket_config != null ? { (local.cloud_log_data_bucket) = var.cloud_log_data_bucket_retention_policy } : null
97+
)
98+
9499
buckets_config = concat(
95100
local.archive_bucket_config != null ? [local.archive_bucket_config] : [],
96101
local.at_bucket_config != null ? [local.at_bucket_config] : [],
97102
local.cloud_log_data_bucket_config != null ? [local.cloud_log_data_bucket_config] : [],
98103
local.cloud_log_metrics_bucket_config != null ? [local.cloud_log_metrics_bucket_config] : []
99104
)
100105

101-
archive_rule = var.existing_at_cos_target_bucket_name == null ? {
106+
archive_rule = length(local.buckets_config) != 0 ? {
102107
enable = true
103108
days = 90
104109
type = "Glacier"
105110
} : null
106111

107-
expire_rule = var.existing_at_cos_target_bucket_name == null ? {
112+
expire_rule = length(local.buckets_config) != 0 ? {
108113
enable = true
109114
days = 366
110115
} : null
@@ -120,6 +125,7 @@ locals {
120125
locations = ["*", "global"]
121126
target_ids = [module.observability_instance.activity_tracker_targets[local.cloud_logs_target_name].id]
122127
}] : []
128+
123129
apply_auth_policy = (var.skip_cos_kms_auth_policy || (length(coalesce(local.buckets_config, [])) == 0)) ? 0 : 1
124130
at_routes = concat(local.at_cos_route, local.at_cloud_logs_route)
125131

@@ -478,7 +484,7 @@ module "cos_bucket" {
478484
force_delete = true
479485
archive_rule = local.archive_rule
480486
expire_rule = local.expire_rule
481-
retention_rule = null
487+
retention_rule = lookup(local.bucket_retention_configs, value.name, null)
482488
metrics_monitoring = {
483489
usage_metrics_enabled = true
484490
request_metrics_enabled = true

solutions/instances/variables.tf

Lines changed: 95 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ variable "cloud_logs_access_tags" {
9797
}
9898
# https://github.ibm.com/GoldenEye/issues/issues/10928#issuecomment-93550079
9999
variable "cloud_logs_existing_en_instances" {
100-
description = "A list of existing Event Notification instances to be integrated with the Cloud Logging service. Each object in the list represents an Event Notification instance, including its CRN, an optional name for the integration, and an optional flag to skip the authentication policy creation for the Event Notification instance [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/tree/main/solutions/standard/DA-types.md#cloud_logs_existing_en_instances). This variable is intended for integrating a multiple Event Notifications instance to Cloud Logs. If you need to integrate only one instance, you may also use the `existing_en_instance_crn`, `en_integration_name` and `skip_en_auth_policy` variables instead."
100+
description = "A list of existing Event Notification instances to be integrated with the Cloud Logging service. Each object in the list represents an Event Notification instance, including its CRN, an optional name for the integration, and an optional flag to skip the authentication policy creation for the Event Notification instance [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/blob/main/solutions/instances/DA-types.md#cloud-logs-event-notification-instances-). This variable is intended for integrating a multiple Event Notifications instance to Cloud Logs. If you need to integrate only one instance, you may also use the `existing_en_instance_crn`, `en_integration_name` and `skip_en_auth_policy` variables instead."
101101
type = list(object({
102102
instance_crn = string
103103
integration_name = optional(string, "cloud-logs-en-integration")
@@ -135,78 +135,6 @@ variable "cloud_logs_retention_period" {
135135
}
136136
}
137137

138-
variable "cloud_log_data_bucket_name" {
139-
type = string
140-
default = "cloud-logs-data-bucket"
141-
description = "The name of the Cloud Object Storage bucket to create to store cloud log data. Cloud Object Storage bucket names are globally unique. If the `add_bucket_name_suffix` variable is set to `true`, 4 random characters are added to this name to ensure that the name of the bucket is globally unique. If the prefix input variable is passed, the name of the bucket is prefixed to the value in the `<prefix>-value` format."
142-
}
143-
144-
variable "existing_cloud_logs_data_bucket_crn" {
145-
type = string
146-
nullable = true
147-
default = null
148-
description = "The crn of an existing bucket within the Cloud Object Storage instance to store IBM Cloud Logs data. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
149-
}
150-
151-
variable "existing_cloud_logs_data_bucket_endpoint" {
152-
type = string
153-
nullable = true
154-
default = null
155-
description = "The endpoint of an existing Cloud Object Storage bucket to use for storing the IBM Cloud Logs data. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
156-
}
157-
158-
variable "cloud_log_data_bucket_class" {
159-
type = string
160-
default = "smart"
161-
description = "The storage class of the newly provisioned cloud logs Cloud Object Storage bucket. Specify one of the following values for the storage class: `standard`, `vault`, `cold`, `smart` (default), or `onerate_active`."
162-
validation {
163-
condition = contains(["standard", "vault", "cold", "smart", "onerate_active"], var.cloud_log_data_bucket_class)
164-
error_message = "Specify one of the following values for the `cos_bucket_class`: `standard`, `vault`, `cold`, `smart`, or `onerate_active`."
165-
}
166-
}
167-
168-
variable "cloud_log_data_bucket_access_tag" {
169-
type = list(string)
170-
default = []
171-
description = "A list of optional tags to add to the cloud log data object storage bucket."
172-
}
173-
174-
variable "cloud_log_metrics_bucket_name" {
175-
type = string
176-
default = "cloud-logs-metrics-bucket"
177-
description = "The name of the Cloud Object Storage bucket to create to store cloud logs metrics. Cloud Object Storage bucket names are globally unique. If the `add_bucket_name_suffix` variable is set to `true`, 4 random characters are added to this name to ensure that the name of the bucket is globally unique. If the prefix input variable is passed, the name of the bucket is prefixed to the value in the `<prefix>-value` format."
178-
}
179-
180-
variable "existing_cloud_logs_metrics_bucket_crn" {
181-
type = string
182-
nullable = true
183-
default = null
184-
description = "The crn of an existing bucket within the Cloud Object Storage instance to store IBM Cloud Logs metrics. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
185-
}
186-
187-
variable "existing_cloud_logs_metrics_bucket_endpoint" {
188-
type = string
189-
nullable = true
190-
default = null
191-
description = "The endpoint of an existing Cloud Object Storage bucket to use for storing the IBM Cloud Logs metrics. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
192-
}
193-
194-
variable "cloud_log_metrics_bucket_class" {
195-
type = string
196-
default = "smart"
197-
description = "The storage class of the newly provisioned cloud logs Cloud Object Storage bucket. Specify one of the following values for the storage class: `standard`, `vault`, `cold`, `smart` (default), or `onerate_active`."
198-
validation {
199-
condition = contains(["standard", "vault", "cold", "smart", "onerate_active"], var.cloud_log_metrics_bucket_class)
200-
error_message = "Specify one of the following values for the `cos_bucket_class`: `standard`, `vault`, `cold`, `smart`, or `onerate_active`."
201-
}
202-
}
203-
204-
variable "cloud_log_metrics_bucket_access_tag" {
205-
type = list(string)
206-
default = []
207-
description = "A list of optional tags to add to the cloud log metrics object storage bucket."
208-
}
209-
210138
variable "skip_logs_routing_auth_policy" {
211139
description = "Whether to create an IAM authorization policy that permits Logs Routing Sender access to the IBM Cloud Logs."
212140
type = bool
@@ -378,6 +306,28 @@ variable "cos_instance_tags" {
378306
default = []
379307
}
380308

309+
variable "at_cos_bucket_retention_policy" {
310+
type = object({
311+
default = optional(number, 90)
312+
maximum = optional(number, 350)
313+
minimum = optional(number, 90)
314+
permanent = optional(bool, false)
315+
})
316+
description = "The retention policy of the IBM Cloud Activity Tracker Event Routing COS target bucket. [Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/blob/main/solutions/instances/DA-types.md#at_cos_bucket_retention_policy-)"
317+
default = null
318+
}
319+
320+
variable "cloud_log_data_bucket_retention_policy" {
321+
type = object({
322+
default = optional(number, 90)
323+
maximum = optional(number, 350)
324+
minimum = optional(number, 90)
325+
permanent = optional(bool, false)
326+
})
327+
description = "The retention policy of the IBM Cloud Logs data bucket.[Learn more](https://github.com/terraform-ibm-modules/terraform-ibm-observability-da/blob/main/solutions/instances/DA-types.md#cloud_log_data_bucket_retention_policy-)"
328+
default = null
329+
}
330+
381331
variable "cos_instance_access_tags" {
382332
type = list(string)
383333
description = "A list of access tags to apply to a new Cloud Object Storage instance."
@@ -396,6 +346,18 @@ variable "at_cos_target_bucket_name" {
396346
description = "The name of the Cloud Object Storage bucket to create for the Cloud Object Storage target to store AT events. Cloud Object Storage bucket names are globally unique. If the `add_bucket_name_suffix` variable is set to `true`, 4 random characters are added to this name to ensure that the name of the bucket is globally unique. If the prefix input variable is passed, the name of the instance is prefixed to the value in the `<prefix>-value` format."
397347
}
398348

349+
variable "cloud_log_data_bucket_name" {
350+
type = string
351+
default = "cloud-logs-data-bucket"
352+
description = "The name of the Cloud Object Storage bucket to create to store cloud log data. Cloud Object Storage bucket names are globally unique. If the `add_bucket_name_suffix` variable is set to `true`, 4 random characters are added to this name to ensure that the name of the bucket is globally unique. If the prefix input variable is passed, the name of the bucket is prefixed to the value in the `<prefix>-value` format."
353+
}
354+
355+
variable "cloud_log_metrics_bucket_name" {
356+
type = string
357+
default = "cloud-logs-metrics-bucket"
358+
description = "The name of the Cloud Object Storage bucket to create to store cloud logs metrics. Cloud Object Storage bucket names are globally unique. If the `add_bucket_name_suffix` variable is set to `true`, 4 random characters are added to this name to ensure that the name of the bucket is globally unique. If the prefix input variable is passed, the name of the bucket is prefixed to the value in the `<prefix>-value` format."
359+
}
360+
399361
variable "archive_bucket_access_tags" {
400362
type = list(string)
401363
default = []
@@ -408,6 +370,18 @@ variable "at_cos_bucket_access_tags" {
408370
description = "A list of optional access tags to add to the IBM Cloud Activity Tracker Event Routing Cloud Object Storage bucket."
409371
}
410372

373+
variable "cloud_log_data_bucket_access_tag" {
374+
type = list(string)
375+
default = []
376+
description = "A list of optional tags to add to the cloud log data object storage bucket."
377+
}
378+
379+
variable "cloud_log_metrics_bucket_access_tag" {
380+
type = list(string)
381+
default = []
382+
description = "A list of optional tags to add to the cloud log metrics object storage bucket."
383+
}
384+
411385
variable "log_archive_cos_bucket_class" {
412386
type = string
413387
default = "smart"
@@ -428,13 +402,47 @@ variable "at_cos_target_bucket_class" {
428402
}
429403
}
430404

405+
variable "cloud_log_data_bucket_class" {
406+
type = string
407+
default = "smart"
408+
description = "The storage class of the newly provisioned cloud logs Cloud Object Storage bucket. Specify one of the following values for the storage class: `standard` or `smart` (default)."
409+
validation {
410+
condition = contains(["standard", "smart"], var.cloud_log_data_bucket_class)
411+
error_message = "Specify one of the following values for the `cos_bucket_class`: `standard` or `smart`. See more at https://cloud.ibm.com/docs/cloud-logs?topic=cloud-logs-configure-data-bucket"
412+
}
413+
}
414+
415+
variable "cloud_log_metrics_bucket_class" {
416+
type = string
417+
default = "smart"
418+
description = "The storage class of the newly provisioned cloud logs Cloud Object Storage bucket. Specify one of the following values for the storage class: `standard` or `smart` (default)."
419+
validation {
420+
condition = contains(["standard", "smart"], var.cloud_log_metrics_bucket_class)
421+
error_message = "Specify one of the following values for the `cos_bucket_class`: `standard`, or `smart`. See more at https://cloud.ibm.com/docs/cloud-logs?topic=cloud-logs-configure-data-bucket"
422+
}
423+
}
424+
431425
variable "existing_cos_instance_crn" {
432426
type = string
433427
nullable = true
434428
default = null
435429
description = "The CRN of an existing Cloud Object Storage instance. If a CRN is not specified, a new instance of Cloud Object Storage is created."
436430
}
437431

432+
variable "existing_cloud_logs_data_bucket_crn" {
433+
type = string
434+
nullable = true
435+
default = null
436+
description = "The crn of an existing bucket within the Cloud Object Storage instance to store IBM Cloud Logs data. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
437+
}
438+
439+
variable "existing_cloud_logs_metrics_bucket_crn" {
440+
type = string
441+
nullable = true
442+
default = null
443+
description = "The crn of an existing bucket within the Cloud Object Storage instance to store IBM Cloud Logs metrics. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
444+
}
445+
438446
variable "existing_at_cos_target_bucket_name" {
439447
type = string
440448
nullable = true
@@ -455,6 +463,20 @@ variable "skip_cos_kms_auth_policy" {
455463
default = false
456464
}
457465

466+
variable "existing_cloud_logs_data_bucket_endpoint" {
467+
type = string
468+
nullable = true
469+
default = null
470+
description = "The endpoint of an existing Cloud Object Storage bucket to use for storing the IBM Cloud Logs data. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
471+
}
472+
473+
variable "existing_cloud_logs_metrics_bucket_endpoint" {
474+
type = string
475+
nullable = true
476+
default = null
477+
description = "The endpoint of an existing Cloud Object Storage bucket to use for storing the IBM Cloud Logs metrics. If an existing Cloud Object Storage bucket is not specified, a bucket is created."
478+
}
479+
458480
variable "skip_cloud_logs_cos_auth_policy" {
459481
type = bool
460482
description = "To skip creating an IAM authorization policy that allows the IBM Cloud logs to write to the Cloud Object Storage bucket, set this variable to `true`."

0 commit comments

Comments
 (0)