forked from lacework/terraform-kubernetes-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
224 lines (209 loc) · 5.24 KB
/
main.tf
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
locals {
config_data = templatefile("${path.module}/config.tmpl", {
lacework_access_token = var.lacework_access_token,
lacework_agent_interface_connection_size = var.lacework_agent_interface_connection_size
lacework_agent_tags = jsonencode(merge({ "Env" : "k8s" }, var.lacework_agent_tags))
})
config_name = "${var.lacework_config_name}-${random_id.config_name_tail.hex}"
}
resource "random_id" "config_name_tail" {
byte_length = 8
keepers = {
data = local.config_data
}
}
resource "kubernetes_secret" "lacework_config" {
metadata {
name = local.config_name
namespace = var.namespace
}
data = {
"config.json" = local.config_data
}
}
resource "kubernetes_daemonset" "lacework_datacollector" {
metadata {
name = var.lacework_agent_name
namespace = var.namespace
labels = {
tier = "monitoring"
app = var.lacework_agent_name
}
}
spec {
selector {
match_labels = {
name = "lacework"
}
}
template {
metadata {
labels = {
name = "lacework"
}
annotations = {
lacework_config_version = kubernetes_secret.lacework_config.metadata.0.resource_version
}
}
spec {
dynamic "toleration" {
for_each = var.tolerations
content {
key = toleration.value["key"]
operator = lookup(toleration.value, "operator", "Equal")
value = lookup(toleration.value, "operator", "Equal") == "Exists" ? "" : lookup(toleration.value, "value", "")
effect = toleration.value["effect"]
}
}
container {
name = "lacework"
image = var.lacework_image
image_pull_policy = var.lacework_image_pull_policy
resources {
requests {
cpu = var.pod_cpu_request
memory = var.pod_mem_request
}
limits {
cpu = var.pod_cpu_limit
memory = var.pod_mem_limit
}
}
security_context {
privileged = true
}
volume_mount {
name = "config"
mount_path = "/var/lib/lacework/config"
}
volume_mount {
name = "dev"
mount_path = "/dev"
}
volume_mount {
name = "run-sock"
mount_path = "/var/run/docker.sock"
}
volume_mount {
name = "run-pid"
mount_path = "/var/run/docker.pid"
}
volume_mount {
name = "sys"
mount_path = "/sys"
}
volume_mount {
name = "log"
mount_path = "/var/log"
}
volume_mount {
name = "passwd"
mount_path = "/etc/passwd"
read_only = true
}
volume_mount {
name = "group"
mount_path = "/etc/group"
read_only = true
}
volume_mount {
name = "hostlacework"
mount_path = "/var/lib/lacework/collector"
}
volume_mount {
name = "hostroot"
mount_path = "/laceworkfim"
read_only = true
}
volume_mount {
name = "podinfo"
mount_path = "/etc/podinfo"
}
}
host_network = true
host_pid = true
volume {
name = "dev"
host_path {
path = "/dev"
}
}
volume {
name = "run-sock"
host_path {
path = "/var/run/docker.sock"
}
}
volume {
name = "run-pid"
host_path {
path = "/var/run/docker.pid"
}
}
volume {
name = "sys"
host_path {
path = "/sys"
}
}
volume {
name = "log"
host_path {
path = "/var/log"
}
}
volume {
name = "passwd"
host_path {
path = "/etc/passwd"
}
}
volume {
name = "group"
host_path {
path = "/etc/group"
}
}
volume {
name = "hostroot"
host_path {
path = "/"
}
}
volume {
name = "hostlacework"
host_path {
path = "/var/lib/lacework/collector"
}
}
volume {
name = "config"
secret {
secret_name = local.config_name
items {
key = "config.json"
path = "config.json"
}
}
}
volume {
name = "podinfo"
downward_api {
items {
path = "labels"
field_ref {
field_path = "metadata.labels"
}
}
items {
path = "annotations"
field_ref {
field_path = "metadata.annotations"
}
}
}
}
}
}
}
}