Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Make the environment variables length a static variable (#32)
Browse files Browse the repository at this point in the history
* Expose an env_vars length to work around a TF bug

* Use the right version of the modules

* Fix name

* Fix the pluralisation issue

* Count the service vars as well
  • Loading branch information
alexwlchan authored and kenoir committed Dec 15, 2017
1 parent eb4beb8 commit b3cdc20
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion service/ecs_task/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ data "aws_iam_role" "task_role" {
# docs: https://www.terraform.io/docs/configuration/interpolation.html

data "template_file" "name_val_pair" {
count = "${length(local.env_vars)}"
count = "${var.config_vars_length + length(var.service_vars)}"
template = "{\"name\": $${jsonencode(key)}, \"value\": $${jsonencode(value)}}"

vars {
Expand Down
2 changes: 2 additions & 0 deletions service/ecs_task/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ variable "config_vars" {
type = "map"
}

variable "config_vars_length" {}

variable "memory" {
description = "How much memory to allocate to the app"
}
Expand Down
3 changes: 2 additions & 1 deletion service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ module "task" {
NGINX_PORT = "${var.primary_container_port}"
}

config_vars = "${var.env_vars}"
config_vars = "${var.env_vars}"
config_vars_length = "${var.env_vars_length}"

log_group_name_prefix = "${var.log_group_name_prefix}"
}
2 changes: 2 additions & 0 deletions service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ variable "env_vars" {
default = {}
}

variable "env_vars_length" {}

variable "host_name" {
description = "Hostname to be matched in the host condition"
default = ""
Expand Down
5 changes: 3 additions & 2 deletions sqs_autoscaling_service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data "aws_ecs_cluster" "cluster" {
}

module "service" {
source = "git::https://github.com/wellcometrust/terraform-modules.git//service?ref=v4.0.0"
source = "git::https://github.com/wellcometrust/terraform-modules.git//service?ref=env_vars_length"
name = "${var.name}"

cluster_id = "${data.aws_ecs_cluster.cluster.arn}"
Expand All @@ -41,7 +41,8 @@ module "service" {
deployment_minimum_healthy_percent = "0"
deployment_maximum_percent = "200"

env_vars = "${var.env_vars}"
env_vars = "${var.env_vars}"
env_vars_length = "${var.env_vars_length}"

loadbalancer_cloudwatch_id = "${var.alb_cloudwatch_id}"
server_error_alarm_topic_arn = "${var.alb_server_error_alarm_arn}"
Expand Down
2 changes: 2 additions & 0 deletions sqs_autoscaling_service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ variable "env_vars" {
type = "map"
}

variable "env_vars_length" {}

variable "alb_priority" {}
variable "alb_listener_https_arn" {}
variable "alb_listener_http_arn" {}
Expand Down

0 comments on commit b3cdc20

Please sign in to comment.