|
| 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 | +} |
0 commit comments