Module: Enscalator::Plugins::ElasticsearchAmazon

Defined in:
lib/enscalator/plugins/elasticsearch_amazon.rb

Overview

Amazon Elasticsearch Service (Amazon ES)

Instance Method Summary collapse

Instance Method Details

#elasticsearch_init(cluster_name, properties: {}) ⇒ Object

Create new service instance

Parameters:

  • cluster_name (String)

    name of the cluster resource

  • properties (Hash) (defaults to: {})

    additional parameters for cluster configuration



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/enscalator/plugins/elasticsearch_amazon.rb', line 8

def elasticsearch_init(cluster_name, properties: {})
  cluster_properties = {
    AccessPolicies: {
      Version: '2012-10-17',
      Statement: [
        {
          Effect: 'Allow',
          Principal: {
            AWS: '*'
          }
        }
      ]
    },
    AdvancedOptions: {
      'rest.action.multi.allow_explicit_index': 'true'
    },
    EBSOptions: {
      EBSEnabled: true,
      Iops: 0,
      VolumeSize: 100,
      VolumeType: 'gp2'
    },
    ElasticsearchClusterConfig: {
      InstanceCount: '1',
      InstanceType: 'm3.medium.elasticsearch'
    },
    SnapshotOptions: {
      AutomatedSnapshotStartHour: '0'
    }
  }

  # do not modify properties passed from template
  props = properties.deep_dup

  default_tags = [
    {
      Key: 'ClusterName',
      Value: cluster_name.downcase
    }
  ]

  if props.key?(:Tags) && !props[:Tags].empty?
    props[:Tags].concat(default_tags)
  else
    props[:Tags] = default_tags
  end

  resource cluster_name,
           Type: 'AWS::Elasticsearch::Domain',
           Properties: cluster_properties.merge(props)

  output "#{cluster_name}ResourceID",
         Description: "#{cluster_name} ResourceID",
         Value: ref(cluster_name)

  output "#{cluster_name}DomainArn",
         Description: "#{cluster_name} DomainArn",
         Value: get_att(cluster_name, 'DomainArn')

  output "#{cluster_name}DomainEndpoint",
         Description: "#{cluster_name} DomainEndpoint",
         Value: get_att(cluster_name, 'DomainEndpoint')

  cluster_name
end