Skip to content

Commit bbff05e

Browse files
authored
Add support for NamespaceResourceWhitelist and clusterResourceBlacklist (argoproj-labs#91)
contributed by @kcirrr
1 parent 61c8231 commit bbff05e

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ resource "argocd_project" "myproject" {
140140
server = "https://kubernetes.default.svc"
141141
namespace = "foo"
142142
}
143+
cluster_resource_blacklist {
144+
group = "*"
145+
kind = "*"
146+
}
143147
cluster_resource_whitelist {
144148
group = "rbac.authorization.k8s.io"
145149
kind = "ClusterRoleBinding"
@@ -152,6 +156,10 @@ resource "argocd_project" "myproject" {
152156
group = "networking.k8s.io"
153157
kind = "Ingress"
154158
}
159+
namespace_resource_whitelist {
160+
group = "*"
161+
kind = "*"
162+
}
155163
orphaned_resources {
156164
warn = true
157165

argocd/resource_argocd_project_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,18 @@ resource "argocd_project" "simple" {
147147
group = "rbac.authorization.k8s.io"
148148
kind = "ClusterRole"
149149
}
150+
cluster_resource_blacklist {
151+
group = "*"
152+
kind = "*"
153+
}
150154
namespace_resource_blacklist {
151155
group = "networking.k8s.io"
152156
kind = "Ingress"
153157
}
158+
namespace_resource_whitelist {
159+
group = "*"
160+
kind = "*"
161+
}
154162
orphaned_resources {
155163
warn = true
156164
ignore {

argocd/schema_project.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ func projectSpecSchemaV0() *schema.Schema {
1515
Required: true,
1616
Elem: &schema.Resource{
1717
Schema: map[string]*schema.Schema{
18+
"cluster_resource_blacklist": {
19+
Type: schema.TypeSet,
20+
Optional: true,
21+
Elem: &schema.Resource{
22+
Schema: map[string]*schema.Schema{
23+
"group": {
24+
Type: schema.TypeString,
25+
ValidateFunc: validateGroupName,
26+
Optional: true,
27+
},
28+
"kind": {
29+
Type: schema.TypeString,
30+
Optional: true,
31+
},
32+
},
33+
},
34+
},
1835
"cluster_resource_whitelist": {
1936
Type: schema.TypeSet,
2037
Optional: true,
@@ -73,6 +90,22 @@ func projectSpecSchemaV0() *schema.Schema {
7390
},
7491
},
7592
},
93+
"namespace_resource_whitelist": {
94+
Type: schema.TypeSet,
95+
Optional: true,
96+
Elem: &schema.Resource{
97+
Schema: map[string]*schema.Schema{
98+
"group": {
99+
Type: schema.TypeString,
100+
Optional: true,
101+
},
102+
"kind": {
103+
Type: schema.TypeString,
104+
Optional: true,
105+
},
106+
},
107+
},
108+
},
76109
"orphaned_resources": {
77110
Type: schema.TypeMap,
78111
Optional: true,
@@ -166,6 +199,23 @@ func projectSpecSchemaV1() *schema.Schema {
166199
Required: true,
167200
Elem: &schema.Resource{
168201
Schema: map[string]*schema.Schema{
202+
"cluster_resource_blacklist": {
203+
Type: schema.TypeSet,
204+
Optional: true,
205+
Elem: &schema.Resource{
206+
Schema: map[string]*schema.Schema{
207+
"group": {
208+
Type: schema.TypeString,
209+
ValidateFunc: validateGroupName,
210+
Optional: true,
211+
},
212+
"kind": {
213+
Type: schema.TypeString,
214+
Optional: true,
215+
},
216+
},
217+
},
218+
},
169219
"cluster_resource_whitelist": {
170220
Type: schema.TypeSet,
171221
Optional: true,
@@ -224,6 +274,22 @@ func projectSpecSchemaV1() *schema.Schema {
224274
},
225275
},
226276
},
277+
"namespace_resource_whitelist": {
278+
Type: schema.TypeSet,
279+
Optional: true,
280+
Elem: &schema.Resource{
281+
Schema: map[string]*schema.Schema{
282+
"group": {
283+
Type: schema.TypeString,
284+
Optional: true,
285+
},
286+
"kind": {
287+
Type: schema.TypeString,
288+
Optional: true,
289+
},
290+
},
291+
},
292+
},
227293
"orphaned_resources": {
228294
Type: schema.TypeSet,
229295
Optional: true,
@@ -351,6 +417,23 @@ func projectSpecSchemaV2() *schema.Schema {
351417
Required: true,
352418
Elem: &schema.Resource{
353419
Schema: map[string]*schema.Schema{
420+
"cluster_resource_blacklist": {
421+
Type: schema.TypeSet,
422+
Optional: true,
423+
Elem: &schema.Resource{
424+
Schema: map[string]*schema.Schema{
425+
"group": {
426+
Type: schema.TypeString,
427+
ValidateFunc: validateGroupName,
428+
Optional: true,
429+
},
430+
"kind": {
431+
Type: schema.TypeString,
432+
Optional: true,
433+
},
434+
},
435+
},
436+
},
354437
"cluster_resource_whitelist": {
355438
Type: schema.TypeSet,
356439
Optional: true,
@@ -409,6 +492,22 @@ func projectSpecSchemaV2() *schema.Schema {
409492
},
410493
},
411494
},
495+
"namespace_resource_whitelist": {
496+
Type: schema.TypeSet,
497+
Optional: true,
498+
Elem: &schema.Resource{
499+
Schema: map[string]*schema.Schema{
500+
"group": {
501+
Type: schema.TypeString,
502+
Optional: true,
503+
},
504+
"kind": {
505+
Type: schema.TypeString,
506+
Optional: true,
507+
},
508+
},
509+
},
510+
},
412511
"orphaned_resources": {
413512
Type: schema.TypeList,
414513
Optional: true,

argocd/schema_project_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ func TestResourceArgoCDProjectStateUpgradeV0(t *testing.T) {
6868
sourceState: map[string]interface{}{
6969
"spec": []interface{}{
7070
map[string]interface{}{
71+
"cluster_resource_blacklist": []map[string]string{},
7172
"cluster_resource_whitelist": []map[string]string{},
7273
"description": "test",
7374
"destination": map[string]string{
7475
"namespace": "*",
7576
"server": "https://testing.io",
7677
},
7778
"namespace_resource_blacklist": []map[string]string{},
79+
"namespace_resource_whitelist": []map[string]string{},
7880
"orphaned_resources": map[string]bool{"warn": true},
7981
"role": []map[string]interface{}{},
8082
"source_repos": []string{"[email protected]:testing/test.git"},
@@ -85,13 +87,15 @@ func TestResourceArgoCDProjectStateUpgradeV0(t *testing.T) {
8587
expectedState: map[string]interface{}{
8688
"spec": []interface{}{
8789
map[string]interface{}{
90+
"cluster_resource_blacklist": []map[string]string{},
8891
"cluster_resource_whitelist": []map[string]string{},
8992
"description": "test",
9093
"destination": map[string]string{
9194
"namespace": "*",
9295
"server": "https://testing.io",
9396
},
9497
"namespace_resource_blacklist": []map[string]string{},
98+
"namespace_resource_whitelist": []map[string]string{},
9599
"orphaned_resources": []interface{}{map[string]bool{"warn": true}},
96100
"role": []map[string]interface{}{},
97101
"source_repos": []string{"[email protected]:testing/test.git"},

argocd/structure_project.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,18 @@ func expandProjectSpec(d *schema.ResourceData) (
7676
}
7777
}
7878
}
79+
if v, ok := s["cluster_resource_blacklist"]; ok {
80+
spec.ClusterResourceBlacklist = expandK8SGroupKind(v.(*schema.Set))
81+
}
7982
if v, ok := s["cluster_resource_whitelist"]; ok {
8083
spec.ClusterResourceWhitelist = expandK8SGroupKind(v.(*schema.Set))
8184
}
8285
if v, ok := s["namespace_resource_blacklist"]; ok {
8386
spec.NamespaceResourceBlacklist = expandK8SGroupKind(v.(*schema.Set))
8487
}
88+
if v, ok := s["namespace_resource_whitelist"]; ok {
89+
spec.NamespaceResourceWhitelist = expandK8SGroupKind(v.(*schema.Set))
90+
}
8591
if v, ok := s["destination"]; ok {
8692
spec.Destinations = expandApplicationDestinations(v.(*schema.Set))
8793
}
@@ -136,8 +142,10 @@ func flattenProject(p *application.AppProject, d *schema.ResourceData) error {
136142

137143
func flattenProjectSpec(s application.AppProjectSpec) []map[string]interface{} {
138144
spec := map[string]interface{}{
145+
"cluster_resource_blacklist": flattenK8SGroupKinds(s.ClusterResourceBlacklist),
139146
"cluster_resource_whitelist": flattenK8SGroupKinds(s.ClusterResourceWhitelist),
140147
"namespace_resource_blacklist": flattenK8SGroupKinds(s.NamespaceResourceBlacklist),
148+
"namespace_resource_whitelist": flattenK8SGroupKinds(s.NamespaceResourceWhitelist),
141149
"destination": flattenApplicationDestinations(s.Destinations),
142150
"orphaned_resources": flattenProjectOrphanedResources(s.OrphanedResources),
143151
"role": flattenProjectRoles(s.Roles),

docs/resources/project.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ resource "argocd_project" "myproject" {
3333
name = "anothercluster"
3434
namespace = "bar"
3535
}
36+
cluster_resource_blacklist {
37+
group = "*"
38+
kind = "*"
39+
}
3640
cluster_resource_whitelist {
3741
group = "rbac.authorization.k8s.io"
3842
kind = "ClusterRoleBinding"
@@ -45,6 +49,10 @@ resource "argocd_project" "myproject" {
4549
group = "networking.k8s.io"
4650
kind = "Ingress"
4751
}
52+
namespace_resource_whitelist {
53+
group = "*"
54+
kind = "*"
55+
}
4856
orphaned_resources {
4957
warn = true
5058

manifests/local-dev/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ resource "argocd_project" "foo" {
5151
group = "networking.k8s.io"
5252
kind = "Ingress"
5353
}
54+
namespace_resource_whitelist {
55+
group = "*"
56+
kind = "*"
57+
}
5458
orphaned_resources {
5559
warn = true
5660
}

0 commit comments

Comments
 (0)