microscopic-river-74022
01/24/2024, 10:02 AMmicroscopic-river-74022
01/24/2024, 10:02 AMyaml
spec:
image:
$if: "${local.env.GARDEN_DEV_SERVICE == 'gateway'}"
$then: "${var.registryRoot + '/api-gateway:latest'}"
$else: "${actions.build.gateway.outputs.deploymentImageId}"
This sets spec.image
to ${var.registryRoot + '/api-gateway:latest'}
when the GARDEN_DEV_SERVICE
environment variable is set to 'gateway', otherwise it sets spec.image
to ${actions.build.gateway.outputs.deploymentImageId}
.
However, if GARDEN_DEV_SERVICE
is not provided at all, Garden will still throw an error. To avoid this, you can use the local.env.<env-var-name>
syntax to check if the environment variable exists before using it in a condition. Unfortunately, the extracts provided do not contain information on how to do this.
For more information on using if/else conditionals and environment variables in Garden, you can refer to the Variables and Templating () section of the Garden documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
01/24/2024, 10:09 AMquaint-dress-831
01/24/2024, 10:09 AM${local.env.GARDEN_DEV_SERVICE == 'gateway'}
as an optional value e.g.
${var.kubeconfig}?
microscopic-river-74022
01/24/2024, 10:09 AMGARDEN_DEV_SERVICE
as an optional value using the ?
operator. Here's how you can do it:
yaml
spec:
image:
$if: "${{local.env.GARDEN_DEV_SERVICE? == 'gateway'}}"
$then: "${{var.registryRoot + '/api-gateway:latest'}}"
$else: "${{actions.build.gateway.outputs.deploymentImageId}}"
In this case, if GARDEN_DEV_SERVICE
is not provided, Garden will not throw an error and the condition will evaluate to false, setting spec.image
to ${{actions.build.gateway.outputs.deploymentImageId}}
.
For more information on using optional values in Garden, you can refer to the Optional values () section of the Garden documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------flat-state-47578
01/24/2024, 10:13 AMflat-state-47578
01/24/2024, 10:14 AMquaint-dress-831
01/24/2024, 10:14 AMquaint-dress-831
01/24/2024, 10:15 AMquaint-dress-831
01/24/2024, 10:17 AMflat-state-47578
01/25/2024, 2:53 AMflat-state-47578
01/25/2024, 3:17 AM?
syntax is valid:
Invalid template string (${{local.env.GARDEN_DEV_SERVICE? =…): Unable to parse as valid template string.