diff --git a/terraform-unity/README.md b/terraform-unity/README.md index c7a0c872..9a067bab 100644 --- a/terraform-unity/README.md +++ b/terraform-unity/README.md @@ -177,7 +177,7 @@ No resources. |------|-------------|------|---------|:--------:| | [airflow\_webserver\_password](#input\_airflow\_webserver\_password) | value | `string` | n/a | yes | | [counter](#input\_counter) | value | `string` | `""` | no | -| [custom\_airflow\_docker\_image](#input\_custom\_airflow\_docker\_image) | Docker image for the customized Airflow image. |
object({
name = string
tag = string
})
|
{
"name": "ghcr.io/unity-sds/unity-sps/sps-airflow",
"tag": "develop"
}
| no | +| [docker\_images](#input\_docker\_images) | Docker images for the services. |
object({
airflow = object({
name = string
tag = string
}),
ogc_processes_api = object({
name = string
tag = string
})
})
|
{
"airflow": {
"name": "ghcr.io/unity-sds/unity-sps/sps-airflow",
"tag": "develop"
},
"ogc_processes_api": {
"name": "ghcr.io/unity-sds/unity-sps-ogc-processes-api/unity-sps-ogc-processes-api",
"tag": "develop"
}
}
| no | | [eks\_cluster\_name](#input\_eks\_cluster\_name) | The name of the EKS cluster. | `string` | n/a | yes | | [helm\_charts](#input\_helm\_charts) | Settings for the required Helm charts. |
map(object({
repository = string
chart = string
version = string
}))
|
{
"airflow": {
"chart": "airflow",
"repository": "https://airflow.apache.org",
"version": "1.11.0"
},
"keda": {
"chart": "keda",
"repository": "https://kedacore.github.io/charts",
"version": "v2.13.1"
}
}
| no | | [kubeconfig\_filepath](#input\_kubeconfig\_filepath) | Path to the kubeconfig file for the Kubernetes cluster | `string` | `"../k8s/kubernetes.yml"` | no | diff --git a/terraform-unity/main.tf b/terraform-unity/main.tf index c512283f..49a5d045 100644 --- a/terraform-unity/main.tf +++ b/terraform-unity/main.tf @@ -1,13 +1,13 @@ module "unity-sps-airflow" { - source = "./modules/terraform-unity-sps-airflow" - project = var.project - venue = var.venue - service_area = var.service_area - counter = var.counter - release = var.release - eks_cluster_name = var.eks_cluster_name - kubeconfig_filepath = var.kubeconfig_filepath - airflow_webserver_password = var.airflow_webserver_password - custom_airflow_docker_image = var.custom_airflow_docker_image - helm_charts = var.helm_charts + source = "./modules/terraform-unity-sps-airflow" + project = var.project + venue = var.venue + service_area = var.service_area + counter = var.counter + release = var.release + eks_cluster_name = var.eks_cluster_name + kubeconfig_filepath = var.kubeconfig_filepath + airflow_webserver_password = var.airflow_webserver_password + docker_images = var.docker_images + helm_charts = var.helm_charts } diff --git a/terraform-unity/modules/terraform-unity-sps-airflow/README.md b/terraform-unity/modules/terraform-unity-sps-airflow/README.md index 9a760b33..91b29ead 100644 --- a/terraform-unity/modules/terraform-unity-sps-airflow/README.md +++ b/terraform-unity/modules/terraform-unity-sps-airflow/README.md @@ -40,13 +40,16 @@ No modules. | [aws_security_group_rule.rds_ingress_from_eks](https://registry.terraform.io/providers/hashicorp/aws/5.35.0/docs/resources/security_group_rule) | resource | | [helm_release.airflow](https://registry.terraform.io/providers/hashicorp/helm/2.12.1/docs/resources/release) | resource | | [helm_release.keda](https://registry.terraform.io/providers/hashicorp/helm/2.12.1/docs/resources/release) | resource | +| [kubernetes_deployment.ogc_processes_api](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/deployment) | resource | | [kubernetes_ingress_v1.airflow_ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/ingress_v1) | resource | +| [kubernetes_ingress_v1.ogc_processes_api_ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/ingress_v1) | resource | | [kubernetes_namespace.airflow](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/namespace) | resource | | [kubernetes_namespace.keda](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/namespace) | resource | | [kubernetes_role.airflow_pod_creator](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/role) | resource | | [kubernetes_role_binding.airflow_pod_creator_binding](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/role_binding) | resource | | [kubernetes_secret.airflow_metadata](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/secret) | resource | | [kubernetes_secret.airflow_webserver](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/secret) | resource | +| [kubernetes_service.ogc_processes_api](https://registry.terraform.io/providers/hashicorp/kubernetes/2.25.2/docs/resources/service) | resource | | [null_resource.remove_finalizers](https://registry.terraform.io/providers/hashicorp/null/3.2.2/docs/resources/resource) | resource | | [random_id.airflow_webserver_secret](https://registry.terraform.io/providers/hashicorp/random/3.6.0/docs/resources/id) | resource | | [random_id.counter](https://registry.terraform.io/providers/hashicorp/random/3.6.0/docs/resources/id) | resource | @@ -64,7 +67,7 @@ No modules. |------|-------------|------|---------|:--------:| | [airflow\_webserver\_password](#input\_airflow\_webserver\_password) | value | `string` | n/a | yes | | [counter](#input\_counter) | value | `string` | n/a | yes | -| [custom\_airflow\_docker\_image](#input\_custom\_airflow\_docker\_image) | Docker image for the customized Airflow image. |
object({
name = string
tag = string
})
| n/a | yes | +| [docker\_images](#input\_docker\_images) | Docker images for the services. |
object({
airflow = object({
name = string
tag = string
}),
ogc_processes_api = object({
name = string
tag = string
})
})
| n/a | yes | | [eks\_cluster\_name](#input\_eks\_cluster\_name) | value | `string` | n/a | yes | | [helm\_charts](#input\_helm\_charts) | Settings for the required Helm charts. |
map(object({
repository = string
chart = string
version = string
}))
| n/a | yes | | [kubeconfig\_filepath](#input\_kubeconfig\_filepath) | Path to the kubeconfig file for the Kubernetes cluster | `string` | n/a | yes | diff --git a/terraform-unity/modules/terraform-unity-sps-airflow/main.tf b/terraform-unity/modules/terraform-unity-sps-airflow/main.tf index 5e5953ce..d9022fba 100644 --- a/terraform-unity/modules/terraform-unity-sps-airflow/main.tf +++ b/terraform-unity/modules/terraform-unity-sps-airflow/main.tf @@ -222,8 +222,8 @@ resource "helm_release" "airflow" { namespace = kubernetes_namespace.airflow.metadata[0].name values = [ templatefile("${path.module}/../../../airflow/helm/values.tmpl.yaml", { - airflow_image_repo = var.custom_airflow_docker_image.name - airflow_image_tag = var.custom_airflow_docker_image.tag + airflow_image_repo = var.docker_images.airflow.name + airflow_image_tag = var.docker_images.airflow.tag kubernetes_namespace = kubernetes_namespace.airflow.metadata[0].name metadata_secret_name = "airflow-metadata-secret" webserver_secret_name = "airflow-webserver-secret" @@ -238,6 +238,55 @@ resource "helm_release" "airflow" { depends_on = [aws_db_instance.airflow_db, helm_release.keda, kubernetes_secret.airflow_metadata, kubernetes_secret.airflow_webserver] } +resource "kubernetes_deployment" "ogc_processes_api" { + metadata { + name = "ogc-processes-api" + namespace = kubernetes_namespace.airflow.metadata[0].name + } + + spec { + replicas = 2 + selector { + match_labels = { + app = "ogc-processes-api" + } + } + template { + metadata { + labels = { + app = "ogc-processes-api" + } + } + spec { + container { + image = "${var.docker_images.ogc_processes_api.name}:${var.docker_images.ogc_processes_api.tag}" + name = "ogc-processes-api" + port { + container_port = 80 + } + } + } + } + } +} + +resource "kubernetes_service" "ogc_processes_api" { + metadata { + name = "ogc-processes-api" + namespace = kubernetes_namespace.airflow.metadata[0].name + } + spec { + selector = { + app = "ogc-processes-api" + } + port { + port = 80 + target_port = 80 + } + type = "ClusterIP" + } +} + resource "kubernetes_ingress_v1" "airflow_ingress" { metadata { name = "airflow-ingress" @@ -267,9 +316,56 @@ resource "kubernetes_ingress_v1" "airflow_ingress" { } } } + # path { + # path = "/ogc-processes-api" + # path_type = "Prefix" + # backend { + # service { + # name = "ogc-processes-api" + # port { + # number = 80 + # } + # } + # } + # } } } } wait_for_load_balancer = true depends_on = [helm_release.airflow] } + +resource "kubernetes_ingress_v1" "ogc_processes_api_ingress" { + metadata { + name = "ogc-processes-api-ingress" + namespace = kubernetes_namespace.airflow.metadata[0].name + annotations = { + "alb.ingress.kubernetes.io/scheme" = "internet-facing" + "alb.ingress.kubernetes.io/target-type" = "ip" + "alb.ingress.kubernetes.io/subnets" = join(",", jsondecode(data.aws_ssm_parameter.subnet_ids.value)["public"]) + "alb.ingress.kubernetes.io/listen-ports" = "[{\"HTTP\": 5001}]" + "alb.ingress.kubernetes.io/healthcheck-path" = "/health" + } + } + + spec { + ingress_class_name = "alb" + rule { + http { + path { + path = "/" + path_type = "Prefix" + backend { + service { + name = kubernetes_service.ogc_processes_api.metadata[0].name + port { + number = 80 + } + } + } + } + } + } + } + wait_for_load_balancer = true +} diff --git a/terraform-unity/modules/terraform-unity-sps-airflow/variables.tf b/terraform-unity/modules/terraform-unity-sps-airflow/variables.tf index b385a0de..57dd209c 100644 --- a/terraform-unity/modules/terraform-unity-sps-airflow/variables.tf +++ b/terraform-unity/modules/terraform-unity-sps-airflow/variables.tf @@ -47,10 +47,16 @@ variable "helm_charts" { })) } -variable "custom_airflow_docker_image" { - description = "Docker image for the customized Airflow image." +variable "docker_images" { + description = "Docker images for the services." type = object({ - name = string - tag = string + airflow = object({ + name = string + tag = string + }), + ogc_processes_api = object({ + name = string + tag = string + }) }) } diff --git a/terraform-unity/variables.tf b/terraform-unity/variables.tf index b4b30992..f1a397e6 100644 --- a/terraform-unity/variables.tf +++ b/terraform-unity/variables.tf @@ -64,14 +64,26 @@ variable "helm_charts" { } } -variable "custom_airflow_docker_image" { - description = "Docker image for the customized Airflow image." +variable "docker_images" { + description = "Docker images for the services." type = object({ - name = string - tag = string + airflow = object({ + name = string + tag = string + }), + ogc_processes_api = object({ + name = string + tag = string + }) }) default = { - name = "ghcr.io/unity-sds/unity-sps/sps-airflow" - tag = "develop" + airflow = { + name = "ghcr.io/unity-sds/unity-sps/sps-airflow" + tag = "develop" + }, + ogc_processes_api = { + name = "ghcr.io/unity-sds/unity-sps-ogc-processes-api/unity-sps-ogc-processes-api" + tag = "develop" + } } }