Skip to main content
Knowledge Base

Replacing intermediate-variable in ECS Service

Answer

I am wondering if you could help me out with the upgrade from the intermediate-variable module? I currently upgraded to terraform 0.12 and figured out that the intermediate-variable module is no longer available. How can I replace it in my ecs service? ``` # ------------------------------------------------------------------------------ # CREATE AN ECS TASK TO RUN THE DOCKER CONTAINER # ------------------------------------------------------------------------------ # This template_file defines the Docker containers we want to run in our ECS Task data "template_file" "ecs_task_container_definitions" { template = file( "${path.module}/container-definition/container-definition.json", ) vars = { container_name = var.service_name image = var.image main_version = var.main_version cpu = var.cpu memory = var.memory memoryReservation = var.memoryReservation env_vars = "[${join(",", data.template_file.all_env_vars.*.rendered)}]" } } # Create default map of env vars in the JSON format used by ECS container # definitions. Note that we use the intermediate-variable module here to store # this map in a "variable" we can use elsewhere. module "default_env_vars" { source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/intermediate-variable?ref=v0.0.6" # If you add to this list, BE SURE to bump the explicitly specified value # below in data.template_file.all_env_vars. map_value = { var.vpc_env_var_name = var.vpc_name var.aws_region_env_var_name = var.aws_region var.db_url_env_var_name = data.terraform_remote_state.db.outputs.primary_endpoint var.redis_url_env_var_name = data.terraform_remote_state.redis.outputs.primary_endpoint } } # Merge the default env vars with any extra env vars passed in by the user into # a single map module "all_env_vars" { source = "git::git@github.com:gruntwork-io/package-terraform-utilities.git//modules/intermediate-variable?ref=v0.0.6" map_value = merge(module.default_env_vars.map_value, var.extra_env_vars) } # Convert the env vars into a JSON format used by ECS container definitions. data "template_file" "all_env_vars" { # where 5 is the number of default_env_vars count = var.extra_env_vars_count + 4 template = <<EOF { "name": "${element(keys(module.all_env_vars.map_value), count.index)}", "value": "${module.all_env_vars.map_value[element(keys(module.all_env_vars.map_value), count.index)]}" } EOF } ```

The customer used code from https://github.com/gruntwork-io/infrastructure-modules-acme/blob/master/services/ecs-service-with-alb/main.tf as a reference point.