mirror of
https://github.com/voxpupuli/puppet-hashi_stack.git
synced 2025-05-24 02:45:01 +01:00
feat: initial pass on hcl config
Signed-off-by: Bram Vogelaar <bram@attachmentgenie.com>
This commit is contained in:
parent
2e6986a13f
commit
9ef92100a9
3 changed files with 59 additions and 0 deletions
32
lib/puppet/functions/hashi_stack/to_hcl.rb
Normal file
32
lib/puppet/functions/hashi_stack/to_hcl.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'hcl2-rb'
|
||||||
|
# @summary
|
||||||
|
# Convert a data structure and output it as YAML
|
||||||
|
Puppet::Functions.create_function(:'hashi_stack::to_hcl') do
|
||||||
|
# @param data
|
||||||
|
# The data you want to convert to YAML
|
||||||
|
# @param options
|
||||||
|
# A hash of options that will be passed to Ruby's Psych library. Note, this could change between Puppet versions, but at time of writing these are `line_width`, `indentation`, and `canonical`.
|
||||||
|
#
|
||||||
|
# @example Output YAML to a file
|
||||||
|
# file { '/tmp/my.yaml':
|
||||||
|
# ensure => file,
|
||||||
|
# content => hashi_stack::to_hcl($myhash),
|
||||||
|
# }
|
||||||
|
# @example Use options to control the output format
|
||||||
|
# file { '/tmp/my.yaml':
|
||||||
|
# ensure => file,
|
||||||
|
# content => hashi_stack::to_hcl($myhash, {spaces => 2, tab => 0})
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# @return [String] The YAML document
|
||||||
|
dispatch :to_hcl do
|
||||||
|
param 'Any', :data
|
||||||
|
optional_param 'Hash', :options
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_hcl(data, options = {})
|
||||||
|
data.to_hcl2(options.transform_keys(&:to_sym))
|
||||||
|
end
|
||||||
|
end
|
9
manifests/config_file.pp
Normal file
9
manifests/config_file.pp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# @summary A short summary of the purpose of this defined type.
|
||||||
|
#
|
||||||
|
# A description of what this defined type does
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# hashi_stack::config_file { 'namevar': }
|
||||||
|
define hashi_stack::config_file (
|
||||||
|
) {
|
||||||
|
}
|
18
spec/defines/config_file_spec.rb
Normal file
18
spec/defines/config_file_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'hashi_stack::config_file' do
|
||||||
|
let(:title) { 'namevar' }
|
||||||
|
let(:params) do
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
on_supported_os.each do |os, os_facts|
|
||||||
|
context "on #{os}" do
|
||||||
|
let(:facts) { os_facts }
|
||||||
|
|
||||||
|
it { is_expected.to compile }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue