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

Convert: variables / locals / referenced maps need to use accessor syntax #2670

Closed
DanielMSchmidt opened this issue Feb 22, 2023 · 4 comments · Fixed by #3056
Closed

Convert: variables / locals / referenced maps need to use accessor syntax #2670

DanielMSchmidt opened this issue Feb 22, 2023 · 4 comments · Fixed by #3056
Assignees
Labels
bug Something isn't working feature/convert priority/important-soon High priority, to be worked on as part of our current release or the following one. size/medium estimated < 1 week
Milestone

Comments

@DanielMSchmidt
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

Affected Resource(s)

Summary

Converting this example leads to an invalid access to the project key in the map, where a Fn.lookup call would have been necessary

variable "default_tags" {
  type        = map(string)
  description = "Map of default tags to apply to resources"
  default = {
    project = "Learning Live with AWS & HashiCorp"
  }
}

resource "aws_eip" "nat" {
  vpc = true
  tags = {
    "Name" = "${var.default_tags.project}-nat-eip"
  }
}
@DanielMSchmidt DanielMSchmidt added bug Something isn't working new Un-triaged issue feature/convert labels Feb 22, 2023
@ansgarm
Copy link
Member

ansgarm commented Feb 22, 2023

While this might not be that much better than Fn.lookup – we might think about exposing the PropertyAccess expression. The good thing about that way, would be that it supports a path, which might be more readable for nested access:

Fn.Lookup(Fn.Lookup(Fn.Lookup(mapRef, "c"), "b"), "a")
// vs.
Todo.propertyAccess(mapRef, ["a", "b", "c"])

(Sidenote: I left out the defaultValue param for lookup for simplicity, as that one is actually still optional but discouraged since TF 0.7; docs)

@ansgarm
Copy link
Member

ansgarm commented Feb 22, 2023

We might even expose this via TF functions 🤔
Maybe Fn.property(mapRef, ["a", "b", "c"]) (like lodash) or some better wording. Another idea would be to do the following:

Fn.lookup(ref, property, defaultValue) // => lookup() TF call
Fn.lookup(ref, property) // => ref[property] TF expression
Fn.lookupNested(ref, [propertyA, propertyB]) // => ref[propertyA][propertyB] TF expression

What do you think? 🤔

@DanielMSchmidt
Copy link
Contributor Author

I think that's a good idea

@DanielMSchmidt DanielMSchmidt added needs-priority Issue has not yet been prioritized; this will prompt team review size/medium estimated < 1 week and removed new Un-triaged issue labels Mar 10, 2023
@xiehan xiehan added priority/important-soon High priority, to be worked on as part of our current release or the following one. and removed needs-priority Issue has not yet been prioritized; this will prompt team review labels Jun 1, 2023
@xiehan xiehan added this to the 0.17 (tentative) milestone Jun 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2023

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've 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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working feature/convert priority/important-soon High priority, to be worked on as part of our current release or the following one. size/medium estimated < 1 week
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants