Can $merge be used multiple times within the same ...
# 🤖|ask-kapa
g
@microscopic-river-74022 Can $merge be used multiple times within the same mapping?
m
Please stand by @glamorous-kangaroo-20427 as I search the knowledge base. I normally take about 15 seconds or so. :wave:
---------------------- Yes, the
$merge
key can be used multiple times within the same mapping in Garden. The
$merge
key allows you to merge two objects together and can be used to avoid repeating a set of commonly repeated values. However, the position of the
$merge
key matters. If the keys being merged overlap between the two objects, the value that's defined later is chosen. Here's an example from the Garden documentation ():
Copy code
yaml
kind: Project
variables:
  - commonEnvVars:
      LOG_LEVEL: info
      SOME_API_KEY: abcdefg
      EXTERNAL_API_URL: <http://api.example.com>
Copy code
yaml
kind: Deploy
type: container
name: service-a
spec:
  env:
    $merge: ${var.commonEnvVars}
    OTHER_ENV_VAR: something
    LOG_LEVEL: debug  # <- This overrides the value set in commonEnvVars, because it is below the $merge key
---
kind: Deploy
type: container
name: service-b
services:
  env:
    SOME_API_KEY: default # <- Because this is above the $merge key, the API_KEY from commonEnvVars will override this
    $merge: ${var.commonEnvVars}
In this example, the
$merge
key is used to share a common set of environment variables between two services. The
LOG_LEVEL
in
service-a
and
SOME_API_KEY
in
service-b
are overridden because they are defined after the
$merge
key. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
g
@microscopic-river-74022 That doesn't show using the
$merge
key multiple times within the same mapping.
m
Let me check the knowledge base for you again. One moment! :books:
---------------------- I apologize for the confusion. You're correct, the provided example does not demonstrate the use of
$merge
multiple times within the same mapping. Unfortunately, none of the provided knowledge sources explicitly demonstrate or discuss using
$merge
multiple times within the same mapping. For the most accurate and detailed information, I would recommend referring to the official Garden documentation or reaching out to the Garden community for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
message has been deleted
4 Views