-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
92 lines (87 loc) · 2.16 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
variable "context" {
description = "Radius-provided object containing information about the resource calling the Recipe."
type = any
}
variable "port" {
description = "The port Redis is offered on. Defaults to 6379."
type = number
default = 6379
}
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0"
}
}
}
resource "kubernetes_deployment" "redis" {
metadata {
name = "redis-${sha512(var.context.resource.id)}"
namespace = var.context.runtime.kubernetes.namespace
labels = {
app = "redis"
}
}
spec {
selector {
match_labels = {
app = "redis"
resource = var.context.resource.name
}
}
template {
metadata {
labels = {
app = "redis"
resource = var.context.resource.name
}
}
spec {
container {
name = "redis"
image = "redis:6"
port {
container_port = 6379
}
}
}
}
}
}
resource "kubernetes_service" "redis" {
metadata {
name = "redis-${var.context.resource.name}"
namespace = var.context.runtime.kubernetes.namespace
}
spec {
type = "ClusterIP"
selector = {
app = "redis"
resource = var.context.resource.name
}
port {
port = var.port
target_port = "6379"
}
}
}
output "result" {
value = {
values = {
host = "${kubernetes_service.redis.metadata[0].name}.${kubernetes_service.redis.metadata[0].namespace}.svc.cluster.local"
port = kubernetes_service.redis.spec[0].port[0].port
username = ""
}
secrets = {
password = ""
}
// UCP resource IDs
resources = [
"/planes/kubernetes/local/namespaces/${kubernetes_service.redis.metadata[0].namespace}/providers/core/Service/${kubernetes_service.redis.metadata[0].name}",
"/planes/kubernetes/local/namespaces/${kubernetes_deployment.redis.metadata[0].namespace}/providers/apps/Deployment/${kubernetes_deployment.redis.metadata[0].name}"
]
}
description = "The result of the Recipe. Must match the target resource's schema."
sensitive = true
}