diff --git a/README.md b/README.md index 853159b..0c96adb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ # puppet-hashi_stack -This module contains shared code for various HashiCorp modules + +[![Puppet Forge](https://img.shields.io/puppetforge/v/puppet/hashi_stack.svg)](https://forge.puppetlabs.com/puppet/hashi_stack) +[![Puppet Forge - downloads](https://img.shields.io/puppetforge/dt/puppet/hashi_stack.svg)](https://forge.puppetlabs.com/puppet/hashi_stack) +[![Puppet Forge - endorsement](https://img.shields.io/puppetforge/e/puppet/hashi_stack.svg)](https://forge.puppetlabs.com/puppet/hashi_stack) +[![Puppet Forge - scores](https://img.shields.io/puppetforge/f/puppet/hashi_stack.svg)](https://forge.puppetlabs.com/puppet/hashi_stack) +[![puppetmodule.info docs](http://www.puppetmodule.info/images/badge.png)](http://www.puppetmodule.info/m/puppet-hashi_stack) +[![Apache-2.0 License](https://img.shields.io/github/license/voxpupuli/puppet-hashi_stack.svg)](LICENSE) + +### What This Module Affects + +* Installs the hashicorp repositories + +## Reference + +See [REFERENCE](REFERENCE.md). + +## Limitations + +Depends on the JSON gem, or a modern ruby. (Ruby 2.5 and newer are supported) + +## Development + +Vox Pupuli welcomes new contributions to this +module, especially those that include documentation and rspec tests. We are +happy to provide guidance if necessary. + +Open an [issue](https://github.com/voxpupuli/puppet-hashi_stack/issues) or +[fork](https://github.com/voxpupuli/puppet-hashi_stack/fork) and open a +[Pull Request](https://github.com/voxpupuli/puppet-hashi_stack/pulls) diff --git a/manifests/repo.pp b/manifests/repo.pp index 12802e3..7a38076 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -1,2 +1,56 @@ +# hashi_stack::repo # -class hashi_stack::repo {} +# @summary Set up the package repository for the HashiCorp Stack components +# +# @example +# include hashi_stack::repo +# +# @param priority A numeric priority for the repo, passed to the package management system +# @param proxy The URL of a HTTP proxy to use for package downloads (YUM only) +# @param base_repo_url The base url for the repo path +class hashi_stack::repo ( + Optional[Integer] $priority = undef, + String $proxy = 'absent', +) { + $key_id='E8A032E094D8EB4EA189D270DA418C88A3219F7B' + $key_source='https://apt.releases.hashicorp.com/gpg' + $description='HashiCorp package repository.' + + case $facts['os']['family'] { + 'Debian': { + include apt + + apt::source { 'HashiCorp': + ensure => 'present', + architecture => 'amd64', + comment => $description, + location => 'https://apt.releases.hashicorp.com', + release => 'stable', + repos => 'main', + key => { + 'id' => $key_id, + 'source' => $key_source, + }, + include => { + 'deb' => true, + 'src' => false, + }, + pin => $priority, + } + } + 'RedHat', 'Linux': { + yumrepo { 'HashiCorp': + descr => $description, + baseurl => 'https://rpm.releases.hashicorp.com/RHEL/$releasever/$basearch/stable', + gpgcheck => 1, + gpgkey => $key_source, + enabled => 1, + proxy => $proxy, + priority => $priority, + } + } + default: { + fail("\"${module_name}\" provides no repository information for OSfamily \"${facts['os']['family']}\"") + } + } +} diff --git a/spec/acceptance/standard_spec.rb b/spec/acceptance/standard_spec.rb new file mode 100644 index 0000000..f6c146f --- /dev/null +++ b/spec/acceptance/standard_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper_acceptance' + +describe 'hashi_stack::repo class' do + + context 'default parameters' do + # Using puppet_apply as a helper + it 'should work with no errors based on the example' do + pp = <<-EOS + class { 'hashi_stack::repo': } + EOS + + # Run it twice and test for idempotency + expect(apply_manifest(pp).exit_code).to_not eq(1) + expect(apply_manifest(pp).exit_code).to eq(0) + end + end +end diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index a32cf8d..3cb9ee7 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -1,9 +1,8 @@ require 'spec_helper' -describe 'nomad' do +describe 'hashi_stack::repo' do on_supported_os.each do |os, os_facts| context "on #{os}" do - let(:facts) { os_facts.merge(service_provider: 'systemd') } end end -end \ No newline at end of file +end