-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tf
63 lines (57 loc) · 2.05 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
locals {
postfix = var.name_postfix != "" ? var.name_postfix : random_id.id.hex
planCredentialPort = replace(var.plan, "standalone", "") != var.plan ? "port" : "sentinel_port"
}
resource "random_id" "id" {
byte_length = 4
}
resource "cloudfoundry_service_instance" "redis" {
name = "tf-redis-${local.postfix}"
space = var.cf_space_id
tags = var.tags
json_params = var.json_params
//noinspection HILUnresolvedReference
service_plan = data.cloudfoundry_service.redis.service_plans[var.plan]
replace_on_service_plan_change = true
recursive_delete = var.recursive_delete_service
}
resource "cloudfoundry_service_key" "key" {
name = "tf-key-${local.postfix}"
service_instance = cloudfoundry_service_instance.redis.id
}
resource "cloudfoundry_app" "exporter" {
name = "tf-redis-exporter-${local.postfix}"
space = var.cf_space_id
docker_image = var.exporter_image
disk_quota = var.exporter_disk_quota
memory = var.exporter_memory
docker_credentials = {
username = var.docker_username
password = var.docker_password
}
environment = merge({
//noinspection HILUnresolvedReference
REDIS_ADDR = "redis://${cloudfoundry_service_key.key.credentials.hostname}:${cloudfoundry_service_key.key.credentials[local.planCredentialPort]}"
//noinspection HILUnresolvedReference
REDIS_PASSWORD = cloudfoundry_service_key.key.credentials.password
}, var.exporter_environment)
//noinspection HCLUnknownBlockType
routes {
route = cloudfoundry_route.exporter.id
}
labels = {
"variant.tva/exporter" = true,
}
annotations = {
"prometheus.exporter.type" = "redis_exporter"
"prometheus.exporter.port" = "9121"
"prometheus.exporter.path" = "/scrape"
"prometheus.targets.port" = "9122"
"prometheus.targets.path" = "/targets"
}
}
resource "cloudfoundry_route" "exporter" {
domain = data.cloudfoundry_domain.apps_internal_domain.id
space = var.cf_space_id
hostname = "tf-redis-exporter-${local.postfix}"
}