From 070d2952a2d730b5038a0ae42333891731fd6433 Mon Sep 17 00:00:00 2001
From: Thomas Bellman <bellman@nsc.liu.se>
Date: Mon, 6 May 2024 09:09:55 +0200
Subject: [PATCH] Forbid not giving $config param to named_vhost.

THIS IS NOT A BACKWARDS-COMPATIBLE CHANGE!  USERS MAY NEED TO CHANGE
THEIR MANIFESTS WHEN UPGRADING!

Previously, we had actually allowed users to not specify any config
for apache::named_vhost.  The reason for having a default value for
the config parameter was, as far as I can remember, so users could
specify ensure => absent and not have to specify the config parameter.

But in practice it worked, because the string value of nil in Ruby
(i.e, ``nil.to_s'') is the empty string, and nil is used to represent
the Puppet value ``undef''.

The previous commit broke that, and you would then get the error
message "undefined method `split' for nil:NilClass" when Puppet tried
to evaluate the named_vhost.conf.erb template.  Without telling which
apache::named_vhost resource that was causing it.

I think it is better to force users to be explicit, so they have to
specify "config => []" if they want to have an empty <VirtualHost>
declaration.  And to get a message that tells them explicitly what
the error is if they don't.  So add a check to apache::named_vhost
that catches this.

As mentioned above, this is not a backwards-compatible change.  Users
who relied on not specifying the 'config' parameter, must change their
manifests to specify it as the empty string or the empty list.  But at
least it is not a silent change; users will get an error message saying
what is wrong.
---
 manifests/named_vhost.pp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/manifests/named_vhost.pp b/manifests/named_vhost.pp
index 64a060b..8758977 100644
--- a/manifests/named_vhost.pp
+++ b/manifests/named_vhost.pp
@@ -61,6 +61,9 @@ define apache::named_vhost($urls,
     case $ensure
     {
 	'present': {
+	    if ($config == undef  or  $config == false) {
+		fail("Apache::Named_vhost[${title}]: Config not specified")
+	    }
 	    if $certname {
 		include x509certs
 	    }
-- 
GitLab