Skip to content

Commit

Permalink
Merge pull request #29 from DNXLabs/fix/rbac-binding
Browse files Browse the repository at this point in the history
split role and role binding into different files due to limitation on kubectl_manifest applying two resources in the same yaml
  • Loading branch information
jeremiasroma authored Sep 21, 2022
2 parents 51ff864 + beb58c4 commit 2b1fcf0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
12 changes: 12 additions & 0 deletions role.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ resource "kubectl_manifest" "cluster_role" {
resourcenames = "${each.value.secrets}"
})
}

resource "kubectl_manifest" "cluster_role_binding" {
for_each = { for role in try(var.roles, []) : role.name => role }
yaml_body = templatefile("${path.module}/role_binding.tpl.yaml", {
name = "${each.value.name}"
namespace = "${each.value.namespace}"
resourcenames = "${each.value.secrets}"
})
depends_on = [
kubectl_manifest.cluster_role
]
}
17 changes: 1 addition & 16 deletions role.tpl.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand All @@ -16,18 +15,4 @@ rules:
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ${name}
namespace: ${namespace}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ${name}
subjects:
- kind: ServiceAccount
name: aws-alb-ingress-controller
namespace: kube-system
- watch
13 changes: 13 additions & 0 deletions role_binding.tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ${name}
namespace: ${namespace}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ${name}
subjects:
- kind: ServiceAccount
name: aws-alb-ingress-controller
namespace: kube-system

0 comments on commit 2b1fcf0

Please sign in to comment.