diff --git a/REFERENCE.md b/REFERENCE.md
index d51eda0..ee101b9 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -21,6 +21,10 @@
* [`caddy::vhost`](#caddy--vhost): This defined type handles the Caddy virtual hosts.
+### Data types
+
+* [`Caddy::VirtualHost`](#Caddy--VirtualHost): Caddy virtual host type
+
## Classes
### `caddy`
@@ -92,6 +96,7 @@ The following parameters are available in the `caddy` class:
* [`caddyfile_content`](#-caddy--caddyfile_content)
* [`config_dir`](#-caddy--config_dir)
* [`purge_config_dir`](#-caddy--purge_config_dir)
+* [`vhosts`](#-caddy--vhosts)
##### `version`
@@ -384,6 +389,14 @@ Whether to purge Caddy config directory.
Default value: `true`
+##### `vhosts`
+
+Data type: `Hash[String[1], Caddy::VirtualHost]`
+
+List of virtual hosts to create.
+
+Default value: `{}`
+
## Defined types
### `caddy::vhost`
@@ -449,3 +462,19 @@ Where to store the vhost config file
Default value: `$caddy::config_dir`
+## Data types
+
+### `Caddy::VirtualHost`
+
+Caddy virtual host type
+
+Alias of
+
+```puppet
+Struct[{
+ ensure => Optional[Enum['absent', 'present']],
+ source => Optional[Stdlib::Filesource],
+ content => Optional[String[1]],
+}]
+```
+
diff --git a/manifests/init.pp b/manifests/init.pp
index 036df60..ec49d5f 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -126,6 +126,9 @@
# @param purge_config_dir
# Whether to purge Caddy config directory.
#
+# @param vhosts
+# List of virtual hosts to create.
+#
class caddy (
String[1] $version = '2.0.0',
Optional[Enum['github','repo']] $install_method = undef,
@@ -163,6 +166,7 @@
Optional[Stdlib::Filesource] $caddyfile_source = undef,
Optional[String[1]] $caddyfile_content = undef,
Boolean $purge_config_dir = true,
+ Hash[String[1], Caddy::VirtualHost] $vhosts = {},
) {
case $caddy_architecture {
'x86_64', 'amd64': { $arch = 'amd64' }
@@ -199,6 +203,12 @@
contain caddy::config
contain caddy::service
+ $vhosts.each |String[1] $name, Caddy::VirtualHost $vhost| {
+ caddy::vhost { $name:
+ * => $vhost,
+ }
+ }
+
Class['caddy::install']
-> Class['caddy::config']
~> Class['caddy::service']
diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb
index 78fae0d..08b054e 100644
--- a/spec/classes/init_spec.rb
+++ b/spec/classes/init_spec.rb
@@ -351,6 +351,28 @@
is_expected.to contain_file('/etc/caddy/Caddyfile').with_source('http://example.com/Caddyfile').with_content(nil)
end
end
+
+ context 'with vhosts set' do
+ let(:params) do
+ {
+ vhosts: {
+ 'h1.example.com': {
+ source: 'http://example.com/test-example-com.conf',
+ },
+ 'h2.example.com': {
+ content: "localhost:1234{\n file_server\n}\n",
+ },
+ 'h3.example.com': {
+ ensure: 'absent',
+ }
+ }
+ }
+ end
+
+ it { is_expected.to contain_file('/etc/caddy/config/h1.example.com.conf').with_source('http://example.com/test-example-com.conf') }
+ it { is_expected.to contain_file('/etc/caddy/config/h2.example.com.conf').with_content("localhost:1234{\n file_server\n}\n") }
+ it { is_expected.to contain_file('/etc/caddy/config/h3.example.com.conf').with_ensure('absent') }
+ end
end
end
end
diff --git a/types/virtualhost.pp b/types/virtualhost.pp
new file mode 100644
index 0000000..8b5dd04
--- /dev/null
+++ b/types/virtualhost.pp
@@ -0,0 +1,6 @@
+# @summary Caddy virtual host type
+type Caddy::VirtualHost = Struct[{
+ ensure => Optional[Enum['absent', 'present']],
+ source => Optional[Stdlib::Filesource],
+ content => Optional[String[1]],
+}]