Skip to content

Commit 7848535

Browse files
committed
feat: argocd rough draft
1 parent 1e577e6 commit 7848535

File tree

5 files changed

+317
-0
lines changed

5 files changed

+317
-0
lines changed

modules/argocd/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Requirements
2+
3+
No requirements.
4+
5+
## Providers
6+
7+
| Name | Version |
8+
|------|---------|
9+
| google | n/a |
10+
| helm | n/a |
11+
12+
## Inputs
13+
14+
| Name | Description | Type | Default | Required |
15+
|------|-------------|------|---------|:--------:|
16+
| apex\_domain | The apex domain to be allocated to the cluster | `string` | n/a | yes |
17+
| cluster\_id | A random generated to uniqly name cluster resources | `string` | n/a | yes |
18+
| cluster\_location | The location (region or zone) in which the cluster master will be created. If you specify a zone (such as us-central1-a), the cluster will be a zonal cluster with a single cluster master. If you specify a region (such as us-west1), the cluster will be a regional cluster with multiple masters spread across zones in the region | `string` | n/a | yes |
19+
| cluster\_name | Name of the Kubernetes cluster | `string` | n/a | yes |
20+
| gcp\_project | The name of the GCP project | `string` | n/a | yes |
21+
| jenkins\_x\_namespace | Kubernetes namespace to install Jenkins X in | `string` | n/a | yes |
22+
| cluster\_network | The name of the network (VPC) to which the cluster is connected | `string` | `"default"` | no |
23+
| cluster\_subnetwork | The name of the subnetwork to which the cluster is connected. Leave blank when using the 'default' vpc to generate a subnet for your cluster | `string` | `""` | no |
24+
| content | Interpolated jx-requirements.yml | `string` | `""` | no |
25+
| helm\_settings | Additional settings which will be passed to the Helm chart values, see https://artifacthub.io/packages/helm/argo/argo-cd | `map(any)` | `{}` | no |
26+
| jx\_bot\_token | Bot token used to interact with the Jenkins X cluster git repository | `string` | `""` | no |
27+
| jx\_bot\_username | Bot username used to interact with the Jenkins X cluster git repository | `string` | `""` | no |
28+
| jx\_git\_operator\_version | The jx-git-operator helm chart version | `string` | `"0.0.192"` | no |
29+
| jx\_git\_url | URL for the Jenins X cluster git repository | `string` | `""` | no |
30+
| kuberhealthy | Enable Kuberhealthy helm installation | `bool` | `true` | no |
31+
32+
## Outputs
33+
34+
| Name | Description |
35+
|------|-------------|
36+
| argocd\_sa\_email | n/a |
37+
| argocd\_sa\_name | n/a |
38+

modules/argocd/main.tf

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// ----------------------------------------------------------------------------
2+
// Create and configure the Argo CD installation
3+
//
4+
// ----------------------------------------------------------------------------
5+
locals {}
6+
7+
resource "helm_release" "bootstrap" {
8+
provider = helm
9+
name = "argocd"
10+
chart = "argo-cd"
11+
namespace = "argocd"
12+
repository = "https://argoproj.github.io/argo-helm"
13+
version = "5.6.1"
14+
create_namespace = true
15+
values = [
16+
jsonencode(
17+
{
18+
"controller" : {
19+
"serviceAccount" : {
20+
"annotations" : {
21+
"iam.gke.io/gcp-service-account" : "argocd-${var.cluster_name}@${var.gcp_project}.iam.gserviceaccount.com"
22+
}
23+
},
24+
},
25+
"repoServer" : {
26+
"autoscaling" : {
27+
"enabled" : true,
28+
"minReplicas" : 2
29+
},
30+
"initContainers" : [
31+
{
32+
"name" : "download-tools",
33+
"image" : "ghcr.io/helmfile/helmfile:v0.147.0",
34+
"command" : [
35+
"sh",
36+
"-c"
37+
],
38+
"args" : [
39+
"wget -qO /custom-tools/argo-cd-helmfile.sh https://raw.githubusercontent.com/travisghansen/argo-cd-helmfile/master/src/argo-cd-helmfile.sh && chmod +x /custom-tools/argo-cd-helmfile.sh && mv /usr/local/bin/helmfile /custom-tools/helmfile"
40+
],
41+
"volumeMounts" : [
42+
{
43+
"mountPath" : "/custom-tools",
44+
"name" : "custom-tools"
45+
}
46+
]
47+
}
48+
],
49+
"serviceAccount" : {
50+
"annotations" : {
51+
"iam.gke.io/gcp-service-account" : "argocd-${var.cluster_name}@${var.gcp_project}.iam.gserviceaccount.com"
52+
}
53+
},
54+
"volumes" : [
55+
{
56+
"name" : "custom-tools",
57+
"emptyDir" : {}
58+
}
59+
],
60+
"volumeMounts" : [
61+
{
62+
"mountPath" : "/usr/local/bin/argo-cd-helmfile.sh",
63+
"name" : "custom-tools",
64+
"subPath" : "argo-cd-helmfile.sh"
65+
},
66+
{
67+
"mountPath" : "/usr/local/bin/helmfile",
68+
"name" : "custom-tools",
69+
"subPath" : "helmfile"
70+
}
71+
]
72+
},
73+
"server" : {
74+
"autoscaling" : {
75+
"enabled" : true,
76+
"minReplicas" : 2
77+
}
78+
"ingress" : {
79+
"enabled" : true,
80+
"annotations" : {
81+
"nginx.ingress.kubernetes.io/backend-protocol" : "HTTPS",
82+
"nginx.ingress.kubernetes.io/force-ssl-redirect" : "true",
83+
"nginx.ingress.kubernetes.io/ssl-passthrough" : "true"
84+
},
85+
"hosts" : [
86+
"argocd.${var.apex_domain}"
87+
],
88+
"serviceAccount" : {
89+
"annotations" : {
90+
"iam.gke.io/gcp-service-account" : "argocd-${var.cluster_name}@${var.gcp_project}.iam.gserviceaccount.com"
91+
}
92+
}
93+
}
94+
}
95+
}
96+
)
97+
]
98+
99+
set {
100+
name = "server.config.configManagementPlugins"
101+
value = <<-EOT
102+
- name: helmfile
103+
init: # Optional command to initialize application source directory
104+
command: ["argo-cd-helmfile.sh"]
105+
args: ["init"]
106+
generate: # Command to generate manifests YAML
107+
command: ["argo-cd-helmfile.sh"]
108+
args: ["generate"]
109+
EOT
110+
}
111+
set {
112+
name = "configs.credentialTemplates.https-creds.url"
113+
value = regex("\\w+://\\w+\\.\\w+", var.jx_git_url)
114+
}
115+
set_sensitive {
116+
name = "configs.credentialTemplates.https-creds.username"
117+
value = var.jx_bot_username
118+
}
119+
set_sensitive {
120+
name = "configs.credentialTemplates.https-creds.password"
121+
value = var.jx_bot_token
122+
}
123+
124+
dynamic "set" {
125+
for_each = var.helm_values
126+
content {
127+
name = set.key
128+
value = set.value
129+
}
130+
}
131+
132+
lifecycle {
133+
# ignore_changes = all
134+
}
135+
}

modules/argocd/outputs.tf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "argocd_sa_email" {
2+
value = google_service_account.argocd_sa.email
3+
}
4+
5+
output "argocd_sa_name" {
6+
value = google_service_account.argocd_sa.name
7+
}

modules/argocd/serviceaccount.tf

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ----------------------------------------------------------------------------
2+
// Setup GCloud Service Accounts
3+
//
4+
// https://www.terraform.io/docs/providers/google/r/google_service_account.html
5+
// https://www.terraform.io/docs/providers/google/r/google_project_iam.html#google_project_iam_member
6+
// ----------------------------------------------------------------------------
7+
// argocd
8+
resource "google_service_account" "argocd_sa" {
9+
provider = google
10+
account_id = "argocd-${var.cluster_name}"
11+
display_name = substr("ArgoCD service account for cluster ${var.cluster_name}", 0, 100)
12+
}
13+
14+
resource "google_project_iam_member" "argocd_sa_secret_manager_admin_binding" {
15+
project = var.gcp_project
16+
provider = google
17+
role = "roles/secretmanager.admin"
18+
member = "serviceAccount:${google_service_account.argocd_sa.email}"
19+
}
20+
21+
resource "google_project_iam_member" "argocd_sa_container_developer_binding" {
22+
project = var.gcp_project
23+
provider = google
24+
role = "roles/container.developer"
25+
member = "serviceAccount:${google_service_account.argocd_sa.email}"
26+
}
27+
28+
resource "google_service_account_iam_member" "argocd_app_controller_sa_workload_identity_user" {
29+
provider = google
30+
service_account_id = google_service_account.argocd_sa.name
31+
role = "roles/iam.workloadIdentityUser"
32+
member = "serviceAccount:${var.gcp_project}.svc.id.goog[argocd/argocd-application-controller]"
33+
}
34+
35+
resource "google_service_account_iam_member" "argocd_repo_server_sa_workload_identity_user" {
36+
provider = google
37+
service_account_id = google_service_account.argocd_sa.name
38+
role = "roles/iam.workloadIdentityUser"
39+
member = "serviceAccount:${var.gcp_project}.svc.id.goog[argocd/argocd-repo-server]"
40+
}
41+
42+
resource "google_service_account_iam_member" "argocd_server_sa_workload_identity_user" {
43+
provider = google
44+
service_account_id = google_service_account.argocd_sa.name
45+
role = "roles/iam.workloadIdentityUser"
46+
member = "serviceAccount:${var.gcp_project}.svc.id.goog[argocd/argocd-server]"
47+
}

modules/argocd/variables.tf

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// ----------------------------------------------------------------------------
2+
// Required Variables
3+
// ----------------------------------------------------------------------------
4+
variable "gcp_project" {
5+
description = "The name of the GCP project"
6+
type = string
7+
}
8+
9+
variable "cluster_location" {
10+
description = "The location (region or zone) in which the cluster master will be created. If you specify a zone (such as us-central1-a), the cluster will be a zonal cluster with a single cluster master. If you specify a region (such as us-west1), the cluster will be a regional cluster with multiple masters spread across zones in the region"
11+
type = string
12+
}
13+
14+
variable "cluster_network" {
15+
description = "The name of the network (VPC) to which the cluster is connected"
16+
type = string
17+
default = "default"
18+
}
19+
20+
variable "cluster_subnetwork" {
21+
description = "The name of the subnetwork to which the cluster is connected. Leave blank when using the 'default' vpc to generate a subnet for your cluster"
22+
type = string
23+
default = ""
24+
}
25+
26+
variable "cluster_name" {
27+
description = "Name of the Kubernetes cluster"
28+
type = string
29+
}
30+
31+
variable "apex_domain" {
32+
description = "The apex domain to be allocated to the cluster"
33+
type = string
34+
}
35+
36+
variable "jenkins_x_namespace" {
37+
description = "Kubernetes namespace to install Jenkins X in"
38+
type = string
39+
}
40+
41+
variable "cluster_id" {
42+
description = "A random generated to uniqly name cluster resources"
43+
type = string
44+
}
45+
46+
// ----------------------------------------------------------------------------
47+
// Optional Variables
48+
// ----------------------------------------------------------------------------
49+
50+
variable "jx_git_url" {
51+
description = "URL for the Jenins X cluster git repository"
52+
type = string
53+
default = ""
54+
}
55+
56+
variable "jx_bot_username" {
57+
description = "Bot username used to interact with the Jenkins X cluster git repository"
58+
type = string
59+
default = ""
60+
}
61+
62+
variable "jx_bot_token" {
63+
description = "Bot token used to interact with the Jenkins X cluster git repository"
64+
type = string
65+
default = ""
66+
}
67+
68+
variable "jx_git_operator_version" {
69+
description = "The jx-git-operator helm chart version"
70+
type = string
71+
default = "0.0.192"
72+
}
73+
74+
variable "kuberhealthy" {
75+
description = "Enable Kuberhealthy helm installation"
76+
type = bool
77+
default = true
78+
}
79+
80+
variable "content" {
81+
description = "Interpolated jx-requirements.yml"
82+
type = string
83+
default = ""
84+
}
85+
86+
variable "helm_values" {
87+
type = map(any)
88+
description = "Additional settings which will be passed to the Helm chart values, see https://artifacthub.io/packages/helm/argo/argo-cd"
89+
default = {}
90+
}

0 commit comments

Comments
 (0)