-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
204 lines (183 loc) · 7.49 KB
/
main.tf
File metadata and controls
204 lines (183 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
##############################################################################
# Resource Group
##############################################################################
module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.4.7"
# if an existing resource group is not set (null) create a new one using prefix
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
existing_resource_group_name = var.resource_group
}
##############################################################################
# Cloud Logs
##############################################################################
module "cloud_logs" {
source = "terraform-ibm-modules/cloud-logs/ibm"
version = "1.10.32"
resource_group_id = module.resource_group.resource_group_id
region = var.region
data_storage = {
logs_data = {
enabled = false
},
metrics_data = {
enabled = false
}
}
}
##############################################################################
# Event Streams
##############################################################################
locals {
topic_name = "${var.prefix}-topic"
}
module "event_streams" {
source = "terraform-ibm-modules/event-streams/ibm"
version = "4.6.24"
es_name = "${var.prefix}-eventsteams-instance"
tags = var.resource_tags
region = var.region
resource_group_id = module.resource_group.resource_group_id
plan = "standard"
topics = [{
name = local.topic_name
partitions = 1
config = {
"cleanup.policy" = "delete"
"retention.ms" = "86400000" # 1 Day
"retention.bytes" = "10485760" # 10 MB
"segment.bytes" = "536870912" # 512 MB
}
}, ]
}
##############################################################################
# Key Protect Instance + Key (used to encrypt bucket)
##############################################################################
locals {
key_ring_name = "at"
key_name = "at-key"
}
module "key_protect" {
source = "terraform-ibm-modules/kms-all-inclusive/ibm"
version = "5.5.25"
resource_group_id = module.resource_group.resource_group_id
region = var.region
resource_tags = var.resource_tags
keys = [
{
key_ring_name = local.key_ring_name
keys = [
{
key_name = local.key_name
}
]
}
]
key_protect_instance_name = "${var.prefix}-kp"
}
##############################################################################
# COS instance (used for AT target)
##############################################################################
module "cos" {
source = "terraform-ibm-modules/cos/ibm"
version = "10.9.7"
resource_group_id = module.resource_group.resource_group_id
cos_instance_name = "${var.prefix}-cos"
cos_tags = var.resource_tags
create_cos_bucket = false
}
locals {
at_bucket_name = "${var.prefix}-at-data"
}
module "buckets" {
source = "terraform-ibm-modules/cos/ibm//modules/buckets"
version = "10.9.7"
bucket_configs = [
{
bucket_name = local.at_bucket_name
kms_encryption_enabled = true
region_location = var.region
resource_instance_id = module.cos.cos_instance_id
kms_guid = module.key_protect.kms_guid
kms_key_crn = module.key_protect.keys["${local.key_ring_name}.${local.key_name}"].crn
skip_iam_authorization_policy = false # Auth policy created in first bucket
}
]
}
##############################################################################
# - Activity Tracker Event Routing config:
# - COS AT target
# - Cloud Logs AT target
# - Event Streams AT target
# - AT route to all above targets
# - Global Event Routing configuration
##############################################################################
locals {
icl_target_name = "${var.prefix}-icl-target"
es_target_name = "${var.prefix}-es-target"
cos_target_name = "${var.prefix}-cos-target"
target_ids = [
module.activity_tracker.activity_tracker_targets[local.cos_target_name].id,
module.activity_tracker.activity_tracker_targets[local.es_target_name].id,
module.activity_tracker.activity_tracker_targets[local.icl_target_name].id
]
}
module "activity_tracker" {
source = "../../"
# delete line above and use below syntax to pull module source from hashicorp when consuming this module
# source = "terraform-ibm-modules/activity-tracker/ibm"
# version = "X.Y.Z" # Replace "X.X.X" with a release version to lock into a specific release
# Activity Tracker targets
cloud_logs_targets = [
{
instance_id = module.cloud_logs.crn
target_region = var.region
target_name = local.icl_target_name
}
]
cos_targets = [
{
bucket_name = local.at_bucket_name
endpoint = module.buckets.buckets[local.at_bucket_name].s3_endpoint_direct
instance_id = module.cos.cos_instance_id
target_region = var.region
target_name = local.cos_target_name
skip_atracker_cos_iam_auth_policy = false
service_to_service_enabled = true
}
]
eventstreams_targets = [
{
instance_id = module.event_streams.id
brokers = [module.event_streams.kafka_brokers_sasl[0]]
topic = local.topic_name
target_region = var.region
target_name = local.es_target_name
service_to_service_enabled = true
skip_atracker_es_iam_auth_policy = false
}
]
# Activity Tracker route
activity_tracker_routes = [
{
locations = ["*"]
target_ids = local.target_ids
route_name = "${var.prefix}-route"
}
]
# Global Event Routing Settings
# default_targets - The default target per account to configure where auditing events that are not explicitly managed in the accounts routing rules are routed.
# metadata_region_primary - The location in your IBM Cloud account where the Activity Tracker Event Routing account configuration metadata is stored. If you do not configure a metadata location before you create a target, the location where the first target is created is automatically configured as the metadata location.
# metadata_region_backup - To store all your metadata in a backup region.
# permitted_target_regions - The locations where an account administrator can configure targets to collect auditing events. You can choose any of the supported locations where Activity Tracker Event Routing is available - https://cloud.ibm.com/docs/atracker?topic=atracker-regions&interface=cli.
# private_api_endpoint_only - The type of endpoints that are allowed to manage the Activity Tracker Event Routing account configuration in the account. If you set this true then you cannot access api through public network.
# Uncomment below to configure global event routing settings.
/*
global_event_routing_settings = {
default_targets = local.target_ids
permitted_target_regions = ["us-south", "eu-de", "us-east", "eu-es", "eu-gb", "au-syd", "br-sao", "ca-tor", "eu-es", "jp-tok", "jp-osa", "in-che", "eu-fr2"]
metadata_region_primary = "us-south"
private_api_endpoint_only = false
}
*/
}