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

[BUG] Issue with metadata interpretation in stack configuration #692

Closed
joshuacook-tamu opened this issue Nov 3, 2022 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@joshuacook-tamu
Copy link

Describe the bug
I am attempting to define orchestration / dependency relationships between stacks. I defined it via the after statement in the stack config and used the metadata such as ${terramate.stack.path.to_root}. Terramate fails to evaluate stating there is no variable named "terramate"

To Reproduce

Steps to reproduce the behavior:

  1. Define a stack as
 stack {
  name = "test vm"
  after = [
    "${terramate.root.path.fs.absolute}/stacks/resources/vm-admin-keypair",
    #"../../resources/vm-admin-keypair",
    "${terramate.stack.path.to_root}/resources/vm-security-group",
    #"../../resources/vm-security-group",
  ]
 }

Note, I tried two different approaches above, but both fail with the same error.

  1. Run command terramate list
  2. See error
terramate list
2022-11-03T11:50:18-05:00 ERR terramate schema error: loading from /redacted/path/to/stacks: loading from /redacted/path/to/stacks/staging: loading from /redacted/path/to/stacks/staging/redacted: eval expression: failed to evaluate "after" attribute: There is no variable named "terramate". file=/redacted/path/to/stacks/staging/redacted/stack.tm.hcl:4,8-17
2022-11-03T11:50:18-05:00 ERR terramate schema error: loading from /redacted/path/to/stacks: loading from /redacted/path/to/stacks/staging: loading from /redacted/path/to/stacks/staging/redacted: eval expression: failed to evaluate "after" attribute: There is no variable named "terramate". file=/redacted/path/to/stacks/staging/redacted/stack.tm.hcl:6,8-17
2022-11-03T11:50:18-05:00 FTL looking up project root

Expected behavior
A clear and concise description of what you expected to happen.

I expected the variable interpolation to work here as it does in multiple other configuration elements within Terramate. Of course, it will work if I uncomment the lines above with the ../.. and comment out the lines with the Terramate metadata elements. This is what I have done for now.

Log Output
Add logs from Terramate to help debug your problem.

Environment (please complete the following information):

  • OS: MacOS
  • OS Version: 12.6.1
  • Git Version: 2.37.1
  • Terramate Version: 0.1.40
@joshuacook-tamu joshuacook-tamu added the bug Something isn't working label Nov 3, 2022
@mariux
Copy link
Contributor

mariux commented Nov 3, 2022

Hi @joshuacook-tamu,

thanks for sharing. The problem is that terramate namepace is not available in after/before as of today.

We will for sure improve the error message in this case ;) We are actually currently refactoring all output to improve the user experience.

A solution to achieve what you want is to use absolute stack path as after and before do not use file-system paths but project paths by default.

so just using

stack {
  name = "test vm"
  after = [
    "/stacks/resources/vm-admin-keypair",
    "/stacks/resources/vm-security-group",
  ]
}

should do the trick (or /resources if this is the path from root)

@joshuacook-tamu
Copy link
Author

Thanks for the response. I'll do it the way you suggest.

Perhaps this could be converted to a feature request as I would suggest that you support this use case. If you do not plan to support it, at least document the fact that the terramate metadata is not available everywhere within the ecosystem.

Again, thanks for your quick response!

@katcipis
Copy link
Contributor

katcipis commented Nov 4, 2022

Added this information on the stack docs on #693.

@joshuacook-tamu on the apparent inconsistency, it is not without reason. We initially avoided allowing globals and metadata on the stack block because allowing it will introduce the possibility of circular definitions, which are tricky (but possible) to detect and debug, so we opted to constrain the stack block to avoid issues.

But on the future we may provide at least a subset of metadata that is safe (project wide metadata, non stack dependent), or even allow global references and deal with circular definitons.

I would suggest we close this as it is not a bug and maybe create a different issue as a feature request.

@joshuacook-tamu
Copy link
Author

I agree that this is not a bug since you designed it this way. I'll try to open a feature request instead. Thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants