Skip to content

Commit

Permalink
Merge pull request #9 from unity-sds/259-cwl
Browse files Browse the repository at this point in the history
Add basic support for deploying the OGC Processes API
  • Loading branch information
drewm-swe authored Feb 28, 2024
2 parents a89e1ed + 88f9ae4 commit c77a148
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 25 deletions.
2 changes: 1 addition & 1 deletion terraform-unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ No resources.
|------|-------------|------|---------|:--------:|
| <a name="input_airflow_webserver_password"></a> [airflow\_webserver\_password](#input\_airflow\_webserver\_password) | value | `string` | n/a | yes |
| <a name="input_counter"></a> [counter](#input\_counter) | value | `string` | `""` | no |
| <a name="input_custom_airflow_docker_image"></a> [custom\_airflow\_docker\_image](#input\_custom\_airflow\_docker\_image) | Docker image for the customized Airflow image. | <pre>object({<br> name = string<br> tag = string<br> })</pre> | <pre>{<br> "name": "ghcr.io/unity-sds/unity-sps/sps-airflow",<br> "tag": "develop"<br>}</pre> | no |
| <a name="input_docker_images"></a> [docker\_images](#input\_docker\_images) | Docker images for the services. | <pre>object({<br> airflow = object({<br> name = string<br> tag = string<br> }),<br> ogc_processes_api = object({<br> name = string<br> tag = string<br> })<br> })</pre> | <pre>{<br> "airflow": {<br> "name": "ghcr.io/unity-sds/unity-sps/sps-airflow",<br> "tag": "develop"<br> },<br> "ogc_processes_api": {<br> "name": "ghcr.io/unity-sds/unity-sps-ogc-processes-api/unity-sps-ogc-processes-api",<br> "tag": "develop"<br> }<br>}</pre> | no |
| <a name="input_eks_cluster_name"></a> [eks\_cluster\_name](#input\_eks\_cluster\_name) | The name of the EKS cluster. | `string` | n/a | yes |
| <a name="input_helm_charts"></a> [helm\_charts](#input\_helm\_charts) | Settings for the required Helm charts. | <pre>map(object({<br> repository = string<br> chart = string<br> version = string<br> }))</pre> | <pre>{<br> "airflow": {<br> "chart": "airflow",<br> "repository": "https://airflow.apache.org",<br> "version": "1.11.0"<br> },<br> "keda": {<br> "chart": "keda",<br> "repository": "https://kedacore.github.io/charts",<br> "version": "v2.13.1"<br> }<br>}</pre> | no |
| <a name="input_kubeconfig_filepath"></a> [kubeconfig\_filepath](#input\_kubeconfig\_filepath) | Path to the kubeconfig file for the Kubernetes cluster | `string` | `"../k8s/kubernetes.yml"` | no |
Expand Down
22 changes: 11 additions & 11 deletions terraform-unity/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -64,7 +67,7 @@ No modules.
|------|-------------|------|---------|:--------:|
| <a name="input_airflow_webserver_password"></a> [airflow\_webserver\_password](#input\_airflow\_webserver\_password) | value | `string` | n/a | yes |
| <a name="input_counter"></a> [counter](#input\_counter) | value | `string` | n/a | yes |
| <a name="input_custom_airflow_docker_image"></a> [custom\_airflow\_docker\_image](#input\_custom\_airflow\_docker\_image) | Docker image for the customized Airflow image. | <pre>object({<br> name = string<br> tag = string<br> })</pre> | n/a | yes |
| <a name="input_docker_images"></a> [docker\_images](#input\_docker\_images) | Docker images for the services. | <pre>object({<br> airflow = object({<br> name = string<br> tag = string<br> }),<br> ogc_processes_api = object({<br> name = string<br> tag = string<br> })<br> })</pre> | n/a | yes |
| <a name="input_eks_cluster_name"></a> [eks\_cluster\_name](#input\_eks\_cluster\_name) | value | `string` | n/a | yes |
| <a name="input_helm_charts"></a> [helm\_charts](#input\_helm\_charts) | Settings for the required Helm charts. | <pre>map(object({<br> repository = string<br> chart = string<br> version = string<br> }))</pre> | n/a | yes |
| <a name="input_kubeconfig_filepath"></a> [kubeconfig\_filepath](#input\_kubeconfig\_filepath) | Path to the kubeconfig file for the Kubernetes cluster | `string` | n/a | yes |
Expand Down
100 changes: 98 additions & 2 deletions terraform-unity/modules/terraform-unity-sps-airflow/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
14 changes: 10 additions & 4 deletions terraform-unity/modules/terraform-unity-sps-airflow/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
}
24 changes: 18 additions & 6 deletions terraform-unity/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit c77a148

Please sign in to comment.