Skip to content

Commit cbeef5f

Browse files
authored
Manage config file (#156)
* added ability to not let the puppet module manage the config file. I need to install Vault Agent, which requires a different services file and config file. I am having to set manage_service_file and manage_service to false, but the config file is still being generated. * Added detail in README, and added spec * Changed per PR feedback
1 parent dcf58c1 commit cbeef5f

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Please see [The official documentation](https://www.vaultproject.io/docs/configu
6262

6363
* `manage_service_file`: Manages the service file regardless of the defaults. Default: See [Installation parameters](#installation-parameters).
6464

65+
* `manage_config_file`: Manages the configuration file. When set to false, `config.json` will not be generated. `manag_storage_dir` is ignored. Default: `true`
66+
6567
### Installation parameters
6668

6769
#### When `install_method` is `repo`

manifests/config.pp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@
44
#
55
class vault::config {
66

7-
$_config_hash = delete_undef_values({
8-
'listener' => $::vault::listener,
9-
'storage' => $::vault::storage,
10-
'ha_storage' => $::vault::ha_storage,
11-
'seal' => $::vault::seal,
12-
'telemetry' => $::vault::telemetry,
13-
'disable_cache' => $::vault::disable_cache,
14-
'default_lease_ttl' => $::vault::default_lease_ttl,
15-
'max_lease_ttl' => $::vault::max_lease_ttl,
16-
'disable_mlock' => $::vault::disable_mlock,
17-
'ui' => $::vault::enable_ui,
18-
'api_addr' => $::vault::api_addr,
19-
})
20-
21-
$config_hash = merge($_config_hash, $::vault::extra_config)
22-
237
file { $::vault::config_dir:
248
ensure => directory,
259
purge => $::vault::purge_config_dir,
@@ -28,26 +12,45 @@
2812
group => $::vault::group,
2913
}
3014

31-
file { "${::vault::config_dir}/config.json":
32-
content => to_json_pretty($config_hash),
33-
owner => $::vault::user,
34-
group => $::vault::group,
35-
mode => $::vault::config_mode,
36-
}
15+
if $::vault::manage_config_file {
3716

38-
# If using the file storage then the path must exist and be readable
39-
# and writable by the vault user, if we have a file path and the
40-
# manage_storage_dir attribute is true, then we create it here.
41-
#
42-
if $::vault::storage['file'] and $::vault::manage_storage_dir {
43-
if ! $::vault::storage['file']['path'] {
44-
fail('Must provide a path attribute to storage file')
17+
$_config_hash = delete_undef_values({
18+
'listener' => $::vault::listener,
19+
'storage' => $::vault::storage,
20+
'ha_storage' => $::vault::ha_storage,
21+
'seal' => $::vault::seal,
22+
'telemetry' => $::vault::telemetry,
23+
'disable_cache' => $::vault::disable_cache,
24+
'default_lease_ttl' => $::vault::default_lease_ttl,
25+
'max_lease_ttl' => $::vault::max_lease_ttl,
26+
'disable_mlock' => $::vault::disable_mlock,
27+
'ui' => $::vault::enable_ui,
28+
'api_addr' => $::vault::api_addr,
29+
})
30+
31+
$config_hash = merge($_config_hash, $::vault::extra_config)
32+
33+
file { "${::vault::config_dir}/config.json":
34+
content => to_json_pretty($config_hash),
35+
owner => $::vault::user,
36+
group => $::vault::group,
37+
mode => $::vault::config_mode,
4538
}
4639

47-
file { $::vault::storage['file']['path']:
48-
ensure => directory,
49-
owner => $::vault::user,
50-
group => $::vault::group,
40+
# If using the file storage then the path must exist and be readable
41+
# and writable by the vault user, if we have a file path and the
42+
# manage_storage_dir attribute is true, then we create it here.
43+
#
44+
if $::vault::storage['file'] and $::vault::manage_storage_dir {
45+
if ! $::vault::storage['file']['path'] {
46+
fail('Must provide a path attribute to storage file')
47+
}
48+
49+
file { $::vault::storage['file']['path']:
50+
ensure => directory,
51+
owner => $::vault::user,
52+
group => $::vault::group,
53+
}
5154
}
5255
}
5356

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
$manage_group = $::vault::params::manage_group,
7979
$bin_dir = $::vault::params::bin_dir,
8080
$config_dir = $::vault::params::config_dir,
81+
$manage_config_file = $::vault::params::manage_config_file,
8182
$config_mode = $::vault::params::config_mode,
8283
$purge_config_dir = true,
8384
$download_url = $::vault::params::download_url,

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$manage_group = true
1111
$config_dir = '/etc/vault'
1212
$config_mode = '0750'
13+
$manage_config_file = true
1314
$download_url = undef
1415
$download_url_base = 'https://releases.hashicorp.com/vault/'
1516
$download_extension = 'zip'

spec/classes/vault_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,18 @@
317317
}
318318
end
319319

320+
context 'when specifying manage_config_file = false' do
321+
let(:params) do
322+
{
323+
manage_config_file: false,
324+
}
325+
end
326+
327+
it {
328+
is_expected.not_to contain_file ('/etc/vault/config.json')
329+
}
330+
end
331+
320332
context 'when ensuring the service is disabled' do
321333
let(:params) do
322334
{

0 commit comments

Comments
 (0)