-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb.tf
98 lines (95 loc) · 3.47 KB
/
mongodb.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
# --------------------------------------------------------------
# Create free tier cluster (only one allowed per Atlas account)
# --------------------------------------------------------------
resource "mongodbatlas_cluster" "cluster-demo" {
project_id = data.external.env_vars.result.MONGODB_ATLAS_PROJECT_ID
name = var.cluster_name_mongodb
provider_name = var.provider_name_mongodb
backing_provider_name = var.cloud_provider_mongodb
provider_region_name = var.cloud_region_mongodb
provider_instance_size_name = var.provider_instance_size_name_mongodb
lifecycle {
prevent_destroy = false
}
}
output "standard_srv" {
# Connection string
value = mongodbatlas_cluster.cluster-demo.connection_strings[0].standard_srv
}
# --------------------------------------------------------
# Whitelist IP Address
# --------------------------------------------------------
resource "mongodbatlas_project_ip_access_list" "my-public-ip" {
project_id = data.external.env_vars.result.MONGODB_ATLAS_PROJECT_ID
cidr_block = data.external.env_vars.result.MONGODB_ATLAS_PUBLIC_IP_ADDRESS
comment = "cidr block for ${var.cluster_name_mongodb}"
lifecycle {
prevent_destroy = false
}
}
# --------------------------------------------------------
# Create DB user
# --------------------------------------------------------
resource "mongodbatlas_database_user" "mongodb-user" {
username = var.username_mongodb
password = random_password.mongodb-password.result
project_id = data.external.env_vars.result.MONGODB_ATLAS_PROJECT_ID
auth_database_name = "admin"
roles {
role_name = "dbAdmin"
database_name = var.database_mongodb
}
roles {
role_name = "readWrite"
database_name = var.database_mongodb
}
lifecycle {
prevent_destroy = false
}
}
output "mongodb-password" {
value = random_password.mongodb-password.result
sensitive = true
}
# --------------------------------------------------------
# MongoDB Sink Connector
# --------------------------------------------------------
resource "confluent_connector" "mongo_db_sink" {
environment {
id = confluent_environment.cc_demo_env.id
}
kafka_cluster {
id = confluent_kafka_cluster.cc_kafka_cluster.id
}
config_sensitive = {
"connection.password" = random_password.mongodb-password.result,
}
config_nonsensitive = {
"connector.class" = "MongoDbAtlasSink"
"name" = "confluent-mongodb-sink"
"kafka.auth.mode" = "SERVICE_ACCOUNT"
"kafka.service.account.id" = confluent_service_account.connectors.id
"write.strategy" = "DefaultWriteModelStrategy",
"database" = var.database_mongodb
"connection.user" = var.username_mongodb
"connection.host" = split("//", mongodbatlas_cluster.cluster-demo.srv_address)[1]
"input.data.format" = "AVRO"
"topics" = "demo-accomplished_female_readers"
"max.num.retries" = "3"
"retries.defer.timeout" = "5000"
"max.batch.size" = "0"
"collection" = "accomplished_female_readers"
"tasks.max" = "1"
}
lifecycle {
prevent_destroy = false
}
depends_on = [
mongodbatlas_cluster.cluster-demo,
shell_script.ksql_queries,
]
}
output "mongo_db_sink" {
description = "CC MongoDB Sink Connector ID"
value = resource.confluent_connector.mongo_db_sink.id
}