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

Maps not coerced to objects for input variables #24092

Closed
davecardwell opened this issue Feb 12, 2020 · 3 comments · Fixed by #24265
Closed

Maps not coerced to objects for input variables #24092

davecardwell opened this issue Feb 12, 2020 · 3 comments · Fixed by #24265
Labels

Comments

@davecardwell
Copy link

Terraform Version

Terraform v0.12.20

Terraform Configuration Files

main.tf

module "child" {
  source = "./child"
  foo    = map("bar", "baz")
}

child/child.tf

variable "foo" {
  type = object({ bar = string })
}

Debug Output

https://gist.github.com/davecardwell/94c238e4f12d7d5612668a3747a35ea1

Expected Behavior

From Conversion of Complex Types in the docs I expected the map to be converted to an object and accepted as a valid value.

Actual Behavior

Error: Invalid value for module argument

  on main.tf line 3, in module "child":
   3:   foo    = map("bar", "baz")

The given value is not suitable for child module variable "foo" defined at
child/child.tf:1,1-15: object required.

Steps to Reproduce

  1. terraform init
  2. terraform validate
@jbardin
Copy link
Member

jbardin commented Feb 13, 2020

Hi @davecardwell,

Thanks, it appears the conversion functions aren't handling this case correctly.

The good news is that if you're only dealing with literals or expressions, they will initially be typed as an object and pass through. The map function itself is deprecated and should not be used.

@davecardwell
Copy link
Author

Thanks for the speedy response, @jbardin.

I used the map function in my example but my actual use case is passing the result of an External Data Source to a child module.

I can set the variable type as map(string) and it works fine, or I can choose the individual values from the data source to pass through in the module {} block, so there are workarounds.

I went digging and raised the issue withgo-cty so will see if they think it’s viable to support map-to-object conversions. I don’t mind if you want to close this issue or leave it open for tracking progress there.

@ghost
Copy link

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