I think I found a bug with template strings in Pro...
# 🌱|help-and-getting-started
b
So I'm working on migrating some old modules to 0.13; I use the following syntax in my projects in 0.12
Copy code
apiVersion: garden.io/v1
kind: Project
name: project
defaultEnvironment: local
dotIgnoreFile: .gitignore

variables:
  POSTGRES_USERNAME: postgres
  POSTGRES_DATABASE: postgres
  POSTGRES_PASSWORD: postgres
  POSTGRES_CONNECTION_STRING:  postgres://${var.POSTGRES_USERNAME}:${var.POSTGRES_PASSWORD}@postgres-edge-api-cc:5432/${var.POSTGRES_DATABASE}?schema=public
This used to work in Garden 0.12 which was nice because I could build variables on the flight in the project level variables; now I can't because of the following error
Copy code
garden validate
Validate βœ”οΈ

β„Ή garden                    β†’ Initializing...
β„Ή garden-dashboard          β†’ You are not logged in. To use the Garden dashboard, log in with the garden login command.
β„Ή garden-dashboard          β†’ Learn more at: https://docs.garden.io/using-garden/dashboard
Failed to resolve project configuration.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Invalid template string (postgres://${var.POSTGRES_USERNAME}:${var.POSTGRES_PASSWORD}@postgres-edge-api-cc:5432/${var.POSTGRES_DATABASE}?schema=public) at path variables.POSTGRES_CONNECTION_STRING: Could not find key var. Available keys: command, datetime, git, local, project and secrets.
Which is pretty sad; I don't see a reason why this should have been removed? I tested doing the string templating in the environment level and it worked; which is pretty bad for my use case because I would need to repeat variables in N environments where the value is always going to be the same.... Workaround: Not use variable substitution on the project level but just hardcode the valuess. 😒
c
b
@chilly-gigabyte-83853 I don’t think that answers the variables interpolation problem?
c
Hi @bright-policeman-43626, I am sorry, I was convinced Thor's answer was covering this. I am a bit puzzled by how the first example was working on 0.12, it could have been a feature that should have been a bug, since I don't recall being able to reference variables from within the same block. πŸ€” It seems though that you are absolutely right and that's not possible in 0.13. If I may suggest a way to reduce repetition, it would be to define:
Copy code
POSTGRES_USERNAME: postgres
POSTGRES_DATABASE: postgres
POSTGRES_PASSWORD: postgres
on the
project.variables
level and
POSTGRES_CONNECTION_STRING
as defined above in the action's
variable
block. If the connections parameters change across environments, you could also move the definitions above under
environments[].variables
so you can tweak those based on your env.
b
@bright-policeman-43626 I tested your code with the latest acorn-edge version and it does not work:
Copy code
Running task test πŸƒβ€β™‚οΈ

Invalid template string (postgres://${var.POSTGRES_USERNAME…): Could not find key var. Available keys: command, datetime, git, local,
project and secrets.
Copy code
0.12.71-edge-acorn-992156f3d
2 Views