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

Self variables are only valid on resources #14684

Closed
scriptjs opened this issue May 19, 2017 · 6 comments
Closed

Self variables are only valid on resources #14684

scriptjs opened this issue May 19, 2017 · 6 comments

Comments

@scriptjs
Copy link

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

invalid scope, self variables are only valid on resources
@apparentlymart
Copy link
Contributor

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 connection blocks and provisioner blocks, but neither of these are relevant to modules.

@scriptjs
Copy link
Author

scriptjs commented May 19, 2017

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.

@apparentlymart
Copy link
Contributor

@scriptjs today a resource cannot refer to its own attributes with self. It's used only for referring to the resource from a provisioner or connection block, like this:

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?

@scriptjs
Copy link
Author

scriptjs commented May 19, 2017

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.

@apparentlymart
Copy link
Contributor

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.

@ghost
Copy link

ghost commented Jul 25, 2019

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 Jul 25, 2019
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