var.* on the environment level
# 🌱|help-and-getting-started
n
Hello. I'm insecure is it bug or feature that's why I decided to write here first. I use individual variables set with --var in CLI flags and define it on the environments level in the project file but I have the error. For example: use this command -> garden deploy --var name=username have this line in project file -> defaultNamespace: user-${var.name} get this error -> Invalid template string (user-${var.name}): Could not find key name under var.
b
Hey @nutritious-kitchen-29367 sorry for taking so long to answer this issue, I see that this command is documented in our docs but I can't see it reflected when I'm running it with my CLI. I'm going to reach back to the OSS Devs to ask about this problem. For the time being here are a couple of workarounds you could try: 1. Create a
garden.env
file and store your variables there in a KEY=VALUE format. 2. You can set variables at the environment level using this structure: https://docs.garden.io/reference/project-config#environments-.variables 3. You can also set variables at the project level by using: https://docs.garden.io/reference/project-config#variables I hope that helps for the time being!
Hey @nutritious-kitchen-29367 I was able to reproduce the scenario and setting variables with --var works for me! Would you mind giving it a try, maybe you can use this simple project to compare with yours and find the issue? https://github.com/ShankyJS/cli-env-vars
n
Hello Shanky. Thanks for answer. Your scenario works because you use var - "installCRDs" in the module level. I spoke about environment level. If you define var in the project.garden.yml I supose you will have the same error as like me.
b
Is it possible that you could share some pieces of your garden config to try to reproduce it? I think I get your idea, basically it fails if you set an environment variable at the env level but you override it with the —var flag?
n
b
Hey @nutritious-kitchen-29367 I was able to reproduce this issue, you are right. It seems like we are not being able to provide variables that are added as an argument to the deploy command specifically to the defaultNamespace field. https://github.com/ShankyJS/cli-env-vars A little workaround that you could use to fix this issue is; Instead of doing:
defaultNamespace: user-${var.name}
you can do
defaultNamespace: user-${local.user}
which will resolve to the user of the terminal you are using ($USER) or $WHOAMI. Also, I would like to ask you if you would be open to submit a
Bug
directly into our Github repository so the Core Developers can tackle this issue as part of future releases? Thanks a lot!
n
Thanks a lot. I will submit a bug.
b
Hey @nutritious-kitchen-29367 where you able to submit a bug for this one? ❤️
h
Ahh just ran into this issue for the exact same scenario (trying to set
defaultNamespace
) Was an issue made for this?
the workaround I'm using is environment variables which seems to work (e.g.
local.env.NAMESPACE
)
b
Sadly Ruslan wasn’t able to submit the issue, would you be able to create it?✨
3 Views