Skip to content

Commit da4cde5

Browse files
authored
Merge pull request #5 from lablabs/fix_k8s_provider_issues
Add dummy helm chart deployment option
2 parents 9da523a + b603b2c commit da4cde5

File tree

8 files changed

+186
-23
lines changed

8 files changed

+186
-23
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Check out these related projects.
3030

3131
See [Basic example](examples/basic/README.md) for further information.
3232

33+
## Potential issues with running terraform plan
34+
35+
When deploying with ArgoCD application, Kubernetes terraform provider requires access to Kubernetes cluster API during plan time. This introduces potential issue when you want to deploy the cluster with this addon at the same time, during the same Terraform run.
36+
37+
To overcome this issue, the module deploys the ArgoCD application object using the Helm provider, which does not require API access during plan. If you want to deploy the application using this workaround, you can set the `argo_application_use_helm` variable to `true`.
38+
3339
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3440
## Requirements
3541

@@ -52,14 +58,16 @@ No modules.
5258
| [aws_iam_policy.cert_manager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
5359
| [aws_iam_role.cert_manager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
5460
| [aws_iam_role_policy_attachment.cert_manager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
61+
| [helm_release.argocd_application](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
5562
| [helm_release.cert_manager](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
5663
| [helm_release.default_cluster_issuer](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
57-
| [kubernetes_manifest.this](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
64+
| [kubernetes_manifest.self](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
5865
| [time_sleep.default_cluster_issuer](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
5966
| [aws_iam_policy_document.cert_manager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
6067
| [aws_iam_policy_document.cert_manager_assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
6168
| [aws_iam_policy_document.cert_manager_irsa](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
6269
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
70+
| [utils_deep_merge_yaml.argo_application_values](https://registry.terraform.io/providers/cloudposse/utils/latest/docs/data-sources/deep_merge_yaml) | data source |
6371
| [utils_deep_merge_yaml.default_cluster_issuer_values](https://registry.terraform.io/providers/cloudposse/utils/latest/docs/data-sources/deep_merge_yaml) | data source |
6472
| [utils_deep_merge_yaml.values](https://registry.terraform.io/providers/cloudposse/utils/latest/docs/data-sources/deep_merge_yaml) | data source |
6573

@@ -71,6 +79,8 @@ No modules.
7179
| <a name="input_cluster_identity_oidc_issuer_arn"></a> [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 |
7280
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name of the cluster | `string` | n/a | yes |
7381
| <a name="input_argo_application_enabled"></a> [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 |
82+
| <a name="input_argo_application_use_helm"></a> [argo\_application\_use\_helm](#input\_argo\_application\_use\_helm) | If set to true, the ArgoCD Application manifest will be deployed using Kubernetes provider as a Helm release. Otherwise it'll be deployed as a Kubernetes manifest. See Readme for more info | `bool` | `false` | no |
83+
| <a name="input_argo_application_values"></a> [argo\_application\_values](#input\_argo\_application\_values) | Value overrides to use when deploying argo application object with helm | `string` | `""` | no |
7484
| <a name="input_argo_destionation_server"></a> [argo\_destionation\_server](#input\_argo\_destionation\_server) | Destination server for ArgoCD Application | `string` | `"https://kubernetes.default.svc"` | no |
7585
| <a name="input_argo_info"></a> [argo\_info](#input\_argo\_info) | ArgoCD info manifest parameter | `list` | <pre>[<br> {<br> "name": "terraform",<br> "value": "true"<br> }<br>]</pre> | no |
7686
| <a name="input_argo_namespace"></a> [argo\_namespace](#input\_argo\_namespace) | Namespace to deploy ArgoCD application CRD to | `string` | `"argo"` | no |

argo.tf

+46-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
1-
resource "kubernetes_manifest" "this" {
2-
count = var.argo_application_enabled ? 1 : 0
1+
locals {
2+
argo_application_values = {
3+
"project" : var.argo_project
4+
"source" : {
5+
"repoURL" : var.helm_repo_url
6+
"chart" : var.helm_chart_name
7+
"targetRevision" : var.helm_chart_version
8+
"helm" : {
9+
"releaseName" : var.helm_release_name
10+
"parameters" : [for k, v in var.settings : tomap({ "forceString" : true, "name" : k, "value" : v })]
11+
"values" : data.utils_deep_merge_yaml.values[0].output
12+
}
13+
}
14+
"destination" : {
15+
"server" : var.argo_destionation_server
16+
"namespace" : var.k8s_namespace
17+
}
18+
"syncPolicy" : var.argo_sync_policy
19+
"info" : var.argo_info
20+
}
21+
}
22+
23+
data "utils_deep_merge_yaml" "argo_application_values" {
24+
count = var.enabled && var.argo_application_enabled && var.argo_application_use_helm ? 1 : 0
25+
input = compact([
26+
yamlencode(local.argo_application_values),
27+
var.argo_application_values
28+
])
29+
}
30+
31+
resource "helm_release" "argocd_application" {
32+
count = var.enabled && var.argo_application_enabled && var.argo_application_use_helm ? 1 : 0
33+
34+
chart = "${path.module}/helm/argocd-application"
35+
name = var.helm_release_name
36+
namespace = var.argo_namespace
37+
38+
values = [
39+
data.utils_deep_merge_yaml.argo_application_values[0].output
40+
]
41+
}
42+
43+
44+
resource "kubernetes_manifest" "self" {
45+
count = var.enabled && var.argo_application_enabled && !var.argo_application_use_helm ? 1 : 0
346
manifest = {
447
"apiVersion" = "argoproj.io/v1alpha1"
548
"kind" = "Application"
649
"metadata" = {
750
"name" = var.helm_release_name
851
"namespace" = var.argo_namespace
952
}
10-
"spec" = {
11-
"project" = var.argo_project
12-
"source" = {
13-
"repoURL" = var.helm_repo_url
14-
"chart" = var.helm_chart_name
15-
"targetRevision" = var.helm_chart_version
16-
"helm" = {
17-
"releaseName" = var.helm_release_name
18-
"parameters" = [for k, v in var.settings : tomap({ "forceString" : true, "name" : k, "value" : v })]
19-
"values" = data.utils_deep_merge_yaml.values[0].output
20-
}
21-
}
22-
"destination" = {
23-
"server" = var.argo_destionation_server
24-
"namespace" = var.k8s_namespace
25-
}
26-
"syncPolicy" = var.argo_sync_policy
27-
"info" = var.argo_info
28-
}
53+
"spec" = local.argo_application_values
2954
}
3055
}

helm/argocd-application/.helmignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/argocd-application/Chart.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v2
2+
name: argocd-application
3+
description: Helm wrapper for deploying ArgoCD application object
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "argocd_application.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "argocd_application.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "argocd_application.chart" -}}
30+
{{- printf "%s" .Chart.Name | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "argocd_application.labels" -}}
37+
helm.sh/chart: {{ include "argocd_application.chart" . }}
38+
{{ include "argocd_application.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "argocd_application.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "argocd_application.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: {{ include "argocd_application.fullname" . }}
5+
labels:
6+
{{- include "argocd_application.labels" . | nindent 4 }}
7+
spec:
8+
project: {{ .Values.project }}
9+
{{ with .Values.source }}
10+
source:
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
13+
{{ with .Values.destination }}
14+
destination:
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
{{ with .Values.syncPolicy }}
18+
syncPolicy:
19+
{{- toYaml . | nindent 4 }}
20+
{{- end }}
21+
{{ with .Values.info }}
22+
info:
23+
{{- toYaml . | nindent 4 }}
24+
{{- end }}

helm/argocd-application/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nameOverride: ""
2+
fullnameOverride: ""

variables.tf

+11-1
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,23 @@ variable "argo_namespace" {
126126
description = "Namespace to deploy ArgoCD application CRD to"
127127
}
128128

129-
130129
variable "argo_application_enabled" {
131130
type = bool
132131
default = false
133132
description = "If set to true, the module will be deployed as ArgoCD application, otherwise it will be deployed as a Helm release"
134133
}
135134

135+
variable "argo_application_use_helm" {
136+
type = bool
137+
default = false
138+
description = "If set to true, the ArgoCD Application manifest will be deployed using Kubernetes provider as a Helm release. Otherwise it'll be deployed as a Kubernetes manifest. See Readme for more info"
139+
}
140+
141+
variable "argo_application_values" {
142+
default = ""
143+
description = "Value overrides to use when deploying argo application object with helm"
144+
}
145+
136146
variable "argo_destionation_server" {
137147
type = string
138148
default = "https://kubernetes.default.svc"

0 commit comments

Comments
 (0)