Freeform area to set up YAML anchors

I have a series of several cron jobs with similar configurations that I’m trying to set up in render.yaml. Since they’re so similar, it would be great to use YAML anchors & references to reduce the amount of boilerplate. For example, I’d love to do something like:

variables:
  # This just sets up a re-usable dictionary, but doesn't configure an
  # actual service. This way, each service can have a smaller definition.
  base-cron-config: &base-cron-config
    type: cron
    env: node
    plan: standard
    autoDeploy: true
    repo: https://github.com/my-org/my-repo.git
    buildCommand: 'npm install'
    envVars:
      - fromGroup: env-var-group-name

services:
  - <<: *base-cron-config
    name: Job 1
    schedule: '0 0/3 * * *'
    startCommand: npm run some-script

  - <<: *base-cron-config
    name: Job 2
    plan: starter plus  # Different resource needs
    schedule: '0/20 * * * *'
    startCommand: 'npm run another-script'

However, when I try to add this as a blueprint, I get an error message about variables being an unknown key.

Instead, I’ve done the following, but it makes the first cron job pretty messy. It also means I have to be careful to make sure every subsequent cron sets every option that the first one does (even if it’s just effectively resetting it to the default). I’d love to separate out the common parts entirely like above.

services:
  - &base-cron-config
    name: Job 1
    schedule: '0 0/3 * * *'
    startCommand: npm run some-script
    type: cron
    env: node
    plan: standard
    autoDeploy: true
    repo: https://github.com/my-org/my-repo.git
    buildCommand: 'npm install'
    envVars:
      - fromGroup: env-var-group-name

  - <<: *base-cron-config
    name: Job 2
    plan: starter plus  # Different resource needs
    schedule: '0/20 * * * *'
    startCommand: 'npm run another-script'

Is there any way I can do top version of this today (i.e. some “neutral” part of the YAML file I could define things in)?

Hi @Mr0grog, I can totally see where you’re coming from with this request. Unfortunately our current parser is strict about the top-level fields it accepts. If you’d like to see us change this, I’d recommend adding a feature request on our feedback page (https://feedback.render.com).

As a workaround, you could put the YAML with the variables field in a different file and then “compile” it to a render.yaml file. For example:

yq -y '{"services": .services}' render-with-variables.yaml > render.yaml

If you want to make sure you don’t forget to run this step you could use a pre-commit hook. I hope this helps! Don’t hesitate to follow up with more questions.

Thanks! Glad to know I’m at least not missing something that would already do this. :slight_smile:

I filed a feature request for this.

1 Like

this is really useful one