Skip to content

Commit 359cad9

Browse files
Issue/data platform robust (#933)
* add elbscheme to elastic beanstalk * update name to v2 * add DATA_PLATFORM_HOST to analysis-dashboard and airflow * add list of ports for the listeners * remove v2 * use container port mappings * fix * fix * fix default * fix
1 parent 9dbe022 commit 359cad9

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

terraform/india/development/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ module "analysis_dashboard" {
189189
container-name = "analysis-dashboard"
190190
container-tag = var.analysis_dashboard_version
191191
container-registry = "ghcr.io/openclimatefix"
192-
container-port = 8501
192+
container-port-mappings = [
193+
{"host":"80", "container": "8501"},
194+
]
193195
eb-app_name = "analysis-dashboard"
194196
eb-instance_type = "t3.small"
195197
s3_bucket = [

terraform/modules/services/eb_app/eb.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ resource "aws_elastic_beanstalk_environment" "eb-environment" {
9898
}
9999

100100
# Following https://discuss.streamlit.io/t/howto-streamlit-on-aws-with-elastic-beanstalk-and-docker/10353
101-
setting {
102-
namespace = "aws:elb:listener:80"
103-
name = "ListenerProtocol"
104-
value = "TCP"
105-
resource = ""
106-
}
101+
dynamic "setting" {
102+
for_each = var.elb_ports
103+
content {
104+
namespace = "aws:elb:listener:${setting.value}"
105+
name = "ListenerProtocol"
106+
value = "TCP"
107+
resource = ""
108+
}
109+
}
107110

108111

109112
###=========================== Logging ========================== ###

terraform/modules/services/eb_app/s3.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "aws_s3_object" "eb-object" {
1616
"environment" = [for kv in var.container-env_vars : format("%s=$%s", kv.name, kv.name)],
1717
"container_name" = (var.container-name),
1818
"command" = (var.container-command),
19-
"ports" = ["${var.container-host-port}:${var.container-port}"],
19+
"ports" = [for mapping in var.container-port-mappings : format("%s:%s", mapping.host, mapping.container)],
2020
}
2121
}
2222
})

terraform/modules/services/eb_app/variables.tf

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,25 @@ variable container-command {
6464
description = "Command to run in the container"
6565
}
6666

67-
variable container-port {
68-
type = number
69-
description = "Port on which the container listens"
70-
default = 80
67+
variable elb_ports {
68+
type = list
69+
description = "List of ports for listeners for the load balancer"
70+
default = ["80"]
7171
}
7272

73-
variable container-host-port {
74-
type = number
75-
description = "Host Port feed to container port"
76-
default = 80
73+
variable container-port-mappings {
74+
type = list(object({
75+
host = string
76+
container = string
77+
}))
78+
description = <<EOT
79+
container-port-mappings = {
80+
container : "The port number within the container that's listening for connections"
81+
host : "The port number on your host machine where you want to receive traffic"
82+
}
83+
container-port-mappings : "Mapping of ports to and from container"
84+
EOT
85+
default = [{"host":"80", "container":"80"}]
7786
}
7887

7988
// EB configuration --------------------------------------------------------

terraform/nowcasting/development/main.tf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ module "airflow" {
157157
{ "name" : "LOGLEVEL", "value" : "INFO" },
158158
{ "name" : "SENTRY_DSN", "value" : var.sentry_dsn_api },
159159
{ "name" : "URL", "value" : var.airflow_url },
160+
{ "name" : "DATA_PLATFORM_HOST", "value": module.data_platform_api.api_url},
160161
]
161162
}
162163

@@ -179,11 +180,14 @@ module "analysis_dashboard" {
179180
{ "name" : "AUTH0_CLIENT_ID", "value" : var.auth_dashboard_client_id },
180181
{ "name" : "REGION", "value": local.domain},
181182
{ "name" : "ENVIRONMENT", "value": local.environment},
183+
{ "name" : "DATA_PLATFORM_HOST", "value": module.data_platform_api.api_url},
182184
]
183185
container-name = "analysis-dashboard"
184186
container-tag = var.internal_ui_version
185187
container-registry = "ghcr.io/openclimatefix"
186-
container-port = 8501
188+
container-port-mappings = [
189+
{"host":"80", "container": "8501"},
190+
]
187191
eb-app_name = "internal-ui"
188192
eb-instance_type = "t3.small"
189193
s3_bucket = [
@@ -303,10 +307,13 @@ module "data_platform_api" {
303307
container-name = "data-platform"
304308
container-tag = var.data_platform_api_version
305309
container-registry = "ghcr.io/openclimatefix"
306-
eb-app_name = "data-platform-api-v2"
310+
eb-app_name = "data-platform-api"
307311
eb-instance_type = "t3.micro"
308312
s3_bucket = []
309-
container-host-port = "50051"
310-
container-port = "50051"
313+
container-port-mappings = [
314+
{"host":"50051", "container": "50051"},
315+
{"host":"80", "container": "50051"},
316+
]
311317
elbscheme="internal"
318+
elb_ports=["80","50051"]
312319
}

0 commit comments

Comments
 (0)