<div dir="ltr">Hi,<div><br></div><div>The trouble is that the backends are C structures created when you compile the VCL, but std.getenv() is called when you use the compile VCL, so that way too late.</div><div><br></div><div>I see two ways:</div><div>- use a dynamic backend vmod (like vmod_goto), allowing you to regularly interrogate DNS a build an elastic director</div><div>- create a static backend point to you k8s proxy, and just set req.http.host to whatever value you want.</div><div><br></div><div>The last one is two of course create a template, but remember that varnish resolves domain names in static backend when it compiles the VCL, so the resolved IP may not be right all the time.</div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div>Guillaume Quintard<br></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 10, 2019 at 2:17 AM Bender, Charles <<a href="mailto:charles@beachcamera.com">charles@beachcamera.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_-6601299274450483237WordSection1">
<p class="MsoNormal">Looking at a VCL I use to set hostname and this seems to work-<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">sub vcl_deliver {<u></u><u></u></p>
<p class="MsoNormal"> set resp.http.X-Cache-Node = server.hostname;<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Maybe you can use in form of server.environmental_variable<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12pt;color:black">From: </span></b><span style="font-size:12pt;color:black">varnish-misc <varnish-misc-bounces+charles=<a href="mailto:beachcamera.com@varnish-cache.org" target="_blank">beachcamera.com@varnish-cache.org</a>> on behalf of Hugues Alary <<a href="mailto:hugues@betabrand.com" target="_blank">hugues@betabrand.com</a>><br>
<b>Date: </b>Monday, September 9, 2019 at 6:09 PM<br>
<b>To: </b>varnish-misc <<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a>><br>
<b>Subject: </b>Environment variables in VCL<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">Hi there, <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I'm using Varnish in a Kubernetes cluster and my configuration needs to use environment variables.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">More specifically, I'm trying to declare a `backend` with a `.host` whose value is an environment variable.<u></u><u></u></p>
</div>
<p class="MsoNormal"><br>
<span style="font-family:"Courier New"">backend b0 {<br>
.host = "<b>$ENVIRONMENT_VARIABLE_HOSTNAME</b>";<br>
.port = "80";<br>
.connect_timeout = 300s;<br>
.first_byte_timeout = 300s;<br>
.between_bytes_timeout = 300s;</span><u></u><u></u></p>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">}</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This doesn't work. It tried using the std.get_env() function but it doesn't work in this context.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><b>Is there any way to use environment variables in VCL, or do I have to create a configuration template?</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks for your help,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">-Hugues<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
</blockquote></div>