Skip to content

Commit 4181ef5

Browse files
committed
Make mqtt broker endpoint mandatory
1 parent 75d5588 commit 4181ef5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

main.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ resource "random_uuid" "suffix" {
44
locals {
55
suffix = coalesce(lower(var.unique_suffix), lower(substr(random_uuid.suffix.id, 0, 5)))
66

7-
server_port = 1983
8-
mqtt_port = 1984
9-
mqtt_broker_endpoint = coalesce(var.mqtt_broker_endpoint, "${var.server_domain}:${local.mqtt_port}")
7+
server_port = 1983
8+
mqtt_port = tonumber(split(":", var.mqtt_broker_endpoint)[2])
109
}
1110

1211
module "lb" {
@@ -46,7 +45,7 @@ module "ecs" {
4645

4746
server_port = local.server_port
4847
mqtt_broker_port = local.mqtt_port
49-
mqtt_broker_endpoint = local.mqtt_broker_endpoint
48+
mqtt_broker_endpoint = var.mqtt_broker_endpoint
5049
mqtt_server_target_group_arn = module.lb.mqtt_target_group_arn
5150

5251
database_url = var.database_url

variables.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ variable "unique_suffix" {
1717

1818
variable "mqtt_broker_endpoint" {
1919
type = string
20-
description = "The endpoint of the MQTT broker. If empty, it'll default to server_domain:1984."
21-
default = ""
20+
description = "The endpoint of the MQTT broker. Make sure the protocol is tls:// and that you include a port number. Example: tls://spacelift-mqtt.mycorp.com:1984"
21+
22+
validation {
23+
condition = can(regex("tls://.*:\\d+", var.mqtt_broker_endpoint))
24+
error_message = "mqtt_broker_endpoint must be in the format tls://<hostname>:<port>"
25+
}
2226
}
2327

2428
variable "server_domain" {

0 commit comments

Comments
 (0)