From 9f6c4e0de12a4ce66c3a0b2e6cd5e2fd7a0dab5a Mon Sep 17 00:00:00 2001 From: leonsteinhaeuser Date: Fri, 27 Oct 2023 13:38:02 +0200 Subject: [PATCH 1/6] feat: added environment based context annotations Signed-off-by: leonsteinhaeuser --- main.tf | 15 +++++++++++++++ variables.tf | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/main.tf b/main.tf index 2004e4b..59e612f 100644 --- a/main.tf +++ b/main.tf @@ -1,6 +1,8 @@ locals { cluster_identifier = var.generator_segment_index_overwrite == null ? ".path.basenameNormalized" : "(index .path.segments ${var.generator_segment_index_overwrite})" resource_name = "{{ ${local.cluster_identifier} }}${var.application_name_suffix != "" ? "-${var.application_name_suffix}" : ""}" + + json_encoded_env_based_annotations = jsonencode(var.env_context_annotations) } resource "argocd_application_set" "this" { @@ -60,6 +62,19 @@ resource "argocd_application_set" "this" { "managed-by" = "argo-cd", "application-set" = var.name }, + { + for k, v in var.env_context_annotations : k => < Date: Fri, 27 Oct 2023 13:39:44 +0200 Subject: [PATCH 2/6] chore: updated example config Signed-off-by: leonsteinhaeuser --- examples/main.tf | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/main.tf b/examples/main.tf index 3721cdd..4de597e 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -34,4 +34,17 @@ module "example" { self_heal = true allow_empty = true } + env_context_annotations = { + "argocd-image-updater.argoproj.io/image-list" = "xyz=tagesspiegel/xyz" + "argocd-image-updater.argoproj.io/xyz.update-strategy" = "latest" + "argocd-image-updater.argoproj.io/xyz.allow-tags" = < Date: Fri, 27 Oct 2023 11:47:30 +0000 Subject: [PATCH 3/6] terraform-docs: automated action --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2f30d84..47c5d4d 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ No modules. |------|-------------|------|---------|:--------:| | [annotations](#input\_annotations) | Annotations to apply to the application set | `map(string)` | `{}` | no | | [application\_name\_suffix](#input\_application\_name\_suffix) | Optional suffix to add to the application name. This is useful if you want to deploy the same application multiple times to the same cluster. The suffix is added to the application name after the cluster name. e.g. prometheus-staging-. ArgoCD based gotemplating is supported. e.g. {{ index .path.segments 2 }} | `string` | `null` | no | +| [env\_context\_annotations](#input\_env\_context\_annotations) | A map of annotations that are rendered via go template. Available variables are cluster, resourceName and applicationName. You can access the variables using go templating. e.g. {{ $cluster }}, {{ $resourceName }}, {{ $applicationName }} | `map(string)` | `{}` | no | | [generator](#input\_generator) | The generator configuration. Only one generator can be used at a time. |
object({
git = optional(object({
repo_url = string
revision = string
files = optional(list(string))
directories = optional(list(object({
path = string
exclude = bool
})))
}))
pull_request = optional(list(object({
requeue_after_seconds = number
repo = string
labels = list(string)
})))
})
| n/a | yes | | [generator\_segment\_index\_overwrite](#input\_generator\_segment\_index\_overwrite) | Optional generator setting to override the index path segment during path selection. This option should only be set if generator.git.directories is used. Otherwise it should be left empty as it may affect the behavior. If this option is set in combination with generator.git.directories and your repository contains the cluster folder name in its root directory, this option should be set to 0. In all other cases, this option should reflect the index segment level to the directory corresponding to the cluster name. | `number` | `null` | no | | [ignore\_difference](#input\_ignore\_difference) | A list of object kinds to ignore during the diff process. This is useful if you want to ignore certain differences between the application set and the cluster. e.g. if you want to ignore differences in the namespace labels. |
list(object({
group = optional(string)
jq_path_expressions = optional(list(string))
json_pointers = optional(list(string))
kind = optional(string)
name = optional(string)
namespace = optional(string)
}))
| `null` | no | From cab088ec2979e6a907dde62136fe7e9fdf64ff95 Mon Sep 17 00:00:00 2001 From: leonsteinhaeuser Date: Fri, 27 Oct 2023 13:48:48 +0200 Subject: [PATCH 4/6] fix: terraform formatting Signed-off-by: leonsteinhaeuser --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 34bd246..1d4d9c7 100644 --- a/variables.tf +++ b/variables.tf @@ -172,5 +172,5 @@ variable "ignore_difference" { variable "env_context_annotations" { type = map(string) description = "A map of annotations that are rendered via go template. Available variables are cluster, resourceName and applicationName. You can access the variables using go templating. e.g. {{ $cluster }}, {{ $resourceName }}, {{ $applicationName }}" - default = {} + default = {} } From 1e940de59906c0cea82319b99ee3422629b0cf7a Mon Sep 17 00:00:00 2001 From: leonsteinhaeuser Date: Fri, 27 Oct 2023 14:09:28 +0200 Subject: [PATCH 5/6] chore: improved go template handling Signed-off-by: leonsteinhaeuser --- main.tf | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 59e612f..e3d3bd5 100644 --- a/main.tf +++ b/main.tf @@ -66,13 +66,7 @@ resource "argocd_application_set" "this" { for k, v in var.env_context_annotations : k => < Date: Fri, 27 Oct 2023 14:25:09 +0200 Subject: [PATCH 6/6] chore: improved env context annotations handling Signed-off-by: leonsteinhaeuser --- main.tf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.tf b/main.tf index e3d3bd5..43db596 100644 --- a/main.tf +++ b/main.tf @@ -63,11 +63,7 @@ resource "argocd_application_set" "this" { "application-set" = var.name }, { - for k, v in var.env_context_annotations : k => < "{{ $applicationName := \"${var.name}\" }}{{ $resourceName := \"${local.resource_name}\" }}{{ $cluster := \"\" }}{{ if eq (index .Path.Segments 1) \"general-purpose\" }}{{ $cluster = \"in-cluster\" }}{{ else }}{{ $cluster = (index .Path.Segments 1) }}{{ end }}${v}" } ) labels = merge(