Using user defined variable in backend definition?

Batanun B batanun at hotmail.com
Mon Aug 24 17:42:05 UTC 2020


Hi,

I'm experimenting with user defined variables, and when using them in regular string concatenation, and in synch output, it works fine. But I would like to use them in the backend definitions, and I simply can't get it to work.

backend myBackend {
    .host = var.get("myBackendHost");
}

But that fails with a VCC-compiler error on that line, saying "Expected CSTR got 'var.get'".
I also tried with the "variable" vmod, but it resulted in the same type of error.

Is there any way to get this to work? I would really like to have all environment specific configuration (including backend hostnames) in an environment specific vcl file, and then include it in the main vcl where the backend definitions should be (and use the variables).  And I would like to achive this using just VCL (and vmods), so no custom script that does search and replace or anything like that.

So, I would like something like this to work:

default.vcl:
...
import var;

include "environment.vcl";

backend myBackend {
    .host = var.get("myBackendHost");
}
...

environment.vcl:
sub vcl_init {
    var.set("myBackendHost", "myHostName");
}





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20200824/af699b28/attachment.html>


More information about the varnish-misc mailing list