Using user defined variable in backend definition?

Dridi Boukelmoune dridi at varni.sh
Tue Aug 25 12:59:44 UTC 2020


On Tue, Aug 25, 2020 at 9:20 AM Batanun B <batanun at hotmail.com> wrote:
>
> On Mon, Aug 24, 2020 at 11:07 PM Dridi Boukelmoune <dridi at varni.sh> wrote:
>
> > Hi,
> >
> > You can't do that, but you can move the backend definition inside
> > environment.vcl instead to keep your default.vcl the same across all
> > environments.
>
> Hi,
>
> Too bad... Strange thing to require hard coded strings. Is there a technical reason for that?

Yes, definitions need to be constant!

> Yeah, I actually ended up doing just that, moving the entire backend definition to the separate file. But I would have preferred having the base structure in the main vcl file, and only the actual host names (and other environment specific configuration) in the separate vcl file. Also, if they were variables, I would be able to use them elsewhere in the vcl (like in synth output, which was my main goal originally). If I want to do that now, I would have to define the same host name multiple times.

I guess, what you want is constants:

https://github.com/varnishcache/varnish-cache/pull/3134

Specifically, from this example, but redacted to remove test-case syntax:

https://github.com/varnishcache/varnish-cache/pull/3134/files#diff-996416d1d725c18f8a7bf688cc2f4a52

environment.vcl:
    const string be_host = "example.com";
    const duration be_tmo = 3s;

main vcl:
    vcl 4.1;

    include "environment.vcl";

    backend be {
        .host = be_host;
        .connect_timeout = be_tmo;
    }

Right now you have the option of either moving the whole backend
definition inside environment.vcl or treat your VCL as a template and
populate the environment-specific parts at some stage of your
deployment pipeline.

Cheers,
Dridi


More information about the varnish-misc mailing list