-
Notifications
You must be signed in to change notification settings - Fork 0
/
cflt_cloud.tf
211 lines (205 loc) · 6.52 KB
/
cflt_cloud.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
# -------------------------------------------------------
# Confluent Cloud Environment
# -------------------------------------------------------
resource "confluent_environment" "cc_demo_env" {
display_name = "${var.cc_env_name}-${random_id.id.hex}"
lifecycle {
prevent_destroy = false
}
}
output "cc_demo_env" {
description = "CC Environment"
value = resource.confluent_environment.cc_demo_env.id
}
# --------------------------------------------------------
# Schema Registry
# --------------------------------------------------------
data "confluent_schema_registry_region" "cc_demo_sr" {
cloud = var.sr_cloud_provider
region = var.sr_cloud_region
package = var.sr_package
}
output "cc_demo_sr" {
description = "CC Schema Registry Region"
value = data.confluent_schema_registry_region.cc_demo_sr
}
resource "confluent_schema_registry_cluster" "cc_sr_cluster" {
package = data.confluent_schema_registry_region.cc_demo_sr.package
environment {
id = confluent_environment.cc_demo_env.id
}
region {
id = data.confluent_schema_registry_region.cc_demo_sr.id
}
lifecycle {
prevent_destroy = false
}
}
output "cc_sr_cluster" {
description = "CC SR Cluster ID"
value = resource.confluent_schema_registry_cluster.cc_sr_cluster.id
}
# --------------------------------------------------------
# Apache Kafka Cluster
# --------------------------------------------------------
resource "confluent_kafka_cluster" "cc_kafka_cluster" {
display_name = var.cc_cluster_name
availability = var.cc_availability
cloud = var.cc_cloud_provider
region = var.cc_cloud_region
basic {}
environment {
id = confluent_environment.cc_demo_env.id
}
lifecycle {
prevent_destroy = false
}
}
output "cc_kafka_cluster" {
description = "CC Kafka Cluster ID"
value = resource.confluent_kafka_cluster.cc_kafka_cluster.id
}
# --------------------------------------------------------
# Flink Compute Pool
# --------------------------------------------------------
resource "confluent_flink_compute_pool" "cc_flink_compute_pool" {
display_name = "${var.cc_dislay_name}-${random_id.id.hex}"
cloud = var.cc_cloud_provider
region = var.cc_cloud_region
max_cfu = var.cc_compute_pool_cfu
environment {
id = confluent_environment.cc_demo_env.id
}
depends_on = [
confluent_kafka_cluster.cc_kafka_cluster
]
lifecycle {
prevent_destroy = false
}
}
# --------------------------------------------------------
# Service Accounts (app_manager, sr, clients)
# --------------------------------------------------------
resource "confluent_service_account" "app_manager" {
display_name = "app-manager-${random_id.id.hex}"
description = local.description
lifecycle {
prevent_destroy = false
}
}
resource "confluent_service_account" "sr" {
display_name = "sr-${random_id.id.hex}"
description = local.description
lifecycle {
prevent_destroy = false
}
}
resource "confluent_service_account" "clients" {
display_name = "client-${random_id.id.hex}"
description = local.description
lifecycle {
prevent_destroy = false
}
}
# --------------------------------------------------------
# Role Bindings (app_manager, sr, clients)
# --------------------------------------------------------
resource "confluent_role_binding" "app_manager_environment_admin" {
principal = "User:${confluent_service_account.app_manager.id}"
role_name = "EnvironmentAdmin"
crn_pattern = confluent_environment.cc_demo_env.resource_name
lifecycle {
prevent_destroy = false
}
}
resource "confluent_role_binding" "sr_environment_admin" {
principal = "User:${confluent_service_account.sr.id}"
role_name = "EnvironmentAdmin"
crn_pattern = confluent_environment.cc_demo_env.resource_name
lifecycle {
prevent_destroy = false
}
}
resource "confluent_role_binding" "clients_cluster_admin" {
principal = "User:${confluent_service_account.clients.id}"
role_name = "CloudClusterAdmin"
crn_pattern = confluent_kafka_cluster.cc_kafka_cluster.rbac_crn
lifecycle {
prevent_destroy = false
}
}
# --------------------------------------------------------
# Credentials / API Keys
# --------------------------------------------------------
# app_manager
resource "confluent_api_key" "app_manager_kafka_cluster_key" {
display_name = "app-manager-${var.cc_cluster_name}-key-${random_id.id.hex}"
description = local.description
owner {
id = confluent_service_account.app_manager.id
api_version = confluent_service_account.app_manager.api_version
kind = confluent_service_account.app_manager.kind
}
managed_resource {
id = confluent_kafka_cluster.cc_kafka_cluster.id
api_version = confluent_kafka_cluster.cc_kafka_cluster.api_version
kind = confluent_kafka_cluster.cc_kafka_cluster.kind
environment {
id = confluent_environment.cc_demo_env.id
}
}
depends_on = [
confluent_role_binding.app_manager_environment_admin
]
lifecycle {
prevent_destroy = false
}
}
# Schema Registry
resource "confluent_api_key" "sr_cluster_key" {
display_name = "sr-${var.cc_cluster_name}-key-${random_id.id.hex}"
description = local.description
owner {
id = confluent_service_account.sr.id
api_version = confluent_service_account.sr.api_version
kind = confluent_service_account.sr.kind
}
managed_resource {
id = confluent_schema_registry_cluster.cc_sr_cluster.id
api_version = confluent_schema_registry_cluster.cc_sr_cluster.api_version
kind = confluent_schema_registry_cluster.cc_sr_cluster.kind
environment {
id = confluent_environment.cc_demo_env.id
}
}
depends_on = [
confluent_role_binding.sr_environment_admin
]
lifecycle {
prevent_destroy = false
}
}
# Kafka clients
resource "confluent_api_key" "clients_kafka_cluster_key" {
display_name = "clients-${var.cc_cluster_name}-key-${random_id.id.hex}"
description = local.description
owner {
id = confluent_service_account.clients.id
api_version = confluent_service_account.clients.api_version
kind = confluent_service_account.clients.kind
}
managed_resource {
id = confluent_kafka_cluster.cc_kafka_cluster.id
api_version = confluent_kafka_cluster.cc_kafka_cluster.api_version
kind = confluent_kafka_cluster.cc_kafka_cluster.kind
environment {
id = confluent_environment.cc_demo_env.id
}
}
depends_on = [
confluent_role_binding.clients_cluster_admin
]
lifecycle {
prevent_destroy = false
}
}