Skip to content

Commit

Permalink
Merge pull request #4 from goci-io/chore
Browse files Browse the repository at this point in the history
allow to disable rbac role and service account
  • Loading branch information
etwillbefine authored Dec 31, 2019
2 parents e7f7b80 + 610b5aa commit 0d345f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion provider.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_version = ">= 0.12.1"

required_providers = {
required_providers {
kubernetes = "~> 1.8"
}
}
12 changes: 8 additions & 4 deletions rbac.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
resource "kubernetes_role" "deployment" {
count = var.enabled_rbac_binding ? 1 : 0

metadata {
name = module.label.id

Expand Down Expand Up @@ -28,21 +30,23 @@ resource "kubernetes_role" "deployment" {
}
}

resource "kubernetes_role_binding" "example" {
resource "kubernetes_role_binding" "sa_binding" {
count = var.enabled_rbac_binding ? 1 : 0

metadata {
name = module.label.id
name = "apps-sa-binding"
namespace = kubernetes_namespace.namespace.metadata.0.name
}

role_ref {
name = kubernetes_role.deployment.metadata.0.name
name = kubernetes_role.deployment[0].metadata.0.name
api_group = "rbac.authorization.k8s.io"
kind = "Role"
}

subject {
kind = "ServiceAccount"
name = "${module.label.id}-apps"
name = kubernetes_service_account.namespace[0].metadata.0.name
namespace = kubernetes_namespace.namespace.metadata.0.name
}
}
7 changes: 5 additions & 2 deletions service-account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ locals {
}

resource "kubernetes_service_account" "namespace" {
count = var.enabled_rbac_binding ? 1 : 0

metadata {
name = "${module.label.id}-apps"
namespace = module.label.id
namespace = kubernetes_namespace.namespace.metadata.0.name
}

dynamic "image_pull_secret" {
for_each = var.image_pull_secrets

content {
name = image_pull_secret.key
}
Expand All @@ -23,7 +26,7 @@ resource "kubernetes_secret" "image_pull" {

metadata {
name = element(local.pull_secret_keys, count.index)
namespace = module.label.id
namespace = kubernetes_namespace.namespace.metadata.0.name
}

data = {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ variable "image_pull_secrets" {
description = "Pull secrets to provide to the service account to fetch docker images"
}

variable "enabled_rbac_binding" {
type = bool
default = true
description = "Deploys additional RBAC role binding to a service account named like the namespace (+-apps)"
}

variable "max_pv_claims" {
default = 30
description = "Maximum amount of PersistentVolumeClaims which can be claimed within this namespace"
Expand Down

0 comments on commit 0d345f8

Please sign in to comment.