Skip to content

Commit

Permalink
Add support for NamespaceResourceWhitelist and clusterResourceBlackli…
Browse files Browse the repository at this point in the history
…st (#91)

contributed by @kcirrr
  • Loading branch information
kcirrr authored Aug 11, 2021
1 parent 61c8231 commit bbff05e
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ resource "argocd_project" "myproject" {
server = "https://kubernetes.default.svc"
namespace = "foo"
}
cluster_resource_blacklist {
group = "*"
kind = "*"
}
cluster_resource_whitelist {
group = "rbac.authorization.k8s.io"
kind = "ClusterRoleBinding"
Expand All @@ -152,6 +156,10 @@ resource "argocd_project" "myproject" {
group = "networking.k8s.io"
kind = "Ingress"
}
namespace_resource_whitelist {
group = "*"
kind = "*"
}
orphaned_resources {
warn = true
Expand Down
8 changes: 8 additions & 0 deletions argocd/resource_argocd_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ resource "argocd_project" "simple" {
group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
}
cluster_resource_blacklist {
group = "*"
kind = "*"
}
namespace_resource_blacklist {
group = "networking.k8s.io"
kind = "Ingress"
}
namespace_resource_whitelist {
group = "*"
kind = "*"
}
orphaned_resources {
warn = true
ignore {
Expand Down
99 changes: 99 additions & 0 deletions argocd/schema_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ func projectSpecSchemaV0() *schema.Schema {
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_resource_blacklist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
ValidateFunc: validateGroupName,
Optional: true,
},
"kind": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"cluster_resource_whitelist": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -73,6 +90,22 @@ func projectSpecSchemaV0() *schema.Schema {
},
},
},
"namespace_resource_whitelist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
Optional: true,
},
"kind": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"orphaned_resources": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -166,6 +199,23 @@ func projectSpecSchemaV1() *schema.Schema {
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_resource_blacklist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
ValidateFunc: validateGroupName,
Optional: true,
},
"kind": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"cluster_resource_whitelist": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -224,6 +274,22 @@ func projectSpecSchemaV1() *schema.Schema {
},
},
},
"namespace_resource_whitelist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
Optional: true,
},
"kind": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"orphaned_resources": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -351,6 +417,23 @@ func projectSpecSchemaV2() *schema.Schema {
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_resource_blacklist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
ValidateFunc: validateGroupName,
Optional: true,
},
"kind": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"cluster_resource_whitelist": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -409,6 +492,22 @@ func projectSpecSchemaV2() *schema.Schema {
},
},
},
"namespace_resource_whitelist": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group": {
Type: schema.TypeString,
Optional: true,
},
"kind": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"orphaned_resources": {
Type: schema.TypeList,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions argocd/schema_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ func TestResourceArgoCDProjectStateUpgradeV0(t *testing.T) {
sourceState: map[string]interface{}{
"spec": []interface{}{
map[string]interface{}{
"cluster_resource_blacklist": []map[string]string{},
"cluster_resource_whitelist": []map[string]string{},
"description": "test",
"destination": map[string]string{
"namespace": "*",
"server": "https://testing.io",
},
"namespace_resource_blacklist": []map[string]string{},
"namespace_resource_whitelist": []map[string]string{},
"orphaned_resources": map[string]bool{"warn": true},
"role": []map[string]interface{}{},
"source_repos": []string{"[email protected]:testing/test.git"},
Expand All @@ -85,13 +87,15 @@ func TestResourceArgoCDProjectStateUpgradeV0(t *testing.T) {
expectedState: map[string]interface{}{
"spec": []interface{}{
map[string]interface{}{
"cluster_resource_blacklist": []map[string]string{},
"cluster_resource_whitelist": []map[string]string{},
"description": "test",
"destination": map[string]string{
"namespace": "*",
"server": "https://testing.io",
},
"namespace_resource_blacklist": []map[string]string{},
"namespace_resource_whitelist": []map[string]string{},
"orphaned_resources": []interface{}{map[string]bool{"warn": true}},
"role": []map[string]interface{}{},
"source_repos": []string{"[email protected]:testing/test.git"},
Expand Down
8 changes: 8 additions & 0 deletions argocd/structure_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ func expandProjectSpec(d *schema.ResourceData) (
}
}
}
if v, ok := s["cluster_resource_blacklist"]; ok {
spec.ClusterResourceBlacklist = expandK8SGroupKind(v.(*schema.Set))
}
if v, ok := s["cluster_resource_whitelist"]; ok {
spec.ClusterResourceWhitelist = expandK8SGroupKind(v.(*schema.Set))
}
if v, ok := s["namespace_resource_blacklist"]; ok {
spec.NamespaceResourceBlacklist = expandK8SGroupKind(v.(*schema.Set))
}
if v, ok := s["namespace_resource_whitelist"]; ok {
spec.NamespaceResourceWhitelist = expandK8SGroupKind(v.(*schema.Set))
}
if v, ok := s["destination"]; ok {
spec.Destinations = expandApplicationDestinations(v.(*schema.Set))
}
Expand Down Expand Up @@ -136,8 +142,10 @@ func flattenProject(p *application.AppProject, d *schema.ResourceData) error {

func flattenProjectSpec(s application.AppProjectSpec) []map[string]interface{} {
spec := map[string]interface{}{
"cluster_resource_blacklist": flattenK8SGroupKinds(s.ClusterResourceBlacklist),
"cluster_resource_whitelist": flattenK8SGroupKinds(s.ClusterResourceWhitelist),
"namespace_resource_blacklist": flattenK8SGroupKinds(s.NamespaceResourceBlacklist),
"namespace_resource_whitelist": flattenK8SGroupKinds(s.NamespaceResourceWhitelist),
"destination": flattenApplicationDestinations(s.Destinations),
"orphaned_resources": flattenProjectOrphanedResources(s.OrphanedResources),
"role": flattenProjectRoles(s.Roles),
Expand Down
8 changes: 8 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ resource "argocd_project" "myproject" {
name = "anothercluster"
namespace = "bar"
}
cluster_resource_blacklist {
group = "*"
kind = "*"
}
cluster_resource_whitelist {
group = "rbac.authorization.k8s.io"
kind = "ClusterRoleBinding"
Expand All @@ -45,6 +49,10 @@ resource "argocd_project" "myproject" {
group = "networking.k8s.io"
kind = "Ingress"
}
namespace_resource_whitelist {
group = "*"
kind = "*"
}
orphaned_resources {
warn = true
Expand Down
4 changes: 4 additions & 0 deletions manifests/local-dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ resource "argocd_project" "foo" {
group = "networking.k8s.io"
kind = "Ingress"
}
namespace_resource_whitelist {
group = "*"
kind = "*"
}
orphaned_resources {
warn = true
}
Expand Down

0 comments on commit bbff05e

Please sign in to comment.