|
9 | 9 | - [Terraform](https://www.terraform.io/downloads.html) 0.12.x |
10 | 10 | - [Go](https://golang.org/doc/install) 1.14+ |
11 | 11 |
|
| 12 | +--- |
| 13 | + |
| 14 | +## Motivations |
| 15 | + |
| 16 | +### *I thought ArgoCD already allowed for 100% declarative configuration?* |
| 17 | + |
| 18 | +While that is true through the use of ArgoCD Kubernetes Custom Resources, |
| 19 | +there are some resources that simply cannot be managed using Kubernetes manifests, |
| 20 | +such as project roles JWTs whose respective lifecycles are better handled by a tool like Terraform. |
| 21 | +Even more so when you need to export these JWTs to another external system using Terraform, like a CI platform. |
| 22 | + |
| 23 | +### *Wouldn't using a Kubernetes provider to handle ArgoCD configuration be enough?* |
| 24 | + |
| 25 | +Existing Kubernetes providers do not patch arrays of objects, losing project role JWTs when doing small project changes just happen. |
| 26 | + |
| 27 | +ArgoCD Kubernetes admission webhook controller is not as exhaustive as ArgoCD API validation, this can be seen with RBAC policies, where no validation occur when creating/patching a project. |
| 28 | + |
| 29 | +Using Terraform to manage Kubernetes Custom Resource becomes increasingly difficult |
| 30 | +the further you use HCL2 DSL to merge different data structures *and* want to preserve type safety. |
| 31 | + |
| 32 | +Whatever the Kubernetes CRD provider you are using, you will probably end up using `locals` and the `yamlencode` function **which does not preserve the values' type**. |
| 33 | +In these cases, not only the readability of your Terraform plan will worsen, but you will also be losing some safeties that Terraform provides in the process. |
| 34 | + |
| 35 | +--- |
| 36 | + |
12 | 37 | ## Building |
13 | 38 |
|
14 | 39 | Clone the repository within your `GOPATH` |
@@ -36,11 +61,72 @@ provider "argocd" { |
36 | 61 | insecure = false # env ARGOCD_INSECURE |
37 | 62 | } |
38 | 63 |
|
| 64 | +resource "argocd_project" "myproject" { |
| 65 | + metadata { |
| 66 | + name = "myproject" |
| 67 | + namespace = "argocd" |
| 68 | + labels = { |
| 69 | + acceptance = "true" |
| 70 | + } |
| 71 | + annotations = { |
| 72 | + "this.is.a.really.long.nested.key" = "yes, really!" |
| 73 | + } |
| 74 | + } |
| 75 | +
|
| 76 | + spec { |
| 77 | + description = "simple project" |
| 78 | + source_repos = ["*"] |
| 79 | +
|
| 80 | + destination { |
| 81 | + server = "https://kubernetes.default.svc" |
| 82 | + namespace = "default" |
| 83 | + } |
| 84 | + destination { |
| 85 | + server = "https://kubernetes.default.svc" |
| 86 | + namespace = "foo" |
| 87 | + } |
| 88 | + cluster_resource_whitelist { |
| 89 | + group = "rbac.authorization.k8s.io" |
| 90 | + kind = "ClusterRoleBinding" |
| 91 | + } |
| 92 | + cluster_resource_whitelist { |
| 93 | + group = "rbac.authorization.k8s.io" |
| 94 | + kind = "ClusterRole" |
| 95 | + } |
| 96 | + namespace_resource_blacklist { |
| 97 | + group = "networking.k8s.io" |
| 98 | + kind = "Ingress" |
| 99 | + } |
| 100 | + orphaned_resources = { |
| 101 | + warn = true |
| 102 | + } |
| 103 | + sync_window { |
| 104 | + kind = "allow" |
| 105 | + applications = ["api-*"] |
| 106 | + clusters = ["*"] |
| 107 | + namespaces = ["*"] |
| 108 | + duration = "3600s" |
| 109 | + schedule = "10 1 * * *" |
| 110 | + manual_sync = true |
| 111 | + } |
| 112 | + sync_window { |
| 113 | + kind = "deny" |
| 114 | + applications = ["foo"] |
| 115 | + clusters = ["in-cluster"] |
| 116 | + namespaces = ["default"] |
| 117 | + duration = "12h" |
| 118 | + schedule = "22 1 5 * *" |
| 119 | + manual_sync = false |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | +
|
39 | 124 | resource "argocd_project_token" "secret" { |
40 | | - project = "myproject" |
41 | | - role = "bar" |
| 125 | + count = 20 |
| 126 | + project = argocd_project.myproject.metadata.0.name |
| 127 | + role = "foobar" |
42 | 128 | description = "short lived token" |
43 | | - expires_in = "3600" |
| 129 | + expires_in = 3600 |
44 | 130 | } |
45 | 131 | ``` |
46 | 132 |
|
|
0 commit comments