bootstrap_dags.tf 2.05 KB
Newer Older
1
2
3
locals {
  dags-bootstrap-name      = "dags-bootstrap"
  dags-bootstrap-configmap = "dags-bootstrap-configmap"
4
  bootstrap_image_dags     = "community.opengroup.org:5555/osdu/platform/data-flow/ingestion/ingestion-dags/osdu-bootstrap-dags:latest"
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
}

resource "kubernetes_config_map" "dags-bootstrap-configmap" {
  depends_on = [
    helm_release.ent-configmap,
    kubernetes_namespace.config,
    google_composer_environment.airflow
  ]
  metadata {
    name      = local.dags-bootstrap-configmap
    namespace = kubernetes_namespace.config.metadata[0].name
    labels = {
      app = local.dags-bootstrap-name
    }
  }
  data = {
21
22
23
    DOMAIN            = var.ingress_domain
    COMPOSER_NAME     = google_composer_environment.airflow.name
    LOCATION          = var.service_google_project_region
24
25
    DATA_PARTITION_ID = var.data_partition_id
    SA_FILE_PATH      = "${module.buckets_for_all_projects[var.service_google_project].buckets["${var.service_google_project}-airflow-sa-bucket"].url}/${google_storage_bucket_object.airflow-key.name}"
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  }
}

resource "kubernetes_job" "dags-bootstrap-job" {
  depends_on = [
    kubernetes_job.ent-bootstrap-job,
    kubernetes_config_map.dags-bootstrap-configmap,
    google_service_account_iam_member.bootstrap-iam-gke-binding
  ]
  metadata {
    name      = local.dags-bootstrap-name
    namespace = kubernetes_namespace.config.metadata[0].name
  }
  spec {
    template {
      metadata {}
      spec {
        service_account_name = kubernetes_service_account.gke-bootstrap-sa.metadata[0].name
        container {
          name  = local.dags-bootstrap-name
          image = local.bootstrap_image_dags
          // TBD sleep 10 added to give dags service start properly
          command = ["/bin/bash", "-c", "sleep 10 && source /opt/bootstrap_dags.sh"]
          env_from {
            config_map_ref {
              name = local.dags-bootstrap-configmap
            }
          }
        }
        restart_policy = "Never"
      }
    }
    backoff_limit = 2
  }
  wait_for_completion = true
  timeouts {
    create = "10m"
    update = "10m"
  }
}