Skip to content

Instantly share code, notes, and snippets.

@jmassardo
Last active February 26, 2019 15:24
Show Gist options
  • Save jmassardo/ef0b0283de9b3e2dfcb7c35b8e2ea392 to your computer and use it in GitHub Desktop.
Save jmassardo/ef0b0283de9b3e2dfcb7c35b8e2ea392 to your computer and use it in GitHub Desktop.

Simple example of pushing the Chef Environment name over to Inspec

Control:

title 'Forwarders'

environments = yaml(content: inspec.profile.file('forwarders.yml')).params
chef_environment = attribute('chef_environment', description: 'The chef environment for the node', default: 'nope')

control 'fwd-1.0' do
  impact 0.7
  title 'Create /tmp directory'
  desc 'An optional description...'
  environments.each do |e|
    if e['env_name'] == chef_environment
      describe file("/tmp/forwarder") do
        its('content') { should match e['forwarder'] }
      end
    end
  end
end

Within the profile, create files/forwarders.yml

Contents:

- env_name: dev
  forwarder: useast.example.com
- env_name: prod
  forwarder: uswest.example.com
- env_name: test
  forwarder: uscentral.example.com
- env_name: nope
  forwarder: nope.nope.nope

Within your wrapper cookbook that has the configs for the audit cookbook, add this attribute:

# push chef env over to inspec
node.normal['audit']['attributes']['chef_environment'] = node.chef_environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment