From 7486ab3ae11d87a5df861c708ce5ac2ebb0ed2cd Mon Sep 17 00:00:00 2001 From: Martin Hauskrecht Date: Wed, 22 Sep 2021 15:48:52 +0200 Subject: [PATCH] Add argocd support (#8) * Add Argo support * Update docs * Update argo variable name --- README.md | 7 +++++++ argo.tf | 30 ++++++++++++++++++++++++++++++ main.tf | 2 +- variables.tf | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 argo.tf diff --git a/README.md b/README.md index bbba9f3..3adaa83 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ No modules. | [aws_iam_role.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | | [aws_iam_role_policy_attachment.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | [helm_release.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | +| [kubernetes_manifest.this](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource | | [aws_iam_policy_document.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_iam_policy_document.cluster_autoscaler_assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | @@ -63,6 +64,12 @@ No modules. | [cluster\_identity\_oidc\_issuer](#input\_cluster\_identity\_oidc\_issuer) | The OIDC Identity issuer for the cluster | `string` | n/a | yes | | [cluster\_identity\_oidc\_issuer\_arn](#input\_cluster\_identity\_oidc\_issuer\_arn) | The OIDC Identity issuer ARN for the cluster that can be used to associate IAM roles with a service account | `string` | n/a | yes | | [cluster\_name](#input\_cluster\_name) | The name of the cluster | `string` | n/a | yes | +| [argo\_application\_enabled](#input\_argo\_application\_enabled) | If set to true, the module will be deployed as ArgoCD application, otherwise it will be deployed as a Helm release | `bool` | `false` | no | +| [argo\_destionation\_server](#input\_argo\_destionation\_server) | Destination server for ArgoCD Application | `string` | `"https://kubernetes.default.svc"` | no | +| [argo\_info](#input\_argo\_info) | ArgoCD info manifest parameter | `list` |
[
{
"name": "terraform",
"value": "true"
}
]
| no | +| [argo\_namespace](#input\_argo\_namespace) | Namespace to deploy ArgoCD application CRD to | `string` | `"argo"` | no | +| [argo\_project](#input\_argo\_project) | ArgoCD Application project | `string` | `"default"` | no | +| [argo\_sync\_policy](#input\_argo\_sync\_policy) | ArgoCD syncPolicy manifest parameter | `map` | `{}` | no | | [enabled](#input\_enabled) | Variable indicating whether deployment is enabled | `bool` | `true` | no | | [helm\_chart\_name](#input\_helm\_chart\_name) | Helm chart name to be installed | `string` | `"cluster-autoscaler"` | no | | [helm\_chart\_version](#input\_helm\_chart\_version) | Version of the Helm chart | `string` | `"9.10.3"` | no | diff --git a/argo.tf b/argo.tf new file mode 100644 index 0000000..0897303 --- /dev/null +++ b/argo.tf @@ -0,0 +1,30 @@ +resource "kubernetes_manifest" "this" { + count = var.argo_application_enabled ? 1 : 0 + manifest = { + "apiVersion" = "argoproj.io/v1alpha1" + "kind" = "Application" + "metadata" = { + "name" = var.helm_release_name + "namespace" = var.argo_namespace + } + "spec" = { + "project" = var.argo_project + "source" = { + "repoURL" = var.helm_repo_url + "chart" = var.helm_chart_name + "targetRevision" = var.helm_chart_version + "helm" = { + "releaseName" = var.helm_release_name + "parameters" = [for k, v in var.settings : tomap({ "forceString" : true, "name" : k, "value" : v })] + "values" = data.utils_deep_merge_yaml.values[0].output + } + } + "destination" = { + "server" = var.argo_destionation_server + "namespace" = var.k8s_namespace + } + "syncPolicy" = var.argo_sync_policy + "info" = var.argo_info + } + } +} diff --git a/main.tf b/main.tf index 4cd6109..94418d4 100644 --- a/main.tf +++ b/main.tf @@ -30,7 +30,7 @@ data "utils_deep_merge_yaml" "values" { } resource "helm_release" "cluster_autoscaler" { - count = var.enabled ? 1 : 0 + count = var.enabled && !var.argo_application_enabled ? 1 : 0 chart = var.helm_chart_name create_namespace = var.helm_create_namespace namespace = var.k8s_namespace diff --git a/variables.tf b/variables.tf index b182eed..6f0c88a 100644 --- a/variables.tf +++ b/variables.tf @@ -88,3 +88,41 @@ variable "values" { default = "" description = "Additional yaml encoded values which will be passed to the Helm chart, see https://hub.helm.sh/charts/stable/cluster-autoscaler" } + +variable "argo_namespace" { + type = string + default = "argo" + description = "Namespace to deploy ArgoCD application CRD to" +} + + +variable "argo_application_enabled" { + type = bool + default = false + description = "If set to true, the module will be deployed as ArgoCD application, otherwise it will be deployed as a Helm release" +} + +variable "argo_destionation_server" { + type = string + default = "https://kubernetes.default.svc" + description = "Destination server for ArgoCD Application" +} + +variable "argo_project" { + type = string + default = "default" + description = "ArgoCD Application project" +} + +variable "argo_info" { + default = [{ + "name" = "terraform" + "value" = "true" + }] + description = "ArgoCD info manifest parameter" +} + +variable "argo_sync_policy" { + description = "ArgoCD syncPolicy manifest parameter" + default = {} +}