Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: environment context based annotations #8

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ No modules.
|------|-------------|------|---------|:--------:|
| <a name="input_annotations"></a> [annotations](#input\_annotations) | Annotations to apply to the application set | `map(string)` | `{}` | no |
| <a name="input_application_name_suffix"></a> [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-<suffix>. ArgoCD based gotemplating is supported. e.g. {{ index .path.segments 2 }} | `string` | `null` | no |
| <a name="input_env_context_annotations"></a> [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 |
| <a name="input_generator"></a> [generator](#input\_generator) | The generator configuration. Only one generator can be used at a time. | <pre>object({<br> git = optional(object({<br> repo_url = string<br> revision = string<br> files = optional(list(string))<br> directories = optional(list(object({<br> path = string<br> exclude = bool<br> })))<br> }))<br> pull_request = optional(list(object({<br> requeue_after_seconds = number<br> repo = string<br> labels = list(string)<br> })))<br> })</pre> | n/a | yes |
| <a name="input_generator_segment_index_overwrite"></a> [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 |
| <a name="input_ignore_difference"></a> [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. | <pre>list(object({<br> group = optional(string)<br> jq_path_expressions = optional(list(string))<br> json_pointers = optional(list(string))<br> kind = optional(string)<br> name = optional(string)<br> namespace = optional(string)<br> }))</pre> | `null` | no |
Expand Down
13 changes: 13 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" = <<EOT
{{- if eq $cluster "staging" }}
regex:v[0-9]{1,}.[0-9]{1,}.[0-9]{1,}-rc.[0-9]{1,}
{{- else if eq $cluster "production" }}
regex:v[0-9]{1,}.[0-9]{1,}.[0-9]{1,}
{{- else }}
develop
{{- end }}"
EOT
}
}
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down Expand Up @@ -60,6 +62,9 @@ resource "argocd_application_set" "this" {
"managed-by" = "argo-cd",
"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(
var.labels,
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,9 @@ variable "ignore_difference" {
description = "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."
default = null
}

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 = {}
}
Loading