-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Self variables are only valid on resources #14684
Comments
Hi @scriptjs, Could you please share an example of what you are trying to do? It's not clear how exactly self variables for modules would work, since self variables are used for |
The use case for self in modules is pretty much the same as resources. I may have a static attribute that becomes part of a name in another attribute or key to a data lookup. I don't want to duplicate the original attribute but use it with some interpolation. There is no interpolation of variables so there can only be interpolation in the module. I think self and count are the two real limitations of modules. |
@scriptjs today a resource cannot refer to its own attributes with resource "aws_instance" "foo" {
# ...
connection {
host = "${self.private_ip}"
}
} Self-referential things are not permitted in general because that would create a dependency cycle. It sounds like your root concern is having a way to say something in one place and then refer to it in other places, like #4084. We couldn't allow a module block to reference its own arguments, but we could allow two arguments in a module block to both reference the same intermediate variable, should such a concept exists. Does that seem fair, or am I misunderstanding what you're asking for? |
I am using data sources created with null_resources to obtain the effect of vars I can use everywhere I need atm which is good. The challenge that brought me to this issue is perhaps more of trying to work around modules without count. I have to create resources for multiple tenants in openstack and I cannot loop with an alias tenant in a resource. Therefore I have had to go to creating modules where tenant ids are static. So even if the id can be made short, I don't want to type it more than once as a key to a map lookup in a data source. Probably I just need to wait for some movement in count and that would dry up my code. Many thanks for your considered reply. |
Although some of the details are different, I think this is basically the same use-case as #3267, or at least is likely to be addressed in the same way as we're discussing over there. I'm going to close this one out just to consolidate the discussion. |
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. |
Terraform Version
0.9.5
Affected Resource(s)
All modules
Using self to reference attributes is just as important to modules as resources but it is not available and will throw with
The text was updated successfully, but these errors were encountered: