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

V1 #6

Merged
merged 5 commits into from
Nov 28, 2024
Merged

V1 #6

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
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v1.0.0
* Added support for additional sources (multiple sources in the chart)
* `skip_crd` has been renamed to `helm_skip_crd`
* `helm_parameters` default value is now null
* `helm_values` type is now `string`
* Added `managed_namespace_metadata`, `additional_yaml_manifests`, `additional_sources`,`helm_pass_credentials`,`helm_version`,`helm_kube_version`,`helm_api_versions`,`helm_namespace`,`info`,`prune_propagation_policy`

## V0.0.7
* Fixed name being required, when it was not the case

Expand Down
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
}
109 changes: 73 additions & 36 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
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.chart
path = var.path
helm = var.chart != null ? {
passCredentials = var.helm_pass_credentials
parameters = local.helm_parameters
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_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"
helm = {
valuesObject = {
anyResources = var.additional_yaml_manifests
}
}
}]
sources = flatten([
[local.main_source], local.additional_manifests, local.additional_sources
])

manifest = {
apiVersion = "argoproj.io/v1alpha1"
kind = "Application"
Expand All @@ -11,53 +52,49 @@ locals {
}
spec = {
project = var.project
source = {
repoURL = var.repo_url
targetRevision = var.target_revision
chart = var.app_source == "helm" ? var.chart : null
path = var.path
helm = var.app_source == "helm" ? {
releaseName = var.release_name == null ? var.name : var.release_name
parameters = local.helm_parameters
values = var.helm_values
valuesObject = var.helm_values_object
skipCrds = var.skip_crd
fileParameters = var.helm_files_parameters
ignoreMissingValueFiles = var.helm_ignore_missing_values
} : null
}
sources = length(local.sources) > 1 ? local.sources : null
source = length(local.sources) == 1 ? local.sources[0] : null
destination = {
server = var.destination_server_name != "" ? null : var.destination_server
name = var.destination_server_name == "" ? null : var.destination_server_name
namespace = var.namespace
}
ignoreDifferences = var.ignore_differences
syncPolicy = {
automated = {
prune = var.automated_prune
selfHeal = var.automated_self_heal
}
// 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.server_side_apply ? "ServerSideApply=true" : "ServerSideApply=false",
var.apply_out_of_sync_only ? "ApplyOutOfSyncOnly=true" : "ApplyOutOfSyncOnly=false",
var.replace ? "Replace=true" : "Replace=false",
var.fail_on_shared_resource ? "FailOnSharedResource=true" : "FailOnSharedResource=false",
])
retry = {
limit = var.retry_limit
backoff = {
duration = var.retry_backoff_duration
factor = var.retry_backoff_factor
maxDuration = var.retry_backoff_max_duration
info = var.info
syncPolicy = merge(
{
automated = {
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",
var.fail_on_shared_resource ? "FailOnSharedResource=true" : "FailOnSharedResource=false",
])
retry = {
limit = var.retry_limit
backoff = {
duration = var.retry_backoff_duration
factor = var.retry_backoff_factor
maxDuration = var.retry_backoff_max_duration
}
}
},
var.managed_namespace_metadata == null ? {} : {
managedNamespaceMetadata = var.managed_namespace_metadata
}
}
)
}
}
}

resource "kubectl_manifest" "argo_application" {
yaml_body = yamlencode(local.manifest)
wait = var.wait_for_deletion
Expand Down
70 changes: 67 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ variable "helm_parameters" {
force_string : bool,
}))
description = "Parameters that will override helm_values"
default = []
default = null
}
variable "helm_values" {
type = any
type = string
description = "Helm values as a block of yaml"
default = null
}
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 @@ -190,4 +190,68 @@ variable "helm_ignore_missing_values" {
type = bool
default = false
description = "Ignore locally missing valueFiles when installing Helm chart"
}
variable "managed_namespace_metadata" {
type = object({
labels : optional(map(string), {})
annotations : optional(map(string), {})
})
default = null
description = "Namespace metadata to be applied to namespaces managed by ArgoCD"
}
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."
}
}
Loading