-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.tf
198 lines (170 loc) · 5.4 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
locals {
server_properties = join("\n", [for k, v in var.server_properties : format("%s = %s", k, v)])
enable_logs = var.s3_logs_bucket != "" || var.cloudwatch_logs_group != "" || var.firehose_logs_delivery_stream != "" ? ["true"] : []
}
data "aws_subnet" "this" {
id = var.client_subnets[0]
}
resource "aws_security_group" "this" {
name_prefix = "${var.cluster_name}-"
vpc_id = data.aws_subnet.this.vpc_id
}
resource "aws_security_group_rule" "msk-plain" {
from_port = 9092
to_port = 9092
protocol = "tcp"
security_group_id = aws_security_group.this.id
type = "ingress"
self = true
}
resource "aws_security_group_rule" "msk-tls" {
from_port = 9094
to_port = 9094
protocol = "tcp"
security_group_id = aws_security_group.this.id
type = "ingress"
self = true
}
resource "aws_security_group_rule" "zookeeper-plain" {
from_port = 2181
to_port = 2181
protocol = "tcp"
security_group_id = aws_security_group.this.id
type = "ingress"
self = true
}
resource "aws_security_group_rule" "zookeeper-tls" {
from_port = 2182
to_port = 2182
protocol = "tcp"
security_group_id = aws_security_group.this.id
type = "ingress"
self = true
}
resource "aws_security_group_rule" "jmx-exporter" {
count = var.prometheus_jmx_exporter ? 1 : 0
from_port = 11001
to_port = 11001
protocol = "tcp"
security_group_id = aws_security_group.this.id
type = "ingress"
self = true
}
resource "aws_security_group_rule" "node_exporter" {
count = var.prometheus_node_exporter ? 1 : 0
from_port = 11002
to_port = 11002
protocol = "tcp"
security_group_id = aws_security_group.this.id
type = "ingress"
self = true
}
resource "random_id" "configuration" {
prefix = "${var.cluster_name}-"
byte_length = 8
keepers = {
server_properties = local.server_properties
kafka_version = var.kafka_version
}
}
resource "aws_msk_configuration" "this" {
kafka_versions = [random_id.configuration.keepers.kafka_version]
name = random_id.configuration.dec
server_properties = random_id.configuration.keepers.server_properties
lifecycle {
create_before_destroy = true
}
}
resource "aws_msk_scram_secret_association" "this" {
count = length(var.client_authentication_sasl_scram_secrets_arns) == 0 ? 0 : 1
cluster_arn = aws_msk_cluster.this.arn
secret_arn_list = var.client_authentication_sasl_scram_secrets_arns
}
resource "aws_msk_cluster" "this" {
depends_on = [aws_msk_configuration.this]
cluster_name = var.cluster_name
kafka_version = var.kafka_version
number_of_broker_nodes = var.number_of_nodes
enhanced_monitoring = var.enhanced_monitoring
broker_node_group_info {
client_subnets = var.client_subnets
instance_type = var.instance_type
security_groups = concat(aws_security_group.this[*].id, var.extra_security_groups)
storage_info {
ebs_storage_info {
volume_size = var.volume_size
dynamic "provisioned_throughput" {
for_each = var.provisioned_volume_throughput[*]
content {
enabled = true
volume_throughput = var.provisioned_volume_throughput
}
}
}
}
}
configuration_info {
arn = aws_msk_configuration.this.arn
revision = aws_msk_configuration.this.latest_revision
}
client_authentication {
unauthenticated = var.client_authentication_unauthenticated_enabled
sasl {
iam = var.client_authentication_sasl_iam_enabled
scram = length(var.client_authentication_sasl_scram_secrets_arns) == 0 ? false : true
}
dynamic "tls" {
for_each = length(var.client_authentication_tls_certificate_authority_arns) != 0 ? ["true"] : []
content {
certificate_authority_arns = var.client_authentication_tls_certificate_authority_arns
}
}
}
encryption_info {
encryption_at_rest_kms_key_arn = var.encryption_at_rest_kms_key_arn
encryption_in_transit {
client_broker = var.encryption_in_transit_client_broker
in_cluster = var.encryption_in_transit_in_cluster
}
}
open_monitoring {
prometheus {
jmx_exporter {
enabled_in_broker = var.prometheus_jmx_exporter
}
node_exporter {
enabled_in_broker = var.prometheus_node_exporter
}
}
}
dynamic "logging_info" {
for_each = local.enable_logs
content {
broker_logs {
dynamic "firehose" {
for_each = var.firehose_logs_delivery_stream != "" ? ["true"] : []
content {
enabled = true
delivery_stream = var.firehose_logs_delivery_stream
}
}
dynamic "cloudwatch_logs" {
for_each = var.cloudwatch_logs_group != "" ? ["true"] : []
content {
enabled = true
log_group = var.cloudwatch_logs_group
}
}
dynamic "s3" {
for_each = var.s3_logs_bucket != "" ? ["true"] : []
content {
enabled = true
bucket = var.s3_logs_bucket
prefix = var.s3_logs_prefix
}
}
}
}
}
tags = var.tags
}