|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// Create and configure the Argo CD installation |
| 3 | +// |
| 4 | +// ---------------------------------------------------------------------------- |
| 5 | +locals {} |
| 6 | + |
| 7 | +resource "helm_release" "bootstrap" { |
| 8 | + provider = helm |
| 9 | + name = "argocd" |
| 10 | + chart = "argo-cd" |
| 11 | + namespace = "argocd" |
| 12 | + repository = "https://argoproj.github.io/argo-helm" |
| 13 | + version = "5.13.6" |
| 14 | + create_namespace = true |
| 15 | + values = [ |
| 16 | + jsonencode( |
| 17 | + { |
| 18 | + "configs" : { |
| 19 | + "cm" : { |
| 20 | + "resource.compareoptions" : "ignoreAggregatedRoles: true" |
| 21 | + } |
| 22 | + }, |
| 23 | + "controller" : { |
| 24 | + "serviceAccount" : { |
| 25 | + "annotations" : { |
| 26 | + "iam.gke.io/gcp-service-account" : "argocd-${var.cluster_name}@${var.gcp_project}.iam.gserviceaccount.com" |
| 27 | + } |
| 28 | + }, |
| 29 | + }, |
| 30 | + "repoServer" : { |
| 31 | + "autoscaling" : { |
| 32 | + "enabled" : true, |
| 33 | + "minReplicas" : 2 |
| 34 | + }, |
| 35 | + "initContainers" : [ |
| 36 | + { |
| 37 | + "name" : "download-tools", |
| 38 | + "image" : "ghcr.io/helmfile/helmfile:v0.147.0", |
| 39 | + "command" : [ |
| 40 | + "sh", |
| 41 | + "-c" |
| 42 | + ], |
| 43 | + "args" : [ |
| 44 | + "wget -qO /custom-tools/argo-cd-helmfile.sh https://raw.githubusercontent.com/travisghansen/argo-cd-helmfile/master/src/argo-cd-helmfile.sh && chmod +x /custom-tools/argo-cd-helmfile.sh && mv /usr/local/bin/helmfile /custom-tools/helmfile" |
| 45 | + ], |
| 46 | + "volumeMounts" : [ |
| 47 | + { |
| 48 | + "mountPath" : "/custom-tools", |
| 49 | + "name" : "custom-tools" |
| 50 | + } |
| 51 | + ] |
| 52 | + } |
| 53 | + ], |
| 54 | + "serviceAccount" : { |
| 55 | + "annotations" : { |
| 56 | + "iam.gke.io/gcp-service-account" : "argocd-${var.cluster_name}@${var.gcp_project}.iam.gserviceaccount.com" |
| 57 | + } |
| 58 | + }, |
| 59 | + "volumes" : [ |
| 60 | + { |
| 61 | + "name" : "custom-tools", |
| 62 | + "emptyDir" : {} |
| 63 | + } |
| 64 | + ], |
| 65 | + "volumeMounts" : [ |
| 66 | + { |
| 67 | + "mountPath" : "/usr/local/bin/argo-cd-helmfile.sh", |
| 68 | + "name" : "custom-tools", |
| 69 | + "subPath" : "argo-cd-helmfile.sh" |
| 70 | + }, |
| 71 | + { |
| 72 | + "mountPath" : "/usr/local/bin/helmfile", |
| 73 | + "name" : "custom-tools", |
| 74 | + "subPath" : "helmfile" |
| 75 | + } |
| 76 | + ] |
| 77 | + }, |
| 78 | + "server" : { |
| 79 | + "autoscaling" : { |
| 80 | + "enabled" : true, |
| 81 | + "minReplicas" : 2 |
| 82 | + } |
| 83 | + "ingress" : { |
| 84 | + "enabled" : true, |
| 85 | + "annotations" : { |
| 86 | + "nginx.ingress.kubernetes.io/backend-protocol" : "HTTPS", |
| 87 | + "nginx.ingress.kubernetes.io/force-ssl-redirect" : "true", |
| 88 | + "nginx.ingress.kubernetes.io/ssl-passthrough" : "true" |
| 89 | + }, |
| 90 | + "hosts" : [ |
| 91 | + "argocd.${var.apex_domain}" |
| 92 | + ], |
| 93 | + "serviceAccount" : { |
| 94 | + "annotations" : { |
| 95 | + "iam.gke.io/gcp-service-account" : "argocd-${var.cluster_name}@${var.gcp_project}.iam.gserviceaccount.com" |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + ) |
| 102 | + ] |
| 103 | + |
| 104 | + set { |
| 105 | + name = "configs.cm.configManagementPlugins" |
| 106 | + value = <<-EOT |
| 107 | + - name: helmfile |
| 108 | + init: # Optional command to initialize application source directory |
| 109 | + command: ["argo-cd-helmfile.sh"] |
| 110 | + args: ["init"] |
| 111 | + generate: # Command to generate manifests YAML |
| 112 | + command: ["argo-cd-helmfile.sh"] |
| 113 | + args: ["generate"] |
| 114 | + EOT |
| 115 | + } |
| 116 | + set { |
| 117 | + name = "configs.credentialTemplates.https-creds.url" |
| 118 | + value = regex("\\w+://\\w+\\.\\w+", var.jx_git_url) |
| 119 | + } |
| 120 | + set_sensitive { |
| 121 | + name = "configs.credentialTemplates.https-creds.username" |
| 122 | + value = var.jx_bot_username |
| 123 | + } |
| 124 | + set_sensitive { |
| 125 | + name = "configs.credentialTemplates.https-creds.password" |
| 126 | + value = var.jx_bot_token |
| 127 | + } |
| 128 | + |
| 129 | + dynamic "set" { |
| 130 | + for_each = var.helm_values |
| 131 | + content { |
| 132 | + name = set.key |
| 133 | + value = set.value |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + lifecycle { |
| 138 | + ignore_changes = all |
| 139 | + } |
| 140 | +} |
0 commit comments