zarf
zarf copied to clipboard
consider enabling templated variables in import paths
Overview
When working with skeleton package imports, the same import path can be listed many times in a single config:
- name: set-zarf-vars
required: true
import:
name: set-zarf-vars
url: oci://ghcr.io/defenseunicorns/packages/dubbd-rke2:0.10.1-skeleton
- name: preflight
required: true
import:
name: preflight
url: oci://ghcr.io/defenseunicorns/packages/dubbd-rke2:0.10.1-skeleton
- name: load-certs
required: true
import:
name: load-certs
url: oci://ghcr.io/defenseunicorns/packages/dubbd-rke2:0.10.1-skeleton
...
The "problem" is exacerbated in packages with many components. The replication leaves room for error and goes against typical DRY code/configuration practices. Tools like Renovate can help lower the burden of updating with CI automation, but for local development and testing it can still be a chore.
Proposed solution
Ideally, the version number or the full OCI path could be replaced with a variable so that it could easily be changed throughout the config or even passed in at build time:
constants:
- name: DUBBD_OCI
value: "oci://ghcr.io/defenseunicorns/packages/dubbd-rke2:0.10.1-skeleton"
components:
- name: set-zarf-vars
required: true
import:
name: set-zarf-vars
url: "###ZARF_PKG_TMPL_DUBBD_OCI###"
- name: preflight
required: true
import:
name: preflight
url: "###ZARF_PKG_TMPL_DUBBD_OCI###"
- name: load-certs
required: true
import:
name: load-certs
url: "###ZARF_PKG_TMPL_DUBBD_OCI###"
...
Currently variable templating does not support variables in import paths.
Workaround
We are currently working around the issue using YAML anchors (thanks @Noxsios!), but it should be noted that this violates the zarf yaml schema which will cause trouble with linting:
x-dubbd-oci: &dubbd_version "oci://ghcr.io/defenseunicorns/packages/dubbd-rke2:0.14.0-skeleton"
components:
- name: set-zarf-vars
required: true
import:
name: set-zarf-vars
url: *dubbd_version
...
Assuming we make this change we also have to change zarf prepare lint
to no longer warn that url: "###ZARF_PKG_TMPL_DUBBD_OCI###"
won't be evaluated
This can safely be closed now that x-
is allowed in zarf.yaml
's schema.
Simple usages of YAML anchors like this is a well supported and documented feature of the YAML spec.