Skip to content

Commit

Permalink
Allow caddy::vhost to be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
jay7x committed Dec 14, 2024
1 parent fe090ae commit 40f2d1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
13 changes: 11 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,22 +394,31 @@ caddy::vhost { 'example2:

The following parameters are available in the `caddy::vhost` defined type:

* [`ensure`](#-caddy--vhost--ensure)
* [`source`](#-caddy--vhost--source)
* [`content`](#-caddy--vhost--content)

##### <a name="-caddy--vhost--ensure"></a>`ensure`

Data type: `Enum['present','absent']`

Make the vhost either present or absent

Default value: `'present'`

##### <a name="-caddy--vhost--source"></a>`source`

Data type: `Optional[Stdlib::Filesource]`

source (path) for the caddy vhost configuration
Source (path) for the caddy vhost configuration

Default value: `undef`

##### <a name="-caddy--vhost--content"></a>`content`

Data type: `Optional[String]`

string with the caddy vhost configuration
String with the caddy vhost configuration

Default value: `undef`

11 changes: 8 additions & 3 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# @summary This defined type handles the Caddy virtual hosts.
#
# @param source source (path) for the caddy vhost configuration
# @param content string with the caddy vhost configuration
# @param ensure
# Make the vhost either present or absent
# @param source
# Source (path) for the caddy vhost configuration
# @param content
# String with the caddy vhost configuration
#
# @example Configure virtual host, based on source
# caddy::vhost { 'example1':
Expand All @@ -14,12 +18,13 @@
# }
#
define caddy::vhost (
Enum['present','absent'] $ensure = 'present',
Optional[Stdlib::Filesource] $source = undef,
Optional[String] $content = undef,
) {
include caddy
file { "/etc/caddy/config/${title}.conf":
ensure => file,
ensure => stdlib::ensure($ensure, 'file'),
content => $content,
source => $source,
mode => '0444',
Expand Down
19 changes: 9 additions & 10 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

context 'with source' do
let(:title) { 'example1' }
let(:params) do
{
source: 'puppet:///modules/caddy/etc/caddy/config/example1.conf'
}
end
let(:params) { { source: 'puppet:///modules/caddy/etc/caddy/config/example1.conf' } }

it do
expect(subject).to contain_file('/etc/caddy/config/example1.conf').with(
Expand All @@ -30,11 +26,7 @@

context 'with content' do
let(:title) { 'example2' }
let(:params) do
{
content: 'localhost:2015'
}
end
let(:params) { { content: 'localhost:2015' } }

it do
expect(subject).to contain_file('/etc/caddy/config/example2.conf').with(
Expand All @@ -46,6 +38,13 @@
)
end
end

context 'with ensure => absent' do
let(:title) { 'example3' }
let(:params) { { ensure: 'absent' } }

it { expect(subject).to contain_file('/etc/caddy/config/example3.conf').with_ensure('absent') }
end
end
end
end

0 comments on commit 40f2d1d

Please sign in to comment.