-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.tf
115 lines (100 loc) · 2.66 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# This blocks creates the Kubernetes cluster
resource "google_container_cluster" "_" {
name = var.kubernetes_name
location = local.region
node_pool {
name = "builtin"
}
lifecycle {
ignore_changes = [node_pool]
}
}
# Creating and attaching the node-pool to the Kubernetes Cluster
resource "google_container_node_pool" "node-pool" {
name = "node-pool"
cluster = google_container_cluster._.id
initial_node_count = 1
node_config {
preemptible = false
machine_type = "e2-standard-4"
}
}
# Create the cluster role binding to give the user the privileges to create resources into Kubernetes
resource "kubernetes_cluster_role_binding" "cluster-admin-binding" {
metadata {
name = "cluster-role-binding"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = "cluster-admin"
}
subject {
kind = "User"
name = "${var.email}"
api_group = "rbac.authorization.k8s.io"
}
subject {
kind = "ServiceAccount"
name = "default"
namespace = "kube-system"
}
subject {
kind = "Group"
name = "system:masters"
api_group = "rbac.authorization.k8s.io"
}
depends_on = [google_container_cluster._, google_container_node_pool.node-pool]
}
# Install ECK operator via helm-charts
resource "helm_release" "elastic" {
name = "elastic-operator"
repository = "https://helm.elastic.co"
chart = "eck-operator"
namespace = "elastic-system"
create_namespace = "true"
depends_on = [google_container_cluster._, google_container_node_pool.node-pool, kubernetes_cluster_role_binding.cluster-admin-binding]
}
# Delay of 30s to wait until ECK operator is up and running
resource "time_sleep" "wait_30_seconds" {
depends_on = [helm_release.elastic]
create_duration = "30s"
}
# Create Elasticsearch manifest
resource "kubectl_manifest" "elastic_quickstart" {
yaml_body = <<YAML
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 8.1.3
nodeSets:
- name: default
count: 3
config:
node.store.allow_mmap: false
YAML
provisioner "local-exec" {
command = "sleep 60"
}
depends_on = [helm_release.elastic, time_sleep.wait_30_seconds]
}
# Create Kibana manifest
resource "kubectl_manifest" "kibana_quickstart" {
yaml_body = <<YAML
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: quickstart
spec:
version: 8.1.3
count: 1
elasticsearchRef:
name: quickstart
YAML
provisioner "local-exec" {
command = "sleep 60"
}
depends_on = [helm_release.elastic, kubectl_manifest.elastic_quickstart]
}