Index: src/puppetcode/environments/test/modules/apt/manifests/backports.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/backports.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/backports.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,65 @@
+class apt::backports (
+  $location = undef,
+  $release  = undef,
+  $repos    = undef,
+  $key      = undef,
+  $pin      = 200,
+){
+  if $location {
+    validate_string($location)
+    $_location = $location
+  }
+  if $release {
+    validate_string($release)
+    $_release = $release
+  }
+  if $repos {
+    validate_string($repos)
+    $_repos = $repos
+  }
+  if $key {
+    unless is_hash($key) {
+      validate_string($key)
+    }
+    $_key = $key
+  }
+  if ($::apt::xfacts['lsbdistid'] == 'debian' or $::apt::xfacts['lsbdistid'] == 'ubuntu') {
+    unless $location {
+      $_location = $::apt::backports['location']
+    }
+    unless $release {
+      $_release = "${::apt::xfacts['lsbdistcodename']}-backports"
+    }
+    unless $repos {
+      $_repos = $::apt::backports['repos']
+    }
+    unless $key {
+      $_key =  $::apt::backports['key']
+    }
+  } else {
+    unless $location and $release and $repos and $key {
+      fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key')
+    }
+  }
+
+  if is_hash($pin) {
+    $_pin = $pin
+  } elsif is_numeric($pin) or is_string($pin) {
+    # apt::source defaults to pinning to origin, but we should pin to release
+    # for backports
+    $_pin = {
+      'priority' => $pin,
+      'release'  => $_release,
+    }
+  } else {
+    fail('pin must be either a string, number or hash')
+  }
+
+  apt::source { 'backports':
+    location => $_location,
+    release  => $_release,
+    repos    => $_repos,
+    key      => $_key,
+    pin      => $_pin,
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/conf.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/conf.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/conf.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,20 @@
+define apt::conf (
+  $content       = undef,
+  $ensure        = present,
+  $priority      = '50',
+  $notify_update = undef,
+) {
+
+  unless $ensure == 'absent' {
+    unless $content {
+      fail('Need to pass in content parameter')
+    }
+  }
+
+  apt::setting { "conf-${name}":
+    ensure        => $ensure,
+    priority      => $priority,
+    content       => template('apt/_conf_header.erb', 'apt/conf.erb'),
+    notify_update => $notify_update,
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/init.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/init.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/init.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,163 @@
+#
+class apt(
+  $update   = {},
+  $purge    = {},
+  $proxy    = {},
+  $sources  = {},
+  $keys     = {},
+  $ppas     = {},
+  $pins     = {},
+  $settings = {},
+) inherits ::apt::params {
+
+  $frequency_options = ['always','daily','weekly','reluctantly']
+  validate_hash($update)
+  if $update['frequency'] {
+    validate_re($update['frequency'], $frequency_options)
+  }
+  if $update['timeout'] {
+    unless is_integer($update['timeout']) {
+      fail('timeout value for update must be an integer')
+    }
+  }
+  if $update['tries'] {
+    unless is_integer($update['tries']) {
+      fail('tries value for update must be an integer')
+    }
+  }
+
+  $_update = merge($::apt::update_defaults, $update)
+  include ::apt::update
+
+  validate_hash($purge)
+  if $purge['sources.list'] {
+    validate_bool($purge['sources.list'])
+  }
+  if $purge['sources.list.d'] {
+    validate_bool($purge['sources.list.d'])
+  }
+  if $purge['preferences'] {
+    validate_bool($purge['preferences'])
+  }
+  if $purge['preferences.d'] {
+    validate_bool($purge['preferences.d'])
+  }
+
+  $_purge = merge($::apt::purge_defaults, $purge)
+
+  validate_hash($proxy)
+  if $proxy['ensure'] {
+    validate_re($proxy['ensure'], ['file', 'present', 'absent'])
+  }
+  if $proxy['host'] {
+    validate_string($proxy['host'])
+  }
+  if $proxy['port'] {
+    unless is_integer($proxy['port']) {
+      fail('$proxy port must be an integer')
+    }
+  }
+  if $proxy['https'] {
+    validate_bool($proxy['https'])
+  }
+
+  $_proxy = merge($apt::proxy_defaults, $proxy)
+
+  validate_hash($sources)
+  validate_hash($keys)
+  validate_hash($settings)
+  validate_hash($ppas)
+  validate_hash($pins)
+
+  if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
+    apt::setting { 'conf-proxy':
+      ensure   => $_proxy['ensure'],
+      priority => '01',
+      content  => template('apt/_conf_header.erb', 'apt/proxy.erb'),
+    }
+  }
+
+  $sources_list_content = $_purge['sources.list'] ? {
+    true    => "# Repos managed by puppet.\n",
+    default => undef,
+  }
+
+  $preferences_ensure = $_purge['preferences'] ? {
+    true    => absent,
+    default => file,
+  }
+
+  if $_update['frequency'] == 'always' {
+    Exec <| title=='apt_update' |> {
+      refreshonly => false,
+    }
+  }
+
+  apt::setting { 'conf-update-stamp':
+    priority => 15,
+    content  => template('apt/_conf_header.erb', 'apt/15update-stamp.erb'),
+  }
+
+  file { 'sources.list':
+    ensure  => file,
+    path    => $::apt::sources_list,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => $sources_list_content,
+    notify  => Class['apt::update'],
+  }
+
+  file { 'sources.list.d':
+    ensure  => directory,
+    path    => $::apt::sources_list_d,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    purge   => $_purge['sources.list.d'],
+    recurse => $_purge['sources.list.d'],
+    notify  => Class['apt::update'],
+  }
+
+  file { 'preferences':
+    ensure => $preferences_ensure,
+    path   => $::apt::preferences,
+    owner  => root,
+    group  => root,
+    mode   => '0644',
+    notify => Class['apt::update'],
+  }
+
+  file { 'preferences.d':
+    ensure  => directory,
+    path    => $::apt::preferences_d,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    purge   => $_purge['preferences.d'],
+    recurse => $_purge['preferences.d'],
+    notify  => Class['apt::update'],
+  }
+
+  # manage sources if present
+  if $sources {
+    create_resources('apt::source', $sources)
+  }
+  # manage keys if present
+  if $keys {
+    create_resources('apt::key', $keys)
+  }
+  # manage ppas if present
+  if $ppas {
+    create_resources('apt::ppa', $ppas)
+  }
+  # manage settings if present
+  if $settings {
+    create_resources('apt::setting', $settings)
+  }
+
+  # manage pins if present
+  if $pins {
+    create_resources('apt::pin', $pins)
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/key.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/key.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/key.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,111 @@
+# == Define: apt::key
+define apt::key (
+  $id          = $title,
+  $ensure      = present,
+  $content     = undef,
+  $source      = undef,
+  $server      = $::apt::keyserver,
+  $options     = undef,
+  $key         = undef,
+  $key_content = undef,
+  $key_source  = undef,
+  $key_server  = undef,
+  $key_options = undef,
+) {
+
+  if $key != undef {
+    warning('$key is deprecated and will be removed in the next major release. Please use $id instead.')
+    $_id = $key
+  } else {
+    $_id = $id
+  }
+
+  if $key_content != undef {
+    warning('$key_content is deprecated and will be removed in the next major release. Please use $content instead.')
+    $_content = $key_content
+  } else {
+    $_content = $content
+  }
+
+  if $key_source != undef {
+    warning('$key_source is deprecated and will be removed in the next major release. Please use $source instead.')
+    $_source = $key_source
+  } else {
+    $_source = $source
+  }
+
+  if $key_server != undef {
+    warning('$key_server is deprecated and will be removed in the next major release. Please use $server instead.')
+    $_server = $key_server
+  } else {
+    $_server = $server
+  }
+
+  if $key_options != undef {
+    warning('$key_options is deprecated and will be removed in the next major release. Please use $options instead.')
+    $_options = $key_options
+  } else {
+    $_options = $options
+  }
+
+  validate_re($_id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
+  validate_re($ensure, ['\Aabsent|present\Z',])
+
+  if $_content {
+    validate_string($_content)
+  }
+
+  if $_source {
+    validate_re($_source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
+  }
+
+  if $_server {
+    validate_re($_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
+  }
+
+  if $_options {
+    validate_string($_options)
+  }
+
+  case $ensure {
+    present: {
+      if defined(Anchor["apt_key ${_id} absent"]){
+        fail("key with id ${_id} already ensured as absent")
+      }
+
+      if !defined(Anchor["apt_key ${_id} present"]) {
+        apt_key { $title:
+          ensure  => $ensure,
+          id      => $_id,
+          source  => $_source,
+          content => $_content,
+          server  => $_server,
+          options => $_options,
+        } ->
+        anchor { "apt_key ${_id} present": }
+      }
+    }
+
+    absent: {
+      if defined(Anchor["apt_key ${_id} present"]){
+        fail("key with id ${_id} already ensured as present")
+      }
+
+      if !defined(Anchor["apt_key ${_id} absent"]){
+        apt_key { $title:
+          ensure  => $ensure,
+          id      => $_id,
+          source  => $_source,
+          content => $_content,
+          server  => $_server,
+          options => $_options,
+        } ->
+        anchor { "apt_key ${_id} absent": }
+      }
+    }
+
+    default: {
+      fail "Invalid 'ensure' value '${ensure}' for apt::key"
+    }
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/params.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/params.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/params.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,162 @@
+class apt::params {
+
+  if $::osfamily != 'Debian' {
+    fail('This module only works on Debian or derivatives like Ubuntu')
+  }
+
+  # prior to puppet 3.5.0, defined couldn't test if a variable was defined
+  # strict variables wasn't added until 3.5.0, so this should be fine.
+  if ! $::settings::strict_variables {
+    $xfacts = {
+      'lsbdistcodename'     => $::lsbdistcodename,
+      'lsbdistrelease'      => $::lsbdistrelease,
+      'lsbmajdistrelease'   => $::lsbmajdistrelease,
+      'lsbdistdescription'  => $::lsbdistdescription,
+      'lsbminordistrelease' => $::lsbminordistrelease,
+      'lsbdistid'           => $::lsbdistid,
+    }
+  } else {
+    # Strict variables facts lookup compatibility
+    $xfacts = {
+      'lsbdistcodename' => defined('$lsbdistcodename') ? {
+        true    => $::lsbdistcodename,
+        default => undef,
+      },
+      'lsbdistrelease' => defined('$lsbdistrelease') ? {
+        true    => $::lsbdistrelease,
+        default => undef,
+      },
+      'lsbmajdistrelease' => defined('$lsbmajdistrelease') ? {
+        true    => $::lsbmajdistrelease,
+        default => undef,
+      },
+      'lsbdistdescription' => defined('$lsbdistdescription') ? {
+        true    => $::lsbdistdescription,
+        default => undef,
+      },
+      'lsbminordistrelease' => defined('$lsbminordistrelease') ? {
+        true    => $::lsbminordistrelease,
+        default => undef,
+      },
+      'lsbdistid' => defined('$lsbdistid') ? {
+        true    => $::lsbdistid,
+        default => undef,
+      },
+    }
+  }
+
+  $root           = '/etc/apt'
+  $provider       = '/usr/bin/apt-get'
+  $sources_list   = "${root}/sources.list"
+  $sources_list_d = "${root}/sources.list.d"
+  $conf_d         = "${root}/apt.conf.d"
+  $preferences    = "${root}/preferences"
+  $preferences_d  = "${root}/preferences.d"
+  $keyserver      = 'keyserver.ubuntu.com'
+
+  $config_files = {
+    'conf'   => {
+      'path' => $conf_d,
+      'ext'  => '',
+    },
+    'pref'   => {
+      'path' => $preferences_d,
+      'ext'  => '.pref',
+    },
+    'list'   => {
+      'path' => $sources_list_d,
+      'ext'  => '.list',
+    }
+  }
+
+  $update_defaults = {
+    'frequency' => 'reluctantly',
+    'timeout'   => undef,
+    'tries'     => undef,
+  }
+
+  $proxy_defaults = {
+    'ensure' => undef,
+    'host'   => undef,
+    'port'   => 8080,
+    'https'  => false,
+  }
+
+  $purge_defaults = {
+    'sources.list'   => false,
+    'sources.list.d' => false,
+    'preferences'    => false,
+    'preferences.d'  => false,
+  }
+
+  $source_key_defaults = {
+    'server'  => $keyserver,
+    'options' => undef,
+    'content' => undef,
+    'source'  => undef,
+  }
+
+  $include_defaults = {
+    'deb' => true,
+    'src' => false,
+  }
+
+  case $xfacts['lsbdistid'] {
+    'debian': {
+      case $xfacts['lsbdistcodename'] {
+        'squeeze': {
+          $backports = {
+            'location' => 'http://httpredir.debian.org/debian-backports',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
+          }
+        }
+        default: {
+          $backports = {
+            'location' => 'http://httpredir.debian.org/debian',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
+          }
+        }
+      }
+
+      $ppa_options = undef
+      $ppa_package = undef
+
+    }
+    'ubuntu': {
+      $backports = {
+        'location' => 'http://archive.ubuntu.com/ubuntu',
+        'key'      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        'repos'    => 'main universe multiverse restricted',
+      }
+
+      case $xfacts['lsbdistcodename'] {
+        'lucid': {
+          $ppa_options        = undef
+          $ppa_package        = 'python-software-properties'
+        }
+        'precise': {
+          $ppa_options        = '-y'
+          $ppa_package        = 'python-software-properties'
+        }
+        'trusty', 'utopic', 'vivid', 'wily': {
+          $ppa_options        = '-y'
+          $ppa_package        = 'software-properties-common'
+        }
+        default: {
+          $ppa_options        = '-y'
+          $ppa_package        = 'python-software-properties'
+        }
+      }
+    }
+    undef: {
+      fail('Unable to determine lsbdistid, please install lsb-release first')
+    }
+    default: {
+      $ppa_options = undef
+      $ppa_package = undef
+      $backports   = undef
+    }
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/pin.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/pin.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/pin.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,80 @@
+# pin.pp
+# pin a release in apt, useful for unstable repositories
+
+define apt::pin(
+  $ensure          = present,
+  $explanation     = undef,
+  $order           = undef,
+  $packages        = '*',
+  $priority        = 0,
+  $release         = '', # a=
+  $origin          = '',
+  $version         = '',
+  $codename        = '', # n=
+  $release_version = '', # v=
+  $component       = '', # c=
+  $originator      = '', # o=
+  $label           = ''  # l=
+) {
+  if $order and !is_integer($order) {
+    fail('Only integers are allowed in the apt::pin order param')
+  }
+
+  if $explanation {
+    $_explanation = $explanation
+  } else {
+    if defined('$caller_module_name') { # strict vars check
+      $_explanation = "${caller_module_name}: ${name}"
+    } else {
+      $_explanation = ": ${name}"
+    }
+  }
+
+  $pin_release_array = [
+    $release,
+    $codename,
+    $release_version,
+    $component,
+    $originator,
+    $label]
+  $pin_release = join($pin_release_array, '')
+
+  # Read the manpage 'apt_preferences(5)', especially the chapter
+  # 'The Effect of APT Preferences' to understand the following logic
+  # and the difference between specific and general form
+  if is_array($packages) {
+    $packages_string = join($packages, ' ')
+  } else {
+    $packages_string = $packages
+  }
+
+  if $packages_string != '*' { # specific form
+    if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
+      ( $version != '' and ( $pin_release != '' or $origin != '' )) {
+      fail('parameters release, origin, and version are mutually exclusive')
+    }
+  } else { # general form
+    if $version != '' {
+      fail('parameter version cannot be used in general form')
+    }
+    if ( $pin_release != '' and $origin != '' ) {
+      fail('parameters release and origin are mutually exclusive')
+    }
+  }
+
+  # According to man 5 apt_preferences:
+  # The files have either no or "pref" as filename extension
+  # and only contain alphanumeric, hyphen (-), underscore (_) and period
+  # (.) characters. Otherwise APT will print a notice that it has ignored a
+  # file, unless that file matches a pattern in the
+  # Dir::Ignore-Files-Silently configuration list - in which case it will
+  # be silently ignored.
+  $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG')
+
+  apt::setting { "pref-${file_name}":
+    ensure        => $ensure,
+    priority      => $order,
+    content       => template('apt/_header.erb', 'apt/pin.pref.erb'),
+    notify_update => false,
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/ppa.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/ppa.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/ppa.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,72 @@
+# ppa.pp
+define apt::ppa(
+  $ensure         = 'present',
+  $options        = $::apt::ppa_options,
+  $release        = $::apt::xfacts['lsbdistcodename'],
+  $package_name   = $::apt::ppa_package,
+  $package_manage = false,
+) {
+  unless $release {
+    fail('lsbdistcodename fact not available: release parameter required')
+  }
+
+  if $::apt::xfacts['lsbdistid'] == 'Debian' {
+    fail('apt::ppa is not currently supported on Debian.')
+  }
+
+  $ubuntu_release_year  = regsubst($::apt::xfacts['lsbdistrelease'], '\.\d+$', '', 'G') + 0
+  $ubuntu_release_month = regsubst($::apt::xfacts['lsbdistrelease'], '^\d+\.', '', 'G') + 0
+
+  if $ubuntu_release_year >= 15 and $ubuntu_release_month >= 10 {
+    $distid = downcase($::apt::xfacts['lsbdistid'])
+    $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}")
+  } else {
+    $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}")
+  }
+
+  $filename_no_slashes      = regsubst($filename, '/', '-', 'G')
+  $filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G')
+  $sources_list_d_filename  = "${filename_no_specialchars}.list"
+
+  if $ensure == 'present' {
+    if $package_manage {
+      ensure_packages($package_name)
+
+      $_require = [File['sources.list.d'], Package[$package_name]]
+    } else {
+      $_require = File['sources.list.d']
+    }
+
+    $_proxy = $::apt::_proxy
+    if $_proxy['host'] {
+      if $_proxy['https'] {
+        $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"]
+      } else {
+        $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"]
+      }
+    } else {
+      $_proxy_env = []
+    }
+
+    exec { "add-apt-repository-${name}":
+      environment => $_proxy_env,
+      command     => "/usr/bin/add-apt-repository ${options} ${name}",
+      unless      => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}",
+      user        => 'root',
+      logoutput   => 'on_failure',
+      notify      => Class['apt::update'],
+      require     => $_require,
+    }
+
+    file { "${::apt::sources_list_d}/${sources_list_d_filename}":
+      ensure  => file,
+      require => Exec["add-apt-repository-${name}"],
+    }
+  }
+  else {
+    file { "${::apt::sources_list_d}/${sources_list_d_filename}":
+      ensure => 'absent',
+      notify => Class['apt::update'],
+    }
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/setting.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/setting.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/setting.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,64 @@
+define apt::setting (
+  $priority      = 50,
+  $ensure        = file,
+  $source        = undef,
+  $content       = undef,
+  $notify_update = true,
+) {
+
+  include 'apt::params'
+  if $content and $source {
+    fail('apt::setting cannot have both content and source')
+  }
+
+  if !$content and !$source {
+    fail('apt::setting needs either of content or source')
+  }
+
+  validate_re($ensure,  ['file', 'present', 'absent'])
+  validate_bool($notify_update)
+
+  $title_array = split($title, '-')
+  $setting_type = $title_array[0]
+  $base_name = join(delete_at($title_array, 0), '-')
+
+  validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
+
+  unless is_integer($priority) {
+    # need this to allow zero-padded priority.
+    validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
+  }
+
+  if $source {
+    validate_string($source)
+  }
+
+  if $content {
+    validate_string($content)
+  }
+
+  if ($setting_type == 'list') or ($setting_type == 'pref') {
+    $_priority = ''
+  } else {
+    $_priority = $priority
+  }
+
+  $_path = $::apt::params::config_files[$setting_type]['path']
+  $_ext  = $::apt::params::config_files[$setting_type]['ext']
+
+  if $notify_update {
+    $_notify = Class['apt::update']
+  } else {
+    $_notify = undef
+  }
+
+  file { "${_path}/${_priority}${base_name}${_ext}":
+    ensure  => $ensure,
+    owner   => 'root',
+    group   => 'root',
+    mode    => '0644',
+    content => $content,
+    source  => $source,
+    notify  => $_notify,
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/source.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/source.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/source.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,156 @@
+# source.pp
+# add an apt source
+define apt::source(
+  $location          = undef,
+  $comment           = $name,
+  $ensure            = present,
+  $release           = undef,
+  $repos             = 'main',
+  $include           = {},
+  $key               = undef,
+  $pin               = undef,
+  $architecture      = undef,
+  $allow_unsigned    = false,
+  $include_src       = undef,
+  $include_deb       = undef,
+  $required_packages = undef,
+  $key_server        = undef,
+  $key_content       = undef,
+  $key_source        = undef,
+  $trusted_source    = undef,
+) {
+  validate_string($architecture, $comment, $location, $repos)
+  validate_bool($allow_unsigned)
+  validate_hash($include)
+
+  # This is needed for compat with 1.8.x
+  include ::apt
+
+  $_before = Apt::Setting["list-${title}"]
+
+  if $include_src != undef {
+    warning("\$include_src is deprecated and will be removed in the next major release, please use \$include => { 'src' => ${include_src} } instead")
+  }
+
+  if $include_deb != undef {
+    warning("\$include_deb is deprecated and will be removed in the next major release, please use \$include => { 'deb' => ${include_deb} } instead")
+  }
+
+  if $required_packages != undef {
+    warning('$required_packages is deprecated and will be removed in the next major release, please use package resources instead.')
+    exec { "Required packages: '${required_packages}' for ${name}":
+      command     => "${::apt::params::provider} -y install ${required_packages}",
+      logoutput   => 'on_failure',
+      refreshonly => true,
+      tries       => 3,
+      try_sleep   => 1,
+      before      => $_before,
+    }
+  }
+
+  if $key_server != undef {
+    warning("\$key_server is deprecated and will be removed in the next major release, please use \$key => { 'server' => ${key_server} } instead.")
+  }
+
+  if $key_content != undef {
+    warning("\$key_content is deprecated and will be removed in the next major release, please use \$key => { 'content' => ${key_content} } instead.")
+  }
+
+  if $key_source != undef {
+    warning("\$key_source is deprecated and will be removed in the next major release, please use \$key => { 'source' => ${key_source} } instead.")
+  }
+
+  if $trusted_source != undef {
+    warning('$trusted_source is deprecated and will be removed in the next major release, please use $allow_unsigned instead.')
+    $_allow_unsigned = $trusted_source
+  } else {
+    $_allow_unsigned = $allow_unsigned
+  }
+
+  if ! $release {
+    $_release = $::apt::params::xfacts['lsbdistcodename']
+    unless $_release {
+      fail('lsbdistcodename fact not available: release parameter required')
+    }
+  } else {
+    $_release = $release
+  }
+
+  if $ensure == 'present' and ! $location {
+    fail('cannot create a source entry without specifying a location')
+  }
+
+  if $include_src != undef and $include_deb != undef {
+    $_deprecated_include = {
+      'src' => $include_src,
+      'deb' => $include_deb,
+    }
+  } elsif $include_src != undef {
+    $_deprecated_include = { 'src' => $include_src }
+  } elsif $include_deb != undef {
+    $_deprecated_include = { 'deb' => $include_deb }
+  } else {
+    $_deprecated_include = {}
+  }
+
+  $_include = merge($::apt::params::include_defaults, $_deprecated_include, $include)
+
+  $_deprecated_key = {
+    'key_server'  => $key_server,
+    'key_content' => $key_content,
+    'key_source'  => $key_source,
+  }
+
+  if $key {
+    if is_hash($key) {
+      unless $key['id'] {
+        fail('key hash must contain at least an id entry')
+      }
+      $_key = merge($::apt::params::source_key_defaults, $_deprecated_key, $key)
+    } else {
+      validate_string($key)
+      $_key = merge( { 'id' => $key }, $_deprecated_key)
+    }
+  }
+
+  apt::setting { "list-${name}":
+    ensure  => $ensure,
+    content => template('apt/_header.erb', 'apt/source.list.erb'),
+  }
+
+  if $pin {
+    if is_hash($pin) {
+      $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
+    } elsif (is_numeric($pin) or is_string($pin)) {
+      $url_split = split($location, '/')
+      $host      = $url_split[2]
+      $_pin = {
+        'ensure'   => $ensure,
+        'priority' => $pin,
+        'before'   => $_before,
+        'origin'   => $host,
+      }
+    } else {
+      fail('Received invalid value for pin parameter')
+    }
+    create_resources('apt::pin', { "${name}" => $_pin })
+  }
+
+  # We do not want to remove keys when the source is absent.
+  if $key and ($ensure == 'present') {
+    if is_hash($_key) {
+      apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
+        ensure      => present,
+        id          => $_key['id'],
+        server      => $_key['server'],
+        content     => $_key['content'],
+        source      => $_key['source'],
+        options     => $_key['options'],
+        key_server  => $_key['key_server'],
+        key_content => $_key['key_content'],
+        key_source  => $_key['key_source'],
+        before      => $_before,
+      }
+    }
+  }
+}
Index: src/puppetcode/environments/test/modules/apt/manifests/update.pp
===================================================================
--- src/puppetcode/environments/test/modules/apt/manifests/update.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
+++ src/puppetcode/environments/test/modules/apt/manifests/update.pp	(revision 1c22429c336ddd7087e5a50b7a6a3e4add4e004b)
@@ -0,0 +1,61 @@
+class apt::update {
+  #TODO: to catch if $::apt_update_last_success has the value of -1 here. If we
+  #opt to do this, a info/warn would likely be all you'd need likely to happen
+  #on the first run, but if it's not run in awhile something is likely borked
+  #with apt and we'd want to know about it.
+
+  case $::apt::_update['frequency'] {
+    'always': {
+      $_kick_apt = true
+    }
+    'daily': {
+      #compare current date with the apt_update_last_success fact to determine
+      #if we should kick apt_update.
+      $daily_threshold = (strftime('%s') - 86400)
+      if $::apt_update_last_success {
+        if $::apt_update_last_success < $daily_threshold {
+          $_kick_apt = true
+        } else {
+          $_kick_apt = false
+        }
+      } else {
+        #if apt-get update has not successfully run, we should kick apt_update
+        $_kick_apt = true
+      }
+    }
+    'weekly':{
+      #compare current date with the apt_update_last_success fact to determine
+      #if we should kick apt_update.
+      $weekly_threshold = (strftime('%s') - 604800)
+      if $::apt_update_last_success {
+        if ( $::apt_update_last_success < $weekly_threshold ) {
+          $_kick_apt = true
+        } else {
+          $_kick_apt = false
+        }
+      } else {
+        #if apt-get update has not successfully run, we should kick apt_update
+        $_kick_apt = true
+      }
+    }
+    default: {
+      #catches 'reluctantly', and any other value (which should not occur).
+      #do nothing.
+      $_kick_apt = false
+    }
+  }
+
+  if $_kick_apt {
+    $_refresh = false
+  } else {
+    $_refresh = true
+  }
+  exec { 'apt_update':
+    command     => "${::apt::provider} update",
+    logoutput   => 'on_failure',
+    refreshonly => $_refresh,
+    timeout     => $::apt::_update['timeout'],
+    tries       => $::apt::_update['tries'],
+    try_sleep   => 1
+  }
+}
