class elastic::search {
  contain elastic::search::install
  contain elastic::search::config
  contain elastic::search::service
}

class elastic::search::install {
  file { '/opt/search':
    ensure => directory
  }

  file { '/opt/search/search.deb':
    ensure => file,
    source => 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.2-amd64.deb'
  } ~>
  package { 'search':
    provider => dpkg,
    source => "/opt/search/search.deb"
  }
}

class elastic::search::config {
  file { '/etc/elasticsearch/elasticsearch.yml':
    ensure => file,
    source => 'puppet:///modules/elastic/elastic.yml',
    notify => Service['elasticsearch']
  }
}

class elastic::search::service {
  service { 'elasticsearch':
    ensure => running,
    enable => true
  }
}
