Skip to content

Commit

Permalink
Gatekeeper Deployment (#358)
Browse files Browse the repository at this point in the history
Added Gatekeeper Deployment MP and CP Cluster
  • Loading branch information
ajaymare authored Mar 7, 2024
1 parent a588ce6 commit e62101e
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 2 deletions.
36 changes: 36 additions & 0 deletions modules/addons/gatekeeper/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
provider "helm" {
kubernetes {
host = var.k8s_host
cluster_ca_certificate = base64decode(var.k8s_cluster_ca_certificate)
token = var.k8s_client_token
}
}

provider "kubectl" {
host = var.k8s_host
cluster_ca_certificate = base64decode(var.k8s_cluster_ca_certificate)
token = var.k8s_client_token
load_config_file = false
}

provider "kubernetes" {
host = var.k8s_host
cluster_ca_certificate = base64decode(var.k8s_cluster_ca_certificate)
token = var.k8s_client_token
}

# Gatekeeper Deployment using helm chart
resource "helm_release" "gatekeeper" {
count = var.gatekeeper_enabled == true ? 1 : 0
name = "gatekeeper"
repository = "https://open-policy-agent.github.io/gatekeeper/charts"
chart = "gatekeeper"
version = var.gatekeeper_version
create_namespace = true
namespace = "gatekeeper-system"
timeout = 240

values = [
file("${path.module}/manifests/gatekeeper-values.yaml")
]
}
1 change: 1 addition & 0 deletions modules/addons/gatekeeper/manifests/gatekeeper-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
replicas: 1
8 changes: 8 additions & 0 deletions modules/addons/gatekeeper/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
kubectl = {
source = "alekc/kubectl"
version = "2.0.3"
}
}
}
18 changes: 18 additions & 0 deletions modules/addons/gatekeeper/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "cluster_name" {
}

variable "k8s_host" {
}

variable "k8s_cluster_ca_certificate" {
}

variable "k8s_client_token" {
}

variable "gatekeeper_enabled" {
}

variable "gatekeeper_version" {
default = "3.15.0"
}
1 change: 1 addition & 0 deletions modules/tsb/mp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ data "kubernetes_service" "tsb" {
}
depends_on = [time_sleep.wait_240_seconds]
}

1 change: 0 additions & 1 deletion modules/tsb/mp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ variable "es_cacert" {




9 changes: 9 additions & 0 deletions terraform-advanced.tfvars.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"tsb-monitoring": {
"enabled": true
},
"gatekeeper": {
"enabled" : true
}
}
}
Expand All @@ -41,6 +44,9 @@
},
"tsb-monitoring": {
"enabled": true
},
"gatekeeper": {
"enabled" : true
}
}
}
Expand All @@ -63,6 +69,9 @@
},
"tsb-monitoring": {
"enabled": true
},
"gatekeeper": {
"enabled" : true
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions terraform-basic.tfvars.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"addons": {
"argocd": {
"enabled": true
},
"gatekeeper": {
"enabled" : true
}
}
}
Expand All @@ -22,6 +25,9 @@
"addons": {
"argocd": {
"enabled": true
},
"gatekeeper": {
"enabled": true
}
}
}
Expand All @@ -35,6 +41,9 @@
"addons": {
"argocd": {
"enabled": true
},
"gatekeeper": {
"enabled": true
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions tsb/cp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ module "ratelimit" {
enabled = var.ratelimit_enabled
}

module "gatekeeper" {
source = "../../modules/addons/gatekeeper"
cluster_name = data.terraform_remote_state.infra.outputs.cluster_name
k8s_host = data.terraform_remote_state.infra.outputs.host
k8s_cluster_ca_certificate = data.terraform_remote_state.infra.outputs.cluster_ca_certificate
k8s_client_token = data.terraform_remote_state.k8s_auth.outputs.token
gatekeeper_enabled = local.cluster.tetrate.management_plane ? false : local.cluster.addons.gatekeeper
}

module "tsb_cp" {
source = "../../modules/tsb/cp"
cloud = local.cluster.cloud
Expand Down
12 changes: 12 additions & 0 deletions tsb/cp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ variable "cluster" {
control_plane = optional(bool)
management_plane = optional(bool)
})
addons = object({
gatekeeper = object({
enabled = optional(bool)
})
})
version = optional(string)
workspace = string
})
Expand All @@ -21,6 +26,9 @@ locals {
management_plane = false
}
version = "1.27"
addons = {
gatekeeper = false
}
}
cluster = {
cloud = var.cluster.cloud
Expand All @@ -33,6 +41,10 @@ locals {
}
version = coalesce(var.cluster.version, local.cluster_defaults.version)
workspace = var.cluster.workspace
addons = {
gatekeeper = coalesce(var.cluster.addons.gatekeeper.enabled,local.cluster_defaults.addons.gatekeeper)
}

}
}

Expand Down
11 changes: 10 additions & 1 deletion tsb/mp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ module "es" {
es_version = local.tetrate.es_version
}

module "gatekeeper" {
source = "../../modules/addons/gatekeeper"
cluster_name = data.terraform_remote_state.infra.outputs.cluster_name
k8s_host = data.terraform_remote_state.infra.outputs.host
k8s_cluster_ca_certificate = data.terraform_remote_state.infra.outputs.cluster_ca_certificate
k8s_client_token = data.terraform_remote_state.k8s_auth.outputs.token
gatekeeper_enabled = local.cluster.addons.gatekeeper
}

module "tsb_mp" {
source = "../../modules/tsb/mp"
name_prefix = var.name_prefix
Expand All @@ -53,4 +62,4 @@ module "tsb_mp" {
k8s_host = data.terraform_remote_state.infra.outputs.host
k8s_cluster_ca_certificate = data.terraform_remote_state.infra.outputs.cluster_ca_certificate
k8s_client_token = data.terraform_remote_state.k8s_auth.outputs.token
}
}
12 changes: 12 additions & 0 deletions tsb/mp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ variable "cluster" {
control_plane = optional(bool)
management_plane = optional(bool)
})
addons = object({
gatekeeper = object({
enabled = optional(bool)
})
})
version = optional(string)
workspace = string
})
Expand All @@ -21,6 +26,9 @@ locals {
management_plane = false
}
version = "1.27"
addons = {
gatekeeper = false
}
}
cluster = {
cloud = var.cluster.cloud
Expand All @@ -33,6 +41,10 @@ locals {
}
version = coalesce(var.cluster.version, local.cluster_defaults.version)
workspace = var.cluster.workspace
addons = {
gatekeeper = coalesce(var.cluster.addons.gatekeeper.enabled,local.cluster_defaults.addons.gatekeeper)
}

}
}

Expand Down

0 comments on commit e62101e

Please sign in to comment.