Terraform: Crash in `aws_instance` data source when passing a list instead of an id as the `instance_id`

Created on 5 Feb 2019  ·  5Comments  ·  Source: hashicorp/terraform

Hi everyone 👋

Sharing this not necessarily because it caused us a big issue and is a must fix but more so in case there is room to improve the error message shown. The below fails when passing a list instead of a string to instance_id

Terraform Version

Terraform v0.11.11
+ provider.aws v1.57.0
+ provider.external v1.0.0

Terraform Configuration Files

data "aws_instance" "beanstalk-ec2-instance" {
  instance_id = "${aws_elastic_beanstalk_environment.my-beanstalk.instances}"
}

output "security-group" {
  value = "${data.aws_instance.beanstalk-ec2-instance.security_groups}"
}

Crash Output

https://gist.github.com/Maikon/7f7991f180d0e42a2e5a934963f80416

The key line I assume is this:

2019-02-05T11:27:53.519Z [DEBUG] plugin.terraform-provider-aws_v1.57.0_x4: panic: Error reading level config: '' expected type 'string', got unconvertible type '[]interface {}'

Expected Behavior

Perhaps a more meaningful error? Maybe show line number and/or hints of what may have gone wrong?

Actual Behavior

Crashes generating a quite large crash.log

bug config crash

Most helpful comment

Hi @Maikon,

I believe this bug is already fixed in master in preparation for the forthcoming v0.12.0 release, so I'm going to label this as part of that milestone to remind us to verify it.

All 5 comments

Hi @Maikon,

I believe this bug is already fixed in master in preparation for the forthcoming v0.12.0 release, so I'm going to label this as part of that milestone to remind us to verify it.

Great, thanks @apparentlymart!

Verified that this is correctly validated in 0.12.

Error: Incorrect attribute value type

  on main.tf line 13, in data "aws_instance" "beanstalk-ec2-instance":
  13:   instance_id = aws_elastic_beanstalk_environment.my-beanstalk.instances

Inappropriate value for attribute "instance_id": string required.

Thanks @Maikon!

Awesome, thank you @jbardin!

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.

Was this page helpful?
0 / 5 - 0 ratings