This commit is contained in:
parent
b555ea788c
commit
360c1263cd
@ -161,7 +161,7 @@ def main(ctx):
|
|||||||
for (coder_template, context) in TEMPLATES[jinja_template].items():
|
for (coder_template, context) in TEMPLATES[jinja_template].items():
|
||||||
context = {k: v for (k, v) in context.items()}
|
context = {k: v for (k, v) in context.items()}
|
||||||
|
|
||||||
target_clusters = [{"name": DEFAULT_CLUSTER_NAME}]
|
target_clusters = [{"name": DEFAULT_CLUSTER_NAME, "config_path": None}]
|
||||||
if "target_clusters" in context:
|
if "target_clusters" in context:
|
||||||
for cluster_name in context["target_clusters"]:
|
for cluster_name in context["target_clusters"]:
|
||||||
target_clusters.append({"name": cluster_name, "config_path": CLUSTERS[cluster_name]})
|
target_clusters.append({"name": cluster_name, "config_path": CLUSTERS[cluster_name]})
|
||||||
|
|||||||
31
base.tf.j2
31
base.tf.j2
@ -12,17 +12,6 @@ terraform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if target_cluster|length > 1 %}
|
|
||||||
{% for cluster in target_clusters %}
|
|
||||||
provider "kubernetes" {
|
|
||||||
alias = "{{cluster['name']}}"
|
|
||||||
{% if "config_path" in cluster %}
|
|
||||||
config_path = "{{cluster['config_path']}}"
|
|
||||||
{% endif %}
|
|
||||||
}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% if coder_user is not defined %}
|
{% if coder_user is not defined %}
|
||||||
@ -56,18 +45,22 @@ locals {
|
|||||||
|
|
||||||
{% block parameters %}
|
{% block parameters %}
|
||||||
{% block target_cluster_parameter %}
|
{% block target_cluster_parameter %}
|
||||||
{% if target_cluster|length > 1 %}
|
{% if target_clusters|length > 1 %}
|
||||||
data "coder_parameter" "target_cluster" {
|
data "coder_parameter" "target_cluster" {
|
||||||
name = "target_cluster"
|
name = "target_cluster"
|
||||||
display_name = "Target Cluster"
|
display_name = "Target Cluster"
|
||||||
description = "The target kubernetes cluster"
|
description = "The target kubernetes cluster"
|
||||||
default = "{{target_cluster[0]['name']}}"
|
default = null
|
||||||
icon = "/icon/k8s.png"
|
icon = "/icon/k8s.png"
|
||||||
mutable = false
|
mutable = false
|
||||||
{% for cluster in target_clusters %}
|
{% for cluster in target_clusters %}
|
||||||
option {
|
option {
|
||||||
name = "{{cluster['name']}}"
|
name = "{{cluster['name']}}"
|
||||||
value = "{{cluster ['name']}}"
|
{% if cluster["config_path"] %}
|
||||||
|
value = "{{cluster ['config_path']}}"
|
||||||
|
{% else %}
|
||||||
|
value = null
|
||||||
|
{% endif %}
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
@ -182,7 +175,11 @@ data "coder_parameter" "git_email" {
|
|||||||
{% block kubernetes %}
|
{% block kubernetes %}
|
||||||
provider "kubernetes" {
|
provider "kubernetes" {
|
||||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||||
|
{% if target_clusters|length > 1 %}
|
||||||
|
config_path = data.coder_parameter.target_cluster.value
|
||||||
|
{% else %}
|
||||||
config_path = null
|
config_path = null
|
||||||
|
{% endif %}
|
||||||
}
|
}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -334,9 +331,6 @@ resource "coder_script" "{{ startup_script }}" {
|
|||||||
|
|
||||||
{% block home_volume %}
|
{% block home_volume %}
|
||||||
resource "kubernetes_persistent_volume_claim" "home" {
|
resource "kubernetes_persistent_volume_claim" "home" {
|
||||||
{% if target_cluster %}
|
|
||||||
provider = kubernetes.{{target_cluster}}
|
|
||||||
{% endif %}
|
|
||||||
metadata {
|
metadata {
|
||||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||||
namespace = "coder"
|
namespace = "coder"
|
||||||
@ -370,9 +364,6 @@ resource "kubernetes_persistent_volume_claim" "home" {
|
|||||||
|
|
||||||
{% block kubernetes_pod_main %}
|
{% block kubernetes_pod_main %}
|
||||||
resource "kubernetes_deployment" "main" {
|
resource "kubernetes_deployment" "main" {
|
||||||
{% if target_cluster %}
|
|
||||||
provider = kubernetes.{{target_cluster}}
|
|
||||||
{% endif %}
|
|
||||||
count = data.coder_workspace.me.start_count
|
count = data.coder_workspace.me.start_count
|
||||||
depends_on = [
|
depends_on = [
|
||||||
kubernetes_persistent_volume_claim.home
|
kubernetes_persistent_volume_claim.home
|
||||||
|
|||||||
Reference in New Issue
Block a user