https.tf 3.03 KB
Newer Older
Oleksandr Kosse (EPAM)'s avatar
Cluster  
Oleksandr Kosse (EPAM) committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
resource "local_file" "ingress" {
  depends_on = [google_container_cluster.primary, local_file.frontend]
  content = templatefile("${path.module}/manifests/tpl/ingress.tpl.yaml", {
    ip        = google_compute_global_address.default.name
    cert_name = google_compute_managed_ssl_certificate.default.name
  })

  filename = "./manifests/ingress.yaml"
}

resource "local_file" "frontend" {
  depends_on = [google_compute_ssl_policy.osdu-ssl-policy]
  content = templatefile("${path.module}/manifests/tpl/frontend.tpl.yaml", {
    policy = "osdu-ssl-policy"
  })

  filename = "./manifests/frontend.yaml"
}

20
module "kubectl" {
21
  source                  = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
22
23
24
25
26
27
28
  module_depends_on       = [google_container_cluster.primary]
  project_id              = var.service_google_project
  cluster_name            = google_container_cluster.primary.name
  cluster_location        = google_container_cluster.primary.location
  additional_components   = ["kubectl", "kpt", "beta"]
  kubectl_create_command  = "${path.module}/scripts/install_asm.sh ${var.service_google_project} ${google_container_cluster.primary.name} ${google_container_cluster.primary.location} asm-downloads"
  kubectl_destroy_command = "${path.module}/scripts/destroy_asm.sh"
Oleksandr Kosse (EPAM)'s avatar
Cluster  
Oleksandr Kosse (EPAM) committed
29
30
31
}

resource "null_resource" "service-gateway" {
32
  depends_on = [google_container_cluster.primary, local_file.ingress, module.kubectl]
Oleksandr Kosse (EPAM)'s avatar
Cluster  
Oleksandr Kosse (EPAM) committed
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

  triggers = {
    endpoint = google_container_cluster.primary.endpoint
    hash     = sha256(file("${path.module}/manifests/service-gateway.yaml"))
    hash     = sha256(local_file.frontend.content)
    hash     = sha256(local_file.ingress.content)
    hash     = sha256(file("${path.module}/scripts/backend-config.sh"))
  }

  provisioner "local-exec" {
    command = "gcloud container clusters get-credentials ${google_container_cluster.primary.name} --zone=${google_container_cluster.primary.location}"
  }

  provisioner "local-exec" {
    command = "kubectl apply -f ${path.module}/manifests/service-gateway.yaml"
  }

  provisioner "local-exec" {
    command = "kubectl apply -f ${local_file.frontend.filename}"
  }
  provisioner "local-exec" {
    command = "kubectl apply -f ${local_file.ingress.filename}"
  }

  provisioner "local-exec" {
    command = "sh ${path.module}/scripts/backend-config.sh"
  }

  provisioner "local-exec" {
    command = "kubectl annotate -n istio-system service/istio-ingressgateway --overwrite cloud.google.com/backend-config='{\"default\": \"http-hc-config\"}' cloud.google.com/neg='{\"ingress\":true}'"
  }

}

resource "google_compute_global_address" "default" {
  depends_on = [module.project-services]
  name       = "gke-ingress-ip"
}

resource "google_compute_managed_ssl_certificate" "default" {
  depends_on = [google_compute_global_address.default, module.project-services]
  name       = "gke-ingress-cert"

  managed {
    domains = [var.ingress_domain]
  }
}

resource "google_compute_ssl_policy" "osdu-ssl-policy" {
  name            = "osdu-ssl-policy"
  profile         = "MODERN"
  min_tls_version = "TLS_1_2"
}