forked from angelabad/terraform-aws-msk-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
155 lines (135 loc) · 4.02 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
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"] : []
}
terraform {
required_version = ">= 0.12"
required_providers {
aws = ">= 2.55"
random = ">= 2.1"
}
}
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" {
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" "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
}
}
resource "aws_msk_configuration" "this" {
kafka_versions = [var.kafka_version]
name = random_id.configuration.dec
server_properties = local.server_properties
}
resource "aws_msk_cluster" "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
ebs_volume_size = var.volume_size
instance_type = var.instance_type
security_groups = concat(aws_security_group.this.*.id, var.extra_security_groups)
}
configuration_info {
arn = aws_msk_configuration.this.arn
revision = aws_msk_configuration.this.latest_revision
}
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
}