fresh-angle-76971
08/13/2025, 8:55 AMCould not find key kubeconfig under var
error when running garden validate
for the following project config?
apiVersion: garden.io/v2
kind: Project
name: pulumi
environments:
- name: init
- name: dev
providers:
- name: pulumi
version: null # use whatever is in path
useNewPulumiVarfileSchema: true
- name: kubernetes
buildMode: cluster-buildkit
kubeconfig: ${var.kubeconfig}? # use $KUBECONFIG if deployment doesn't set this explicitly
It should work according to docs, it's actually the example listed there: https://docs.garden.io/features/variables-and-templating#optional-valuesmicroscopic-river-74022
08/13/2025, 8:55 AMmicroscopic-river-74022
08/13/2025, 8:55 AM${var.kubeconfig}?
in the kubeconfig
field should make the value optional, so Garden should not throw an error if the variable is not set. This is explicitly documented and even shown as an example in the official docs:
yaml
kind: Project
providers:
- name: kubernetes
kubeconfig: ${var.kubeconfig}?
This is useful when you don't want to provide any value unless one is explicitly set, effectively falling back to whichever the default is for the field in question [Features > Variables and Templating > Optional values]().
If you are still getting the error Could not find key kubeconfig under var
when running garden validate
, this suggests one of the following:
- You may be using a version of Garden that does not support the optional template syntax (?
). Make sure you are using a version that includes this feature, as documented.
- There could be a bug or regression in the version you are using.
- The error may be coming from a different part of your configuration or a different provider/module that expects var.kubeconfig
to be set.
What you can do:
1. Double-check your Garden version and ensure it matches the documentation you are referencing.
2. Try running with a minimal config (just the example from the docs) to isolate the issue.
3. If the problem persists and you are on a supported version, consider reporting it as a bug, since the documented behavior is that the optional value should not cause a validation error if unset.microscopic-river-74022
08/13/2025, 8:55 AMmicroscopic-river-74022
08/13/2025, 8:55 AMfresh-angle-76971
08/13/2025, 9:10 AMmicroscopic-river-74022
08/13/2025, 9:10 AMmicroscopic-river-74022
08/13/2025, 9:10 AM${var.kubeconfig}?
) is being removed in Garden 0.14. The documentation for Garden 0.14 (Cedar) and the deprecation guides state that you should use explicit fallback values instead, such as ${var.kubeconfig || null}
. The ?
syntax is supported in Garden 0.13 (Bonsai) and earlier, but not in 0.14 and later:
> The optional template expression syntax will be removed in Garden 0.14. Use explicit fallback values instead, e.g. ${var.foo || null}
[Bonsai-0.13 > Guides > Deprecations and updating to Cedar > Template Language]().
So, since you are running Garden 0.14.6, the ${var.kubeconfig}?
syntax is not supported. You should update your configuration to use the new fallback syntax:
yaml
kubeconfig: ${var.kubeconfig || null}
This will ensure compatibility with Garden 0.14 and later.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
08/13/2025, 9:10 AMmicroscopic-river-74022
08/13/2025, 9:13 AMfresh-angle-76971
08/13/2025, 9:13 AMmicroscopic-river-74022
08/13/2025, 9:13 AMnpm run build
before pushing to update the Table of Contents.
5. Open a pull request and request a review from the maintainers.
You can find more details and guidelines in the docs, including how the documentation is structured and where to make changes. If you prefer, you can also report a bug or inconsistency by opening an issue in the Garden GitHub repository [Edge-release > Contributing to the Docs]().
For more information on how to contribute or report issues, see the relevant section in the documentation:
[How our docs are structured]().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
08/13/2025, 9:13 AM