Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring inline block of resource with list of maps configuration leads to the error: parameter: should be a list #19581

Closed
iliazlobin opened this issue Dec 10, 2018 · 2 comments

Comments

@iliazlobin
Copy link

Description

There is a very convenient way to setup modules using maps. There is a bunch of resources which accept that way of configuration. I've stumbled upon an "aws_ecs_service" resource.

The "aws_ecs_service" resource accept "load_balancer" inline parameter which has it's internal configuration with arguments: "target_group_arn", "container_name", "container_port". The way that Terraform offers to configure it is to use a map like that:

load_balancer {
  target_group_arn = "${aws_lb_target_group.foo.arn}"
  container_name   = "mongo"
  container_port   = 8080
}

It's even work if we would use external configuration: outside of a module. The "load_balancer" parameter is plausible to mention several times in module declaration. So we can use a list of those maps in our module configuration:

module "ecs-service" {
  source = "./ecs-service"

  load_balancer = [{
    target_group_arn = "arn1"
    container_name   = "first"
    container_port   = 80
  },
  {
    target_group_arn = "arn2"
    container_name   = "first"
    container_port   = 80
  }]
}

But, if is it necessary to put ARN value as an output of another module it turns out to get an error:

user$ terraform apply -var-file=./debug.tfvars
Error: module.ecs-service.aws_ecs_service.simple_ecs_service: load_balancer: should be a list

Steps to Reproduce

  1. Checkout code from my repository - https://github.com/iliazlobin/terraform-issue-should_be_a_list
  2. Create the settings file "debug.tfvars" and fill it with your auth data and VPC id (VPC doesn't need to be exist on that moment if you are trying a failing scenario)
aws-region="us-east-1"
aws-access_key="00000000000000000000"
aws-secret_key="0000000000000000000000000000000000000000"
vpc-id="vpc-00000000000000000"
  1. Evaluate next commands and get the error
terraform init
terraform apply -var-file=./debug.tfvars

References

There is a similar issue #13103 where have been discussed about the way how to correctly pass argument from the output of one module to the input of another. And the recommendation is to use interpolation syntax like that:

locals {
  load_balancer_configuration_map = {
    target_group_arn = "${module.alb.arn-value}"
    container_name   = "first"
    container_port   = 80
  }
}

module "ecs-service" {
  source = "./ecs-service"

  load_balancer = "${list(local.load_balancer_configuration_map)}"
}

But it also doesn't work. It returns another error:

Error: module.ecs-service.aws_ecs_service.simple_ecs_service: "load_balancer.0.container_name": required field is not set
Error: module.ecs-service.aws_ecs_service.simple_ecs_service: "load_balancer.0.container_port": required field is not set

The nature of the problem differs. In my case, the argument is the list of maps, but in the issue, it's just list of arguments.

Terraform Version

terraform --version
Terraform v0.11.10
+ provider.aws v1.51.0
@jbardin
Copy link
Member

jbardin commented Dec 10, 2018

Hi @iliazlobin,

Unfortunately this is not really a valid configuration, and though assigning a list of maps to a block takes advantage of some internal implementation details, and works in some cases, you can see does not work in all cases.

There's not much that can be done in 0.11, however we do have a rich type system coming in 0.12 which will support block assignment. https://www.hashicorp.com/blog/terraform-0-12-rich-value-types

@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants