0.7.13
The page https://www.terraform.io/docs/providers/aws/r/lambda_function.html#variables states:
variables - (Optional) A map that defines environment variables for the Lambda function.
But when creating a map
variable "something" {
type = "map"
default {
something = "somethingelse"
}
}
And use it as:
resource "aws_lambda_function" "something" {
environment = "${var.something}"
}
I get:
* aws_lambda_function.something: environment: should be a list
Thinking about this a bit more, I think that TF is wrong in requiring it to be a list. A list don't have key/value (as in "variable name" and "variable value"), so the documentation is probably right, but the TF code is wrong.
Hi @FransUrbo
Apologies for the issue here - i am not quite sure why we have such a confusing message on this. From our nightly acceptance tests, I can see we have the following example:
resource "aws_lambda_function" "lambda_function_test" {
filename = "test-fixtures/lambdatest.zip"
function_name = "my-test-lambda-name"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.example"
environment {
variables = {
foo = "bar"
}
}
}
If you can, give that a shot and see if that works out for you - if so, then i will change the documentation example to reflect this
Paul
I think the confusing message here comes from how we represent nested blocks like that environment block. Inside the helper/schema system there's no support for a single nested block, so we usually represent it as either a set or list of nested blocks and then check in the code to make sure that this list/set only has one member. But if you give it something other than a list, it'd get caught up in the built-in validation logic in helper/schema, which is (I suspect) what is generating this generic error message.
To improve on this we'd probably need to give helper/schema itself some way to model these single nested block constructs, so that it can then give a more appropriate error message.
Worked perfectly, thank you!
Hi @FransUrbo
Just opened https://github.com/hashicorp/terraform/pull/10490 to help address the example here
Thanks for letting me know
Paul
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.