diff --git a/jupyter-on-gke/iap_module/iap.tf b/jupyter-on-gke/iap_module/iap.tf index a74574f03..ae6fe4d4c 100644 --- a/jupyter-on-gke/iap_module/iap.tf +++ b/jupyter-on-gke/iap_module/iap.tf @@ -24,13 +24,6 @@ data "local_file" "static_ingress_yaml" { filename = "${path.module}/deployments/static-ingress.yaml" } -data "google_compute_backend_service" "jupyter-ingress" { - name = var.service_name - project = var.project_id - - depends_on = [ kubectl_manifest.backend_config ] -} - # Reserve IP Address resource "google_compute_global_address" "default" { provider = google-beta @@ -40,12 +33,14 @@ resource "google_compute_global_address" "default" { ip_version = "IPV4" } +# The configuration that will trigger turning on IAP resource "kubectl_manifest" "backend_config" { override_namespace = var.namespace yaml_body = templatefile("${path.module}/deployments/backend-config.yaml", {}) depends_on = [ kubectl_manifest.static_ingress ] } +# Specifies the domain for the SSL certificate, wildcard domains are not supported resource "kubectl_manifest" "managed_cert" { override_namespace = var.namespace yaml_body = templatefile("${path.module}/deployments/managed-cert.yaml", { @@ -54,6 +49,7 @@ resource "kubectl_manifest" "managed_cert" { depends_on = [ google_compute_global_address.default ] } +# Ingress for IAP resource "kubectl_manifest" "static_ingress" { override_namespace = var.namespace @@ -63,6 +59,7 @@ resource "kubectl_manifest" "static_ingress" { depends_on = [ google_compute_global_address.default, kubectl_manifest.managed_cert ] } +# Secret used by the BackendConfig, contains the OAuth client info resource "kubernetes_secret" "my-secret" { metadata { name = "my-secret" diff --git a/jupyter-on-gke/iap_module/output.tf b/jupyter-on-gke/iap_module/output.tf deleted file mode 100644 index 25397163a..000000000 --- a/jupyter-on-gke/iap_module/output.tf +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -output "backend_service_id" { - description = "Backend Service" - value = data.google_compute_backend_service.jupyter-ingress.generated_id == null ? "no-id-yet" : data.google_compute_backend_service.jupyter-ingress.generated_id -} \ No newline at end of file diff --git a/jupyter-on-gke/jupyterhub.tf b/jupyter-on-gke/jupyterhub.tf index 075ebf1ce..5514b2051 100644 --- a/jupyter-on-gke/jupyterhub.tf +++ b/jupyter-on-gke/jupyterhub.tf @@ -31,6 +31,16 @@ provider "google-beta" { region = var.location } +data "google_project" "project" { + project_id = var.project_id +} + +# The data of the GCP backend service. IAP is enabled on this backend service +data "google_compute_backend_service" "jupyter-ingress" { + name = var.service_name + project = var.project_id +} + resource "kubernetes_namespace" "namespace" { count = var.create_namespace ? 1 : 0 metadata { @@ -53,7 +63,10 @@ module "iap_auth" { client_secret = var.client_secret service_name = var.service_name - depends_on = [ kubernetes_namespace.namespace ] + depends_on = [ + helm_release.jupyterhub, + kubernetes_namespace.namespace, + ] } resource "helm_release" "jupyterhub" { @@ -64,14 +77,13 @@ resource "helm_release" "jupyterhub" { cleanup_on_fail = "true" values = [ - templatefile(var.add_auth ? "${path.module}/jupyter_config/config-selfauth.yaml" : "${path.module}/jupyter_config/config.yaml", { - service_id = var.add_auth ? "${module.iap_auth[0].backend_service_id}" : "none" - project_number = "${var.project_number}" + templatefile(var.add_auth ? "${path.module}/jupyter_config/config-selfauth.yaml" : "${path.module}/jupyter_config/config-filestore.yaml", { + service_id = var.add_auth && data.google_compute_backend_service.jupyter-ingress.generated_id != null ? "${data.google_compute_backend_service.jupyter-ingress.generated_id}" : "no-id-yet" + project_number = data.google_project.project.number }) ] depends_on = [ - module.iap_auth, kubernetes_namespace.namespace ] } diff --git a/jupyter-on-gke/variables.tf b/jupyter-on-gke/variables.tf index 378e755bd..486eeb1b7 100644 --- a/jupyter-on-gke/variables.tf +++ b/jupyter-on-gke/variables.tf @@ -33,13 +33,7 @@ variable "add_auth" { variable "project_id" { type = string description = "GCP project id" - default = "<>Project ID here" -} - -variable "project_number" { - type = string - description = "GCP project number (Not to be confused with porject id)" - default = "" + default = "" } variable "location" {