Skip to content

Commit 0339491

Browse files
authored
Ability to install argocd as an extension (#1030)
* fix: added argocd extension added support for deploying argocd as an extension --------- Signed-off-by: Deepak Devadathan <[email protected]>
1 parent 1b5ec8c commit 0339491

File tree

5 files changed

+136
-2
lines changed

5 files changed

+136
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2017, 2023 Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
argocd_install = true
5+
argocd_namespace = "argocd"
6+
argocd_helm_version = "8.1.2"
7+
argocd_helm_values = {}
8+
argocd_helm_values_files = []

module-extensions.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,11 @@ module "extensions" {
122122
# Service Account
123123
create_service_account = var.create_service_account
124124
service_accounts = var.service_accounts
125+
126+
# Argocd
127+
argocd_install = var.argocd_install
128+
argocd_namespace = var.argocd_namespace
129+
argocd_helm_version = var.argocd_helm_version
130+
argocd_helm_values = var.argocd_helm_values
131+
argocd_helm_values_files = var.argocd_helm_values_files
125132
}

modules/extensions/argocd.tf

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright (c) 2021, 2023 Oracle Corporation and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
3+
4+
locals {
5+
argocd_enabled = var.argocd_install && var.expected_node_count > 0
6+
argocd_manifest = sensitive(one(data.helm_template.argocd[*].manifest))
7+
argocd_manifest_path = join("/", [local.yaml_manifest_path, "argocd.yaml"])
8+
}
9+
10+
data "helm_template" "argocd" {
11+
count = local.argocd_enabled ? 1 : 0
12+
chart = "argo-cd"
13+
repository = "https://argoproj.github.io/argo-helm"
14+
version = var.argocd_helm_version
15+
kube_version = var.kubernetes_version
16+
17+
name = "argocd"
18+
namespace = var.argocd_namespace
19+
create_namespace = true
20+
include_crds = true
21+
skip_tests = true
22+
values = length(var.argocd_helm_values_files) > 0 ? [
23+
for path in var.argocd_helm_values_files : file(path)
24+
] : null
25+
26+
set = concat(
27+
[ for k, v in var.argocd_helm_values:
28+
{
29+
name = k,
30+
value = v
31+
}
32+
]
33+
)
34+
35+
lifecycle {
36+
precondition {
37+
condition = alltrue([for path in var.argocd_helm_values_files : fileexists(path)])
38+
error_message = format("Missing Helm values files in configuration: %s",
39+
jsonencode([for path in var.argocd_helm_values_files : path if !fileexists(path)])
40+
)
41+
}
42+
}
43+
}
44+
45+
resource "null_resource" "argocd" {
46+
count = local.argocd_enabled ? 1 : 0
47+
48+
triggers = {
49+
manifest_md5 = try(md5(local.argocd_manifest), null)
50+
}
51+
52+
connection {
53+
bastion_host = var.bastion_host
54+
bastion_user = var.bastion_user
55+
bastion_private_key = var.ssh_private_key
56+
host = var.operator_host
57+
user = var.operator_user
58+
private_key = var.ssh_private_key
59+
timeout = "40m"
60+
type = "ssh"
61+
}
62+
63+
provisioner "remote-exec" {
64+
inline = ["mkdir -p ${local.yaml_manifest_path}"]
65+
}
66+
67+
provisioner "file" {
68+
content = local.argocd_manifest
69+
destination = local.argocd_manifest_path
70+
}
71+
72+
provisioner "remote-exec" {
73+
inline = [for c in compact([
74+
(contains(["kube-system", "default"], var.argocd_namespace) ? null
75+
: format(local.kubectl_create_missing_ns, var.argocd_namespace)),
76+
format(local.kubectl_apply_server_file, local.argocd_manifest_path),
77+
]) : format(local.output_log, c, "argocd")
78+
]
79+
}
80+
}

modules/extensions/variables.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,11 @@ variable "gatekeeper_helm_values_files" { type = list(string) }
105105

106106
# Service Account
107107
variable "create_service_account" { type = bool }
108-
variable "service_accounts" { type = map(any) }
108+
variable "service_accounts" { type = map(any) }
109+
110+
# Argocd
111+
variable "argocd_install" { type = bool }
112+
variable "argocd_namespace" { type = string }
113+
variable "argocd_helm_version" { type = string }
114+
variable "argocd_helm_values" { type = map(string) }
115+
variable "argocd_helm_values_files" { type = list(string) }

variables-extensions.tf

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,36 @@ variable "service_accounts" {
386386
}
387387
description = "Map of service accounts and associated parameters."
388388
type = map(any)
389-
}
389+
}
390+
391+
# Argocd
392+
393+
variable "argocd_install" {
394+
default = false
395+
description = "Whether to deploy the Argocd Helm chart. See https://github.com/argoproj/argo-cd. NOTE: Provided only as a convenience and not supported by or sourced from Oracle - use at your own risk."
396+
type = bool
397+
}
398+
399+
variable "argocd_namespace" {
400+
default = "argocd"
401+
description = "Kubernetes namespace for deployed resources."
402+
type = string
403+
}
404+
405+
variable "argocd_helm_version" {
406+
default = "8.1.2"
407+
description = "Version of the Helm chart to install. List available releases using `helm search repo [keyword] --versions`."
408+
type = string
409+
}
410+
411+
variable "argocd_helm_values" {
412+
default = {}
413+
description = "Map of individual Helm chart values. See <a href=https://registry.terraform.io/providers/hashicorp/helm/latest/docs/data-sources/template>data.helm_template</a>."
414+
type = map(string)
415+
}
416+
417+
variable "argocd_helm_values_files" {
418+
default = []
419+
description = "Paths to a local YAML files with Helm chart values (as with `helm install -f` which supports multiple). Generate with defaults using `helm show values [CHART] [flags]`."
420+
type = list(string)
421+
}

0 commit comments

Comments
 (0)