During templating, can I cause an error to be rais...
# 🤖|ask-kapa
g
@microscopic-river-74022 During templating, can I cause an error to be raised? The use case would be to have an if statement where one branch is not permitted. An error would be raised, preventing Garden from continuing
m
Please stand by @glamorous-kangaroo-20427 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- Yes, you can cause an error to be raised during templating in Garden. If a template string resolves to an undefined value, an error is thrown by default. This can be used to prevent Garden from continuing if a certain condition is not met. For example, if you have an
if
statement in your configuration and one branch is not permitted, you can use a template string that will resolve to an undefined value in that branch. This will cause an error to be thrown and Garden will stop. Here is an example of how you can use a template string in your configuration:
Copy code
yaml
kind: Project
providers:
  - name: kubernetes
    kubeconfig: ${var.kubeconfig}
In this example, if
var.kubeconfig
is not defined, Garden will throw an error and stop. However, please note that if you want to allow a template string to resolve to an undefined value without throwing an error, you can do so by adding a
?
after the template, like so:
Copy code
yaml
kind: Project
providers:
  - name: kubernetes
    kubeconfig: ${var.kubeconfig}?
In this case, if
var.kubeconfig
is not defined, no error will be thrown and Garden will continue with the default value for the field in question. For more information, you can refer to the Garden documentation on variables and templating (). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted