-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargocd.tf
132 lines (124 loc) · 3.56 KB
/
argocd.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
resource "kubernetes_namespace" "argocd-namespace" {
count = var.argocd ? 1 : 0
metadata {
name = "argocd"
}
}
resource "helm_release" "argocd" {
name = "argocd"
repository = "https://argoproj.github.io/argo-helm"
chart = "argo-cd"
version = "7.7.0"
namespace = kubernetes_namespace.argocd-namespace
count = var.argocd ? 1 : 0
force_update = true
values = [templatefile("${path.module}/values/argocdvalues.yaml", {
host = "argocd.${var.local_domain}"
argocdServerAdminPassword = bcrypt(var.argocd_admin_pass)
argocdServerAdminPasswordMtime = time_static.now.rfc3339
})]
}
resource "helm_release" "argocd_project" {
description = "projects"
depends_on = [
helm_release.argocd
]
name = "projects"
repository = "https://argoproj.github.io/argo-helm"
chart = "argocd-apps"
version = "2.0.0"
namespace = kubernetes_namespace.argocd-namespace
force_update = true
count = var.argocd_app_of_apps ? 1 : 0
values = [
yamlencode({
projects = [
for project in var.argocd_projects : {
name = project
sourceRepos = [
"*"
]
destinations = [
{
namespace = "*"
server = "*"
}
]
clusterResourceWhitelist = [
{
group = "*"
kind = "*"
}
]
}
]
})
]
}
resource "helm_release" "application" {
description = "Initial app of app"
depends_on = [
helm_release.argocd
]
name = "applications"
repository = "https://argoproj.github.io/argo-helm"
chart = "argocd-apps"
version = "2.0.0"
namespace = kubernetes_namespace.argocd-namespace
force_update = true
count = var.argocd_app_of_apps ? 1 : 0
values = [
yamlencode({
# field values reference -> https://github.com/argoproj/argo-helm/blob/main/charts/argocd-apps/values.yaml
applications = [
for key, value in var.argocd_applications : {
name = key
project = value.application_project
additionalLabels = {
"app.kubernetes.io/managed-by" = "terraform"
}
source = {
repoURL = value.repoURL
targetRevision = value.targetRevision
path = value.path
}
destination = {
namespace = value.destination_namespace
server = "https://kubernetes.default.svc"
}
syncPolicy = {
automated = {
prune = true
selfHeal = true
}
syncOptions = [
"CreateNamespace=true"
]
}
}
]
})
]
}
resource "time_static" "now" {}
resource "kubectl_manifest" "argocd_dashboard" {
yaml_body = file("${path.module}/dashboards/argocd-grafana-dashboard.yaml")
depends_on = [
helm_release.argocd,
kubernetes_namespace.argocd-namespace
]
count = var.argocd ? 1 : 0
}
resource "kubectl_manifest" "argocduihttps" {
yaml_body = file("${path.module}/manifests/argocduihttps.yaml")
# count = length(data.kubectl_filename_list.argocduihttps.matches)
# yaml_body = file(element(data.kubectl_filename_list.argocduihttps.matches, count.index))
depends_on = [
helm_release.argocd,
kubernetes_namespace.argocd-namespace
]
count = var.argocd ? 1 : 0
}
# data "kubectl_filename_list" "argocduihttps" {
# pattern = "./manifests/argocduihttps.yaml"
# }