From 0d9fb81d1eb702ebed57bb2572c24a51d7627676 Mon Sep 17 00:00:00 2001 From: Dylan Turnbull Date: Mon, 22 Nov 2021 16:10:47 -0600 Subject: [PATCH 1/4] removed the k8s_manifest and replaced it with a kubernetes_manifest object --- .terraform.lock.hcl | 18 ++++++++++++++ README.md | 14 ++++++++--- locals.tf | 54 ++---------------------------------------- main.tf | 57 +++++++++++++++++++++++++++++++++++++++++++-- variables.tf | 5 ---- versions.tf | 6 ++--- 6 files changed, 88 insertions(+), 66 deletions(-) diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index e57c3e5..ef76e7c 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -20,3 +20,21 @@ provider "registry.terraform.io/banzaicloud/k8s" { "zh:ff204d13e191a65c37a357f28e623e02c132ae26a8c1939acf1a4bf6177ae892", ] } + +provider "registry.terraform.io/hashicorp/kubernetes" { + version = "2.6.1" + hashes = [ + "h1:DWgawNO2C7IuXC2v9IjTSsqs1vZHSAbP4ilWQ0LdbwI=", + "zh:081fbaf9441ebb278753dcf05f318fa7d445e9599a600d7c525e9a18b871d4c8", + "zh:143bfbe871c628981d756ead47486e807fce876232d05607e0b8852ebee4eed8", + "zh:34f413a644eb952e3f041d67ef19200f4c286d374eae87b60fafdd8bf6bb5654", + "zh:370562be70233be730e1876d565710c3ef477e047f209cb3dff8a4a3217a6461", + "zh:443021df6d56e59e4d8dda8e57b506affff32b8a22de09661d21b98bc781fefb", + "zh:51a9501360b58adf9ee6e09fb81f555042ebc909ab36e06ccfc5e701e91f9923", + "zh:7d41d48b8291b98e0a4b7a1f79a9d1fe140a2e0d8df422c5b48cbae4c3fa615a", + "zh:881b3e44814d7d49a5820e2e4b13ee3d000b5baf7957df774a909f17472ece8a", + "zh:b860ff68a944de63fbe0a624c41f2e373711a2da4298c0f0cb151e00fb32a6b3", + "zh:c4ab48ea6e0f8d4a6db1abab1877addb2b21ecd126e505c74b8c85804bd92cbe", + "zh:e96589575dfd31eab48fcc85466dd49895925473c60c802b346cdb4037953350", + ] +} diff --git a/README.md b/README.md index 94ffb5b..df025ec 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,17 @@ The only hard requirement is a Kubernetes cluster with a functioning ArgoCD depl --- -### TODO: -- Update the Terraform version to 1.0+ -- Deprecate the `k8s` provider in favor of the `kubernetes_manifest` resource in the `kubernetes` provider. +### Upate from >v1.0.5 +When upgrading from v1.0.5 or older to v1.1.0+ you will need to import all the argocd application manifests + +**Import the resource state from the cluster** +```shell +# Import the ArgoCD application using the new provider +terraform import -var-file=secrets.tfvars 'module.octal-extras.module.octal_extras_kubedb[0].module.kubedb_argocd_application.kubernetes_manifest.argo_application' "apiVersion=argoproj.io/v1alpha1,kind=Application,namespace=kube-argocd,name=kubedb" + +# Delete the state reference to the old k8s_manifest object +terraform state rm 'module.octal-extras.module.octal_extras_kubedb[0].module.kubedb_argocd_application.k8s_manifest.argo_application' +``` ### Example ```hcl-terraform diff --git a/locals.tf b/locals.tf index a6423de..4364886 100644 --- a/locals.tf +++ b/locals.tf @@ -1,8 +1,8 @@ locals { - labels = { + labels = merge({ # Other labels can go here. - } + }, var.labels) helm_parameters = [ for parameter in var.helm_parameters : @@ -12,54 +12,4 @@ locals { forceString = parameter["force_string"] } ] - - helm_application = { - apiVersion = "argoproj.io/v1alpha1" - kind = "Application" - metadata = { - name = var.name - namespace = var.argocd_namespace - labels = local.labels - } - finalizers = var.cascade_delete ? ["resources-finalizer.argocd.argoproj.io"] : [] - spec = { - project = var.project - source = { - repoURL = var.repo_url - targetRevision = var.target_revision - chart = var.chart - path = var.path - helm = { - version = var.helm_template_version - releaseName = var.release_name == null ? var.name : var.release_name - parameters = local.helm_parameters - values = yamlencode(merge({ labels = merge(local.labels, var.labels) }, var.helm_values)) - } - } - destination = { - server = var.destination_server - namespace = var.namespace - } - ignoreDifferences = var.ignore_differences - syncPolicy = { - automated = { - prune = var.automated_prune - selfHeal = var.automated_self_heal - } - syncOptions = concat(var.sync_options, [ - var.sync_option_validate ? "Validate=true" : "Validate=false", - var.sync_option_create_namespace ? "CreateNamespace=true" : "CreateNamespace=false", - ]) - retry = { - limit = var.retry_limit - backoff = { - duration = var.retry_backoff_duration - factor = var.retry_backoff_factor - maxDuration = var.retry_backoff_max_duration - } - } - } - ignoreDifferences = var.ignore_differences - } - } } \ No newline at end of file diff --git a/main.tf b/main.tf index abfdad1..c5cec95 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,56 @@ -resource "k8s_manifest" "argo_application" { - content = yamlencode(local.helm_application) +resource "kubernetes_manifest" "argo_application" { + computed_fields = [ + "metadata.labels", + "metadata.annotations", + "metadata.finalizers", + "spec.source.helm.version" + ] + manifest = { + apiVersion = "argoproj.io/v1alpha1" + kind = "Application" + metadata = { + name = var.name + namespace = var.argocd_namespace + labels = local.labels + finalizers = var.cascade_delete == true ? ["resources-finalizer.argocd.argoproj.io"] : [] + } + spec = { + project = var.project + source = { + repoURL = var.repo_url + targetRevision = var.target_revision + chart = var.chart + path = var.path + helm = { + releaseName = var.release_name == null ? var.name : var.release_name + parameters = local.helm_parameters + values = yamlencode(merge({ labels = local.labels }, var.helm_values)) + } + } + destination = { + server = var.destination_server + namespace = var.namespace + } + ignoreDifferences = var.ignore_differences + syncPolicy = { + automated = { + prune = var.automated_prune + selfHeal = var.automated_self_heal + } + syncOptions = concat(var.sync_options, [ + var.sync_option_validate ? "Validate=true" : "Validate=false", + var.sync_option_create_namespace ? "CreateNamespace=true" : "CreateNamespace=false", + ]) + retry = { + limit = var.retry_limit + backoff = { + duration = var.retry_backoff_duration + factor = var.retry_backoff_factor + maxDuration = var.retry_backoff_max_duration + } + } + } + ignoreDifferences = var.ignore_differences + } + } } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 1f0a3b9..a8d43ed 100644 --- a/variables.tf +++ b/variables.tf @@ -25,11 +25,6 @@ variable "release_name" { description = "Release name override (defaults to application name)" default = null } -variable "helm_template_version" { - type = string - description = "Optional Helm version to template with. If omitted it will fallback to look at the 'apiVersion' in Chart.yaml and decide which Helm binary to use automatically. This field can be either 'v2' or 'v3'." - default = null -} variable "helm_parameters" { type = list(object({ name : string, diff --git a/versions.tf b/versions.tf index 0b271d5..c91d430 100644 --- a/versions.tf +++ b/versions.tf @@ -1,10 +1,8 @@ terraform { required_version = ">= 0.13, < 2.0.0" required_providers { - # This should be replaced by https://github.com/hashicorp/terraform-provider-kubernetes-alpha eventually... - k8s = { - version = ">= 0.8.0" - source = "banzaicloud/k8s" + kubernetes = { + source = "hashicorp/kubernetes" } } } From 71c3ca734866f2d716826a474f7d2f3d8d7bfee6 Mon Sep 17 00:00:00 2001 From: Dylan Turnbull Date: Mon, 22 Nov 2021 16:40:08 -0600 Subject: [PATCH 2/4] bumped the minimum Terraform version per the kubernetes provider docs --- versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.tf b/versions.tf index c91d430..b034a39 100644 --- a/versions.tf +++ b/versions.tf @@ -1,5 +1,5 @@ terraform { - required_version = ">= 0.13, < 2.0.0" + required_version = ">= 0.14.8, < 2.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" From 0f299dc0fa80cbf5d52acdc14894e51cefd9f245 Mon Sep 17 00:00:00 2001 From: Dylan Turnbull Date: Tue, 23 Nov 2021 19:40:38 -0600 Subject: [PATCH 3/4] tf fmt --- main.tf | 10 +++++----- versions.tf | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index c5cec95..d35c179 100644 --- a/main.tf +++ b/main.tf @@ -1,17 +1,17 @@ resource "kubernetes_manifest" "argo_application" { - computed_fields = [ + computed_fields = [ "metadata.labels", "metadata.annotations", "metadata.finalizers", "spec.source.helm.version" ] manifest = { - apiVersion = "argoproj.io/v1alpha1" + apiVersion = "argoproj.io/v1alpha1" kind = "Application" metadata = { - name = var.name - namespace = var.argocd_namespace - labels = local.labels + name = var.name + namespace = var.argocd_namespace + labels = local.labels finalizers = var.cascade_delete == true ? ["resources-finalizer.argocd.argoproj.io"] : [] } spec = { diff --git a/versions.tf b/versions.tf index b034a39..e765ccc 100644 --- a/versions.tf +++ b/versions.tf @@ -5,4 +5,4 @@ terraform { source = "hashicorp/kubernetes" } } -} +} \ No newline at end of file From a4ce5b94567ac28d043d6989430656a35d97baff Mon Sep 17 00:00:00 2001 From: Dylan Turnbull Date: Tue, 23 Nov 2021 19:41:08 -0600 Subject: [PATCH 4/4] update documentation --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index df025ec..cf7b61e 100644 --- a/README.md +++ b/README.md @@ -70,14 +70,13 @@ module "argocd_application" { | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13 | -| [k8s](#requirement\_k8s) | >= 0.8.0 | +| [terraform](#requirement\_terraform) | >= 0.14.8, < 2.0.0 | ## Providers | Name | Version | |------|---------| -| [k8s](#provider\_k8s) | >= 0.8.0 | +| [kubernetes](#provider\_kubernetes) | 2.6.1 | ## Modules @@ -87,7 +86,7 @@ No modules. | Name | Type | |------|------| -| [k8s_manifest.argo_application](https://registry.terraform.io/providers/banzaicloud/k8s/latest/docs/resources/manifest) | resource | +| [kubernetes_manifest.argo_application](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource | ## Inputs @@ -100,7 +99,6 @@ No modules. | [chart](#input\_chart) | The name of the Helm chart | `string` | n/a | yes | | [destination\_server](#input\_destination\_server) | n/a | `string` | `"https://kubernetes.default.svc"` | no | | [helm\_parameters](#input\_helm\_parameters) | Parameters that will override helm\_values |
list(object({
name : string,
value : any,
force_string : bool,
}))
| `[]` | no | -| [helm\_template\_version](#input\_helm\_template\_version) | Optional Helm version to template with. If omitted it will fallback to look at the 'apiVersion' in Chart.yaml and decide which Helm binary to use automatically. This field can be either 'v2' or 'v3'. | `string` | `null` | no | | [helm\_values](#input\_helm\_values) | Helm values as a block of yaml | `any` | `{}` | no | | [ignore\_differences](#input\_ignore\_differences) | Ignore differences at the specified json pointers | `list(object({ kind : string, group : string, name : string, jsonPointers : list(string) }))` | `[]` | no | | [labels](#input\_labels) | n/a | `map(string)` | `{}` | no |