-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add terraform module #1049
Closed
Closed
add terraform module #1049
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4230f65
add terraform module
wasaga 92a0d9f
expose databroker
wasaga af25956
add tolerations
wasaga a10bfbf
add proxy service port remapping
wasaga f9c6d78
add node selectors
wasaga caa364e
skip proxy service creation by setting proxy_service_type=null, add p…
wasaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
```terraform | ||
provider "kubernetes" { | ||
|
||
} | ||
|
||
module "pomerium_ingress_controller" { | ||
source = "git:https://github.com/pomerium/ingress-controller//terraform?ref=v0.28.0" | ||
} | ||
|
||
resource "kubernetes_manifest" "pomerium_config" { | ||
manifest = { | ||
apiVersion = "ingress.pomerium.io/v1" | ||
kind = "Pomerium" | ||
metadata = { | ||
name = "global" | ||
} | ||
spec = { | ||
secrets = "pomerium-ingress-controller/bootstrap" | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
resource "kubernetes_cluster_role_binding" "controller" { | ||
metadata { | ||
name = var.controller_cluster_role_name | ||
labels = var.cluster_role_labels | ||
} | ||
|
||
role_ref { | ||
api_group = "rbac.authorization.k8s.io" | ||
kind = "ClusterRole" | ||
name = kubernetes_cluster_role.controller.metadata[0].name | ||
} | ||
|
||
subject { | ||
kind = "ServiceAccount" | ||
name = kubernetes_service_account.controller.metadata[0].name | ||
namespace = kubernetes_namespace.pomerium.metadata[0].name | ||
} | ||
} | ||
|
||
resource "kubernetes_cluster_role_binding" "gen_secrets" { | ||
metadata { | ||
name = var.gen_secrets_cluster_role_name | ||
labels = var.cluster_role_labels | ||
} | ||
|
||
role_ref { | ||
api_group = "rbac.authorization.k8s.io" | ||
kind = "ClusterRole" | ||
name = kubernetes_cluster_role.gen_secrets.metadata[0].name | ||
} | ||
|
||
subject { | ||
kind = "ServiceAccount" | ||
name = kubernetes_service_account.gen_secrets.metadata[0].name | ||
namespace = kubernetes_namespace.pomerium.metadata[0].name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
resource "kubernetes_cluster_role" "controller" { | ||
metadata { | ||
name = var.controller_cluster_role_name | ||
labels = var.cluster_role_labels | ||
} | ||
|
||
rule { | ||
api_groups = [""] | ||
resources = ["services", "endpoints", "secrets"] | ||
verbs = ["get", "list", "watch"] | ||
} | ||
|
||
rule { | ||
api_groups = [""] | ||
resources = ["services/status", "secrets/status", "endpoints/status"] | ||
verbs = ["get"] | ||
} | ||
|
||
rule { | ||
api_groups = ["networking.k8s.io"] | ||
resources = ["ingresses", "ingressclasses"] | ||
verbs = ["get", "list", "watch"] | ||
} | ||
|
||
rule { | ||
api_groups = ["networking.k8s.io"] | ||
resources = ["ingresses/status"] | ||
verbs = ["get", "patch", "update"] | ||
} | ||
|
||
rule { | ||
api_groups = ["ingress.pomerium.io"] | ||
resources = ["pomerium"] | ||
verbs = ["get", "list", "watch"] | ||
} | ||
|
||
rule { | ||
api_groups = ["ingress.pomerium.io"] | ||
resources = ["pomerium/status"] | ||
verbs = ["get", "update", "patch"] | ||
} | ||
|
||
rule { | ||
api_groups = [""] | ||
resources = ["events"] | ||
verbs = ["create", "patch"] | ||
} | ||
} | ||
|
||
resource "kubernetes_cluster_role" "gen_secrets" { | ||
metadata { | ||
name = var.gen_secrets_cluster_role_name | ||
labels = var.cluster_role_labels | ||
} | ||
|
||
rule { | ||
api_groups = [""] | ||
resources = ["secrets"] | ||
verbs = ["create"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resource "kubernetes_manifest" "pomerium_crd" { | ||
manifest = yamldecode(file("${path.module}/crd.yaml")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../config/crd/bases/ingress.pomerium.io_pomerium.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
resource "kubernetes_deployment" "pomerium" { | ||
metadata { | ||
name = var.deployment_name | ||
namespace = var.namespace_name | ||
labels = var.deployment_labels | ||
} | ||
|
||
spec { | ||
replicas = var.deployment_replicas | ||
|
||
selector { | ||
match_labels = { | ||
"app.kubernetes.io/name" = "pomerium-ingress-controller" | ||
} | ||
} | ||
|
||
template { | ||
metadata { | ||
labels = { | ||
"app.kubernetes.io/name" = "pomerium-ingress-controller" | ||
} | ||
} | ||
|
||
spec { | ||
service_account_name = kubernetes_service_account.controller.metadata[0].name | ||
termination_grace_period_seconds = 10 | ||
|
||
security_context { | ||
run_as_non_root = true | ||
} | ||
|
||
node_selector = { | ||
"kubernetes.io/os" = "linux" | ||
} | ||
|
||
container { | ||
name = "pomerium-ingress-controller" | ||
image = "${var.image_repository}:${var.image_tag}" | ||
image_pull_policy = var.image_pull_policy | ||
|
||
args = [ | ||
"all-in-one", | ||
"--pomerium-config=${var.pomerium_config_name}", | ||
"--update-status-from-service=$(POMERIUM_NAMESPACE)/pomerium-proxy", | ||
"--metrics-bind-address=$(POD_IP):9090", | ||
] | ||
|
||
env { | ||
name = "TMPDIR" | ||
value = "/tmp" | ||
} | ||
|
||
env { | ||
name = "XDG_CACHE_HOME" | ||
value = "/tmp" | ||
} | ||
|
||
env { | ||
name = "POMERIUM_NAMESPACE" | ||
value_from { | ||
field_ref { | ||
field_path = "metadata.namespace" | ||
} | ||
} | ||
} | ||
|
||
env { | ||
name = "POD_IP" | ||
value_from { | ||
field_ref { | ||
field_path = "status.podIP" | ||
} | ||
} | ||
} | ||
|
||
port { | ||
container_port = 8443 | ||
name = "https" | ||
protocol = "TCP" | ||
} | ||
|
||
port { | ||
container_port = 8080 | ||
name = "http" | ||
protocol = "TCP" | ||
} | ||
|
||
port { | ||
container_port = 9090 | ||
name = "metrics" | ||
protocol = "TCP" | ||
} | ||
|
||
resources { | ||
limits = { | ||
cpu = var.resources_limits_cpu | ||
memory = var.resources_limits_memory | ||
} | ||
|
||
requests = { | ||
cpu = var.resources_requests_cpu | ||
memory = var.resources_requests_memory | ||
} | ||
} | ||
|
||
security_context { | ||
allow_privilege_escalation = false | ||
read_only_root_filesystem = true | ||
run_as_group = 65532 | ||
run_as_non_root = true | ||
run_as_user = 65532 | ||
} | ||
|
||
volume_mount { | ||
name = "tmp" | ||
mount_path = "/tmp" | ||
} | ||
} | ||
|
||
dynamic "toleration" { | ||
for_each = var.deployment_tolerations | ||
content { | ||
key = lookup(toleration.value, "key", null) | ||
operator = lookup(toleration.value, "operator", null) | ||
value = lookup(toleration.value, "value", null) | ||
effect = lookup(toleration.value, "effect", null) | ||
toleration_seconds = lookup(toleration.value, "toleration_seconds", null) | ||
} | ||
} | ||
|
||
volume { | ||
name = "tmp" | ||
|
||
empty_dir {} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
resource "kubernetes_job" "gen_secrets" { | ||
metadata { | ||
name = var.job_name | ||
namespace = var.namespace_name | ||
labels = var.deployment_labels | ||
} | ||
|
||
spec { | ||
template { | ||
metadata { | ||
name = var.job_name | ||
labels = var.deployment_labels | ||
} | ||
|
||
spec { | ||
service_account_name = kubernetes_service_account.gen_secrets.metadata[0].name | ||
restart_policy = "OnFailure" | ||
|
||
security_context { | ||
fs_group = 1000 | ||
run_as_non_root = true | ||
run_as_user = 1000 | ||
} | ||
|
||
node_selector = { | ||
"kubernetes.io/os" = "linux" | ||
} | ||
|
||
container { | ||
name = "gen-secrets" | ||
image = "${var.image_repository}:${var.image_tag}" | ||
image_pull_policy = "IfNotPresent" | ||
|
||
args = [ | ||
"gen-secrets", | ||
"--secrets=$(POD_NAMESPACE)/bootstrap", | ||
] | ||
|
||
env { | ||
name = "POD_NAMESPACE" | ||
value_from { | ||
field_ref { | ||
field_path = "metadata.namespace" | ||
} | ||
} | ||
} | ||
|
||
security_context { | ||
allow_privilege_escalation = false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "kubernetes_ingress_class" "pomerium" { | ||
metadata { | ||
name = var.ingress_class_name | ||
labels = var.labels | ||
} | ||
|
||
spec { | ||
controller = "pomerium.io/ingress-controller" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource "kubernetes_namespace" "pomerium" { | ||
metadata { | ||
name = var.namespace_name | ||
labels = var.labels | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resource "kubernetes_service_account" "controller" { | ||
metadata { | ||
name = var.controller_service_account_name | ||
namespace = kubernetes_namespace.pomerium.metadata[0].name | ||
labels = var.service_account_labels | ||
} | ||
} | ||
|
||
resource "kubernetes_service_account" "gen_secrets" { | ||
metadata { | ||
name = var.gen_secrets_service_account_name | ||
namespace = kubernetes_namespace.pomerium.metadata[0].name | ||
labels = var.service_account_labels | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
resource "kubernetes_service" "proxy" { | ||
metadata { | ||
name = "pomerium-proxy" | ||
namespace = kubernetes_namespace.pomerium.metadata[0].name | ||
labels = var.service_labels | ||
} | ||
|
||
spec { | ||
selector = { | ||
"app.kubernetes.io/name" = "pomerium-ingress-controller" | ||
} | ||
|
||
external_traffic_policy = var.service_type == "LoadBalancer" ? "Local" : null | ||
|
||
port { | ||
name = "https" | ||
port = 443 | ||
target_port = "https" | ||
protocol = "TCP" | ||
} | ||
|
||
port { | ||
name = "http" | ||
port = 80 | ||
target_port = "http" | ||
protocol = "TCP" | ||
} | ||
|
||
type = var.service_type | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the installation and configuration need be split into separate steps, due to hashicorp/terraform-provider-kubernetes#1367
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also use
kubectl_manifest
instead ofkubernetes_manifest
, which doesn't have this issue.