Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alekc committed Nov 17, 2024
1 parent 89d4228 commit 3a2f950
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 14 deletions.
4 changes: 2 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ locals {
# Other labels can go here.
}, var.labels)

helm_parameters = [
helm_parameters = var.helm_parameters != null ? [
for parameter in var.helm_parameters :
{
name = parameter["name"],
value = parameter["value"],
forceString = parameter["force_string"]
}
]
] : null
}
36 changes: 26 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
variable "automated_allow_empty" {
description = "Allows deleting all application resources during automatic syncing ( false by default )."
type = bool
default = false
}
locals {
main_source = {
repoURL = var.repo_url
targetRevision = var.target_revision
chart = var.app_source == "helm" ? var.chart : null
chart = var.chart
path = var.path
helm = var.app_source == "helm" ? {
releaseName = var.release_name == null ? var.name : var.release_name
helm = var.chart != null ? {
passCredentials = var.helm_pass_credentials
parameters = local.helm_parameters
values = var.helm_values
valuesObject = var.helm_values_object
skipCrds = var.skip_crd
fileParameters = var.helm_files_parameters
releaseName = var.release_name == null ? var.name : var.release_name
valueFiles = var.helm_values_files
ignoreMissingValueFiles = var.helm_ignore_missing_values
values = var.helm_values
valuesObject = var.helm_values_object
skipCrds = var.helm_skip_crd
version = var.helm_version
kubeVersion = var.helm_kube_version
apiVersions = var.helm_api_versions
namespace = var.helm_namespace
} : null
}
additional_sources = var.additional_yaml_manifests == null ? [] : [{
additional_sources = var.additional_sources == null ? [] : [for k, yaml_string in var.additional_sources : yamldecode(yaml_string)]
additional_manifests = var.additional_yaml_manifests == null ? [] : [{
repoURL = "https://kiwigrid.github.io"
targetRevision = "0.1.0"
chart = "any-resource"
Expand All @@ -25,7 +37,7 @@ locals {
}
}]
sources = flatten([
[local.main_source], local.additional_sources
[local.main_source], local.additional_manifests, local.additional_sources
])

manifest = {
Expand All @@ -47,16 +59,19 @@ locals {
namespace = var.namespace
}
ignoreDifferences = var.ignore_differences
info = var.info
syncPolicy = merge(
{
automated = {
prune = var.automated_prune
selfHeal = var.automated_self_heal
prune = var.automated_prune
selfHeal = var.automated_self_heal
allowEmpty = var.automated_allow_empty
}
// https://argo-cd.readthedocs.io/en/latest/user-guide/sync-options/
syncOptions = concat(var.sync_options, [
var.sync_option_validate ? "Validate=true" : "Validate=false",
var.sync_option_create_namespace ? "CreateNamespace=true" : "CreateNamespace=false",
var.prune_propagation_policy != null ? "PrunePropagationPolicy=${var.prune_propagation_policy}" : null,
var.server_side_apply ? "ServerSideApply=true" : "ServerSideApply=false",
var.apply_out_of_sync_only ? "ApplyOutOfSyncOnly=true" : "ApplyOutOfSyncOnly=false",
var.replace ? "Replace=true" : "Replace=false",
Expand All @@ -78,6 +93,7 @@ locals {
}
}
}

resource "kubectl_manifest" "argo_application" {
yaml_body = yamlencode(local.manifest)
wait = var.wait_for_deletion
Expand Down
55 changes: 53 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ variable "helm_parameters" {
force_string : bool,
}))
description = "Parameters that will override helm_values"
default = []
default = null
}
variable "helm_values" {
type = string
Expand Down Expand Up @@ -159,7 +159,7 @@ variable "wait_for_deletion" {
description = "If set to true, will wait until the object is removed completely from kubernetes before proceeding further"
default = false
}
variable "skip_crd" {
variable "helm_skip_crd" {
default = false
description = "If set to true, it will skip the deployment of crd entities from the helm chart"
}
Expand Down Expand Up @@ -203,4 +203,55 @@ variable "additional_yaml_manifests" {
type = map(string)
default = null
description = "Additional YAML manifests to be applied to the application"
}
variable "additional_sources" {
type = map(string)
description = "Additional sources (in yaml manifests) to be applied to the application"
default = null
}
variable "helm_pass_credentials" {
default = null
type = bool
description = "f true then adds --pass-credentials to Helm commands to pass credentials to all domains"
}
variable "helm_version" {
default = null
type = string
description = "Optional Helm version to template with. If omitted it will fall back to look at the 'apiVersion' in Chart.yaml and decide which Helm binary to use automatically. This field can be either 'v2' or 'v3'."
validation {
condition = var.helm_version == null || var.helm_version == "v2" || var.helm_version == "v3"
error_message = "helm_version must be either 'v2' or 'v3'"
}
}
variable "helm_kube_version" {
description = "You can specify the Kubernetes API version to pass to Helm when templating manifests. By default, Argo CD uses the Kubernetes version of the target cluster. The value must be semver formatted. Do not prefix with `v`."
default = null
type = string
}
variable "helm_api_versions" {
description = "# You can specify the Kubernetes resource API versions to pass to Helm when templating manifests. By default, ArgoCD uses the API versions of the target cluster. The format is [group/]version/kind."
type = list(string)
default = null
}
variable "helm_namespace" {
description = "Optional namespace to template with. If left empty, defaults to the app's destination namespace."
type = string
default = null
}
variable "info" {
description = "Extra information to show in the Argo CD Application details tab"
type = list(object({
name : string
value : string
}))
default = null
}
variable "prune_propagation_policy" {
description = "Supported policies are background, foreground and orphan."
type = string
default = "foreground"
validation {
condition = var.prune_propagation_policy == "foreground" || var.prune_propagation_policy == "background" || var.prune_propagation_policy == "orphan"
error_message = "Supported policies are background, foreground and orphan."
}
}

0 comments on commit 3a2f950

Please sign in to comment.