diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..05127f3 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,8 @@ +fixtures: + forge_modules: + stdlib: puppetlabs/stdlib + apt: puppetlabs/apt + yum: puppet/yum + yumrepo_core: + repo: puppetlabs/yumrepo_core + puppet_version: ">= 6.0.0" diff --git a/REFERENCE.md b/REFERENCE.md new file mode 100644 index 0000000..70b0321 --- /dev/null +++ b/REFERENCE.md @@ -0,0 +1,74 @@ +# Reference + + + +## Table of Contents + +### Classes + +* [`hashi_stack::repo`](#hashi_stackrepo): Set up the package repository for the HashiCorp Stack components + +## Classes + +### `hashi_stack::repo` + +This class installs the hashicorp repository + +#### Examples + +##### + +```puppet +include hashi_stack::repo +``` + +##### + +```puppet +class { 'hashi_stack::repo': } -> package { 'packer': ensure => installed } +``` + +#### Parameters + +The following parameters are available in the `hashi_stack::repo` class. + +##### `priority` + +Data type: `Optional[Integer]` + +A numeric priority for the repo, passed to the package management system + +Default value: ``undef`` + +##### `proxy` + +Data type: `String` + +The URL of a HTTP proxy to use for package downloads (YUM only) + +Default value: `'absent'` + +##### `key_id` + +Data type: `String` + +GPG key to authenticate Apt package signatures. + +Default value: `'E8A032E094D8EB4EA189D270DA418C88A3219F7B'` + +##### `key_source` + +Data type: `Stdlib::HTTPSUrl` + +The location of an existing GPG key file to copy. + +Default value: `'https://apt.releases.hashicorp.com/gpg'` + +##### `description` + +Data type: `String` + +Repository description + +Default value: `'HashiCorp package repository.'` + diff --git a/example/init.pp b/example/init.pp new file mode 100644 index 0000000..ed5cde0 --- /dev/null +++ b/example/init.pp @@ -0,0 +1,2 @@ +class { 'hashi_stack::repo': } +-> package { 'packer': ensure => installed } diff --git a/manifests/repo.pp b/manifests/repo.pp index 8e6902b..3ed5ad7 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -5,17 +5,21 @@ # @example # include hashi_stack::repo # +# @example +# class { 'hashi_stack::repo': } -> package { 'packer': ensure => installed } +# # @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 +# @param key_id GPG key to authenticate Apt package signatures. +# @param key_source The location of an existing GPG key file to copy. +# @param description Repository description class hashi_stack::repo ( - Optional[Integer] $priority = undef, - String $proxy = 'absent', + Optional[Integer] $priority = undef, + String $proxy = 'absent', + String $key_id = 'E8A032E094D8EB4EA189D270DA418C88A3219F7B', + Stdlib::HTTPSUrl $key_source = 'https://apt.releases.hashicorp.com/gpg', + String $description = 'HashiCorp package repository.', ) { - $key_id='E8A032E094D8EB4EA189D270DA418C88A3219F7B' - $key_source='https://apt.releases.hashicorp.com/gpg' - $description='HashiCorp package repository.' - case $facts['os']['family'] { 'Debian': { include apt @@ -25,7 +29,7 @@ class hashi_stack::repo ( architecture => 'amd64', comment => $description, location => 'https://apt.releases.hashicorp.com', - release => 'stable', + release => $facts['os']['distro']['codename'], repos => 'main', key => { 'id' => $key_id, diff --git a/spec/acceptance/standard_spec.rb b/spec/acceptance/standard_spec.rb index f6c146f..2174044 100644 --- a/spec/acceptance/standard_spec.rb +++ b/spec/acceptance/standard_spec.rb @@ -6,12 +6,12 @@ describe 'hashi_stack::repo class' do # Using puppet_apply as a helper it 'should work with no errors based on the example' do pp = <<-EOS - class { 'hashi_stack::repo': } + class { 'hashi_stack::repo': } -> package { 'packer': ensure => installed } 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) + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) end end end diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index 3cb9ee7..063e9a9 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -1,8 +1,16 @@ require 'spec_helper' -describe 'hashi_stack::repo' do +describe 'hashi_stack::repo', type: 'class' do on_supported_os.each do |os, os_facts| context "on #{os}" do + let(:facts) { os_facts } + + case os_facts[:os]['family'] + when 'Debian' + it { is_expected.to contain_apt__source('HashiCorp') } + when 'RedHat' + it { is_expected.to contain_yumrepo('HashiCorp') } + end end end end