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

Crash when list is assigned to string parameter #2984

Closed
choosy opened this issue Aug 12, 2015 · 9 comments
Closed

Crash when list is assigned to string parameter #2984

choosy opened this issue Aug 12, 2015 · 9 comments

Comments

@choosy
Copy link

choosy commented Aug 12, 2015

Got this crash report.

https://gist.github.com/choosy/a41dde20526671837943

@apparentlymart
Copy link
Contributor

@choosy it looks like you got this error with a aws_route_table_association resource. Would you mind sharing the configuration of that object so that it's easier to see how to reproduce this?

@choosy
Copy link
Author

choosy commented Aug 13, 2015

Hi @apparentlymart,

I have put it here:
https://gist.github.com/choosy/2c028c780b23ac65d127

Thank you for your investigation.

@apparentlymart
Copy link
Contributor

I think the problem here is that you've put a list as the value of subnet_id (on line 186) but it expects only a single string.

It is a bug in Terraform that this wasn't caught during the configuration validation step and instead blew up inside the diffing logic. However, you should be able to work around that bug by using a separate aws_route_table_association resource for each pair of route_table_id and subnet_id, like this:

resource "aws_route_table_association" "rt-assoc-dmz-use1b" {
    route_table_id = "${aws_route_table.rt-vpc18-dmz.id}"
    subnet_id = "${aws_subnet.vpc18-dmz-us-east-1b.id}"
}
resource "aws_route_table_association" "rt-assoc-dmz-use1c" {
    route_table_id = "${aws_route_table.rt-vpc18-dmz.id}"
    subnet_id = "${aws_subnet.vpc18-dmz-us-east-1c.id}"
}
resource "aws_route_table_association" "rt-assoc-dmz-use1d" {
    route_table_id = "${aws_route_table.rt-vpc18-dmz.id}"
    subnet_id = "${aws_subnet.vpc18-dmz-us-east-1d.id}"
}
resource "aws_route_table_association" "rt-assoc-dmz-use1e" {
    route_table_id = "${aws_route_table.rt-vpc18-dmz.id}"
    subnet_id = "${aws_subnet.vpc18-dmz-us-east-1e.id}"
}

@choosy
Copy link
Author

choosy commented Aug 14, 2015

Hi @apparentlymart ,

That was it. I managed to get passed that using your example.

Thank you!

@apparentlymart
Copy link
Contributor

Great! I'm glad that worked out. @choosy would you mind changing the title of your issue to "Crash when list is assigned to string parameter"? That should make it easier for folks to find this issue and increase the chance that it'll be fixed.

@apparentlymart
Copy link
Contributor

I can repro your crash with your exact config but interestingly if I try to simplify it to just the core issue of using a list instead of a string then it ceases to be a crash and instead appears as a regular error:

$ terraform plan
There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Errors:

  * aws_route_table_association.foo: '' expected type 'string', got unconvertible type '[]interface {}'

Here is my simplified config:

resource "aws_route_table_association" "foo" {
    route_table_id = "bar"
    subnet_id = ["baz", "foo"]
}

Either way this is not a user-friendly error message since it uses Go type system terminology rather than Terraform config language terminology. Feels to me like there's a missing check earlier up the chain that should've caught this in both cases, and it just happens that in one case it gets paniced and in the other case it gets returned but either way it's a "should never happen"-type situation.

@apparentlymart
Copy link
Contributor

I made a nicer validation error message in #3009, but that hasn't fixed this crash. It seems that somehow the aws_route_table_association resource block in @choosy's config is bypassing the Validate step, since the crash still returns the internal mapstructure error message and not the new, higher-level message introduced in that other PR.

@apparentlymart
Copy link
Contributor

I found the trick: because there were interpolations of computed values in the list, the validator skipped validating that field. My updated patch in #3009 now checks for lists even when the list values are computed, so we get the proper error message and not a crash with @choosy's config.

@choosy choosy changed the title Crash report (v0.6.3) Crash when list is assigned to string parameter Aug 20, 2015
@ghost
Copy link

ghost commented Apr 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 Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants