-
Notifications
You must be signed in to change notification settings - Fork 0
/
confluent-kafka-resources.tf
196 lines (169 loc) · 5.78 KB
/
confluent-kafka-resources.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
# Create the Kafka cluster
resource "confluent_kafka_cluster" "kafka_cluster" {
display_name = local.secrets_insert
availability = "SINGLE_ZONE"
cloud = local.cloud
region = var.aws_region
basic {}
environment {
id = confluent_environment.env.id
}
}
# Create the Service Account for the Kafka Cluster API
resource "confluent_service_account" "kafka_cluster_api" {
display_name = "${local.secrets_insert}-kafka_cluster-api"
description = "Kafka Cluster API Service Account"
}
# Since the Kafka Cluster created is a Basic Cluster type, setting more granular
# permissions is not allowed. Therefore, the ‘EnvironmentAdmin’ role is assigned
# to the entire cluster instead of implementing RBAC for specific Kafka topics.
resource "confluent_role_binding" "kafka_cluster_api_environment_admin" {
principal = "User:${confluent_service_account.kafka_cluster_api.id}"
role_name = "EnvironmentAdmin"
crn_pattern = confluent_environment.env.resource_name
}
# Create the Kafka Cluster API Key Pairs, rotate them in accordance to a time schedule,
# and provide the current acitve API Key Pair to use
module "kafka_cluster_api_key_rotation" {
source = "github.com/j3-signalroom/iac-confluent-api_key_rotation-tf_module"
#Required Input(s)
owner = {
id = confluent_service_account.kafka_cluster_api.id
api_version = confluent_service_account.kafka_cluster_api.api_version
kind = confluent_service_account.kafka_cluster_api.kind
}
resource = {
id = confluent_kafka_cluster.kafka_cluster.id
api_version = confluent_kafka_cluster.kafka_cluster.api_version
kind = confluent_kafka_cluster.kafka_cluster.kind
environment = {
id = confluent_environment.env.id
}
}
confluent_api_key = var.confluent_api_key
confluent_api_secret = var.confluent_api_secret
# Optional Input(s)
key_display_name = "Confluent Kafka Cluster Service Account API Key - {date} - Managed by Terraform Cloud"
number_of_api_keys_to_retain = var.number_of_api_keys_to_retain
day_count = var.day_count
}
# Create the `airline.skyone` Kafka topic
resource "confluent_kafka_topic" "airline_skyone" {
kafka_cluster {
id = confluent_kafka_cluster.kafka_cluster.id
}
topic_name = "airline.skyone"
partitions_count = 1
rest_endpoint = confluent_kafka_cluster.kafka_cluster.rest_endpoint
config = {
"retention.bytes" = "-1"
"retention.ms" = "-1"
}
credentials {
key = module.kafka_cluster_api_key_rotation.active_api_key.id
secret = module.kafka_cluster_api_key_rotation.active_api_key.secret
}
depends_on = [
confluent_kafka_cluster.kafka_cluster
]
}
# Create the `airline.sunset` Kafka topic
resource "confluent_kafka_topic" "airline_sunset" {
kafka_cluster {
id = confluent_kafka_cluster.kafka_cluster.id
}
topic_name = "airline.sunset"
partitions_count = 1
rest_endpoint = confluent_kafka_cluster.kafka_cluster.rest_endpoint
config = {
"retention.bytes" = "-1"
"retention.ms" = "-1"
}
credentials {
key = module.kafka_cluster_api_key_rotation.active_api_key.id
secret = module.kafka_cluster_api_key_rotation.active_api_key.secret
}
depends_on = [
confluent_kafka_cluster.kafka_cluster
]
}
# Create the `airline.skyone_avro` Kafka topic
resource "confluent_kafka_topic" "airline_skyone_avro" {
kafka_cluster {
id = confluent_kafka_cluster.kafka_cluster.id
}
topic_name = "airline.skyone_avro"
partitions_count = 1
rest_endpoint = confluent_kafka_cluster.kafka_cluster.rest_endpoint
config = {
"retention.bytes" = "-1"
"retention.ms" = "-1"
}
credentials {
key = module.kafka_cluster_api_key_rotation.active_api_key.id
secret = module.kafka_cluster_api_key_rotation.active_api_key.secret
}
depends_on = [
confluent_kafka_cluster.kafka_cluster
]
}
# Create the `airline.sunset_avro` Kafka topic
resource "confluent_kafka_topic" "airline_sunset_avro" {
kafka_cluster {
id = confluent_kafka_cluster.kafka_cluster.id
}
topic_name = "airline.sunset_avro"
partitions_count = 1
rest_endpoint = confluent_kafka_cluster.kafka_cluster.rest_endpoint
config = {
"retention.bytes" = "-1"
"retention.ms" = "-1"
}
credentials {
key = module.kafka_cluster_api_key_rotation.active_api_key.id
secret = module.kafka_cluster_api_key_rotation.active_api_key.secret
}
depends_on = [
confluent_kafka_cluster.kafka_cluster
]
}
# Create the `airline.flight` Kafka topic
resource "confluent_kafka_topic" "airline_flight" {
kafka_cluster {
id = confluent_kafka_cluster.kafka_cluster.id
}
topic_name = "airline.flight"
partitions_count = 1
rest_endpoint = confluent_kafka_cluster.kafka_cluster.rest_endpoint
config = {
"retention.bytes" = "-1"
"retention.ms" = "-1"
}
credentials {
key = module.kafka_cluster_api_key_rotation.active_api_key.id
secret = module.kafka_cluster_api_key_rotation.active_api_key.secret
}
depends_on = [
confluent_kafka_cluster.kafka_cluster
]
}
# Create the `airline.flyer_stats` Kafka topic
resource "confluent_kafka_topic" "airline_flyer_stats" {
kafka_cluster {
id = confluent_kafka_cluster.kafka_cluster.id
}
topic_name = "airline.flyer_stats"
partitions_count = 1
rest_endpoint = confluent_kafka_cluster.kafka_cluster.rest_endpoint
config = {
"retention.bytes" = "-1"
"retention.ms" = "-1"
}
credentials {
key = module.kafka_cluster_api_key_rotation.active_api_key.id
secret = module.kafka_cluster_api_key_rotation.active_api_key.secret
}
depends_on = [
confluent_kafka_cluster.kafka_cluster
]
}