sf-hiera-aws 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d39910445613c2d49ecf0e13dc57e122129a5788
4
- data.tar.gz: e0589b22593c40fac6f61d4d6b93aea0655be822
3
+ metadata.gz: f7c460e98b3363eeec6460d644ebefc2361e7eb4
4
+ data.tar.gz: 53d713bbe89e34005bb8a3f4ddb7a844abcb4d3c
5
5
  SHA512:
6
- metadata.gz: e6eafb08e724871a9512882215aed82678e15019d01dcb3dbba11daa1eb91967e8046be08e1fd913e78a0c49927c7b9fe975ada1e4b14a24ef2d0b4c60f9d0e5
7
- data.tar.gz: 7358df8a4ceef3d6385f1728bfe5c5a30c655feebb809f13589a93947eb8acf279084d068a11223232197f9e4431546e0e2a45994ee8ff1f39698fbad82f6ef4
6
+ metadata.gz: 29aac28022286ccc023aee65d89ed05bbd5ff5354c2e182046d604777bb70316b9c02e45092ac65189ffa103d6177079d09607c75873c43ad874cfdeb09232bd
7
+ data.tar.gz: f4dcc37e4ed641e7720053bb710737d92d4f75e766801818af032718719848142fb11ffaaf8271605393ce269b6997acbb28a97efaaff6260998a697a183cf47
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # sf-hiera-aws changelog
2
+
3
+ ## 0.0.7 (2 June 2016)
4
+
5
+ * Add support for ElastiCache Replication Groups
6
+
1
7
  ## 0.0.6 (22 March 2016)
2
8
 
3
9
  * Correct bad filter logic
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,59 @@
1
+ # Contributing
2
+
3
+ ## Unit Tests
4
+
5
+ You can run the unit tests with `bundle exec rake test:unit`
6
+
7
+ The tests live under `spec/` as per the rspec convention, with one spec file
8
+ per lookup type. We use a combination of dependency injection and the mocking
9
+ features of the AWS SDK to test the logic inside the hiera back-end.
10
+
11
+
12
+ ## Testing For Real
13
+
14
+ With unit tests in place, you'll want to test against some real infrastructure
15
+ at some point too. The easiest way to do this is using the Hiera CLI tool.
16
+
17
+ Check out this backend onto your test box. Alongside it, you'll create three
18
+ config files.
19
+
20
+ ```
21
+ hiera.yaml scope.yaml sf-hiera-aws sf_hiera_aws.yaml
22
+ ```
23
+
24
+ `hiera.yaml` should look like:
25
+
26
+ ```
27
+ ---
28
+ :backends:
29
+ - sf_hiera_aws
30
+
31
+ :logger: console
32
+
33
+ :aws_sdk:
34
+ :config_file: sf_hiera_aws.yaml
35
+ ```
36
+
37
+ `scope.yaml` should contain any variables you interpolate in the other config
38
+ files. For example:
39
+
40
+ ```
41
+ ---
42
+ "::sf_environment": test
43
+ "::sf_location": euwest1
44
+ ```
45
+
46
+ `sf_hiera_aws.yaml` should be your config for this back-end, as documented
47
+ in the README for this project.
48
+
49
+ To ensure we load the checked out version of this plugin rather than any
50
+ installed copy, we set the RUBYLIB environment variable to point at the
51
+ project `lib/` folder.
52
+
53
+ To look up a test key, do the following:
54
+
55
+ ```
56
+ $ RUBYLIB=sf-hiera-aws/lib hiera -c ./hiera.yaml -y ./scope.yaml --debug <key>
57
+ ```
58
+
59
+
data/README.md CHANGED
@@ -52,6 +52,8 @@ aws_am_search_nodes:
52
52
  filters:
53
53
  - name: tag:aws:autoscaling:groupName
54
54
  values: [ "%{::sf_location}-%{::sf_environment}-search" ]
55
+ - name: instance-state-name
56
+ values: [ 'running' ]
55
57
  return:
56
58
  - :instance_id
57
59
  - :private_ip_address
@@ -60,6 +62,8 @@ aws_am_search_nodes:
60
62
 
61
63
  The value of `return` here is also the default, and so can be omitted. You can use any of the methods listed at http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Instance.html to obtain other details from the Instance object. Calls to this key will return a list of hashes, each containing `instace_id`, `private_ip_address` and `private_dns_name` keys.
62
64
 
65
+ Note that by default all EC2 instances will be returned, including stopped instances. To return only the running instances, add a filter as shown in this example.
66
+
63
67
  ### Example - EC2 nodes by tag, single item list
64
68
 
65
69
  ```
@@ -99,3 +103,21 @@ Calls to `:elasticache_cache_cluster` type keys return a list of cache nodes, th
99
103
  Pass a `return` key with value `:hostname` to have a list of hostnames of keys of all cache nodes matching the cache_cluster_id returned.
100
104
  Pass a `return` key with value `:hostname_and_port` to have a list of `"<hostname>:<port>"` strings returned.
101
105
 
106
+ ### Example - ElastiCache replication group by name
107
+
108
+ ```
109
+ aws_app_redis:
110
+ type: :elasticache_replication_group
111
+ replication_group_id: "%{::sf_location}-%{::sf_environment}-redis"
112
+ ```
113
+
114
+ Calls to `:elasticache_replication_group` return a list of replication groups, their primary endpoints and node group members.
115
+ Pass a `return` key with value `:primary_endpoint` to have the hostname for the primary end point of the node group returned.
116
+ Pass a `return` key with value `:primary_endpoint_and_port` to have the hostname and port returned as a colon-separated string.
117
+ Pass a `return` key with value `:read_endpoints` to return an array of read endpoint hostnames, if a `replication_group_id` is specified. Returns `nil` if `replication_group_id` is unspecified.
118
+ Pass a `return` key with value `:read_endpoints_with_ports` to return an array of read endpoint hostnames and ports as colon delimted strongs. Returns `nil` if `replication_group_id` is unspecified.
119
+
120
+ ## Notes
121
+
122
+ * The order in which items are returned, for example EC2 nodes matching a tag, is undefined. If you are using an array of items in a configuration file template, for example, you are advised to sort the array in the template. This eliminates the likelihood of unnecessary configuration file changes, and the consequential unnecessary restart of dependent services.
123
+ * By default, all EC2 instances are returned, including those in a non-running state. To return only running instances, add a filter on `name: instance-state-name` and `values: ['running']` as per the example above.
@@ -303,6 +303,84 @@ class Hiera
303
303
  end
304
304
 
305
305
  end
306
+
307
+ def type_elasticache_replication_group(options)
308
+ elasticache = get_elasticache_client
309
+
310
+ if options.key? 'replication_group_id'
311
+ replgroups = elasticache.describe_replication_groups(
312
+ replication_group_id: options['replication_group_id'],
313
+ ).replication_groups
314
+ else
315
+ replgroups = elasticache.describe_replication_groups.replication_groups
316
+ end
317
+
318
+ if !options.key? 'return'
319
+
320
+ return replgroups.collect do |rg|
321
+ {
322
+ 'replication_group_id' => rg.replication_group_id,
323
+ 'primary_endpoint_address' => rg.node_groups[0].primary_endpoint.address,
324
+ 'primary_endpoint_port' => rg.node_groups[0].primary_endpoint.port,
325
+ 'node_group_members' => rg.node_groups[0].node_group_members.collect do |ngm|
326
+ {
327
+ 'cache_node_id' => ngm.cache_node_id,
328
+ 'cache_cluster_id' => ngm.cache_cluster_id,
329
+ 'read_endpoint_address' => ngm.read_endpoint.address,
330
+ 'read_endpoint_port' => ngm.read_endpoint.port,
331
+ 'current_role' => ngm.current_role,
332
+ }
333
+ end
334
+ }
335
+ end
336
+
337
+ end
338
+
339
+ if options['return'] == :read_endpoints
340
+
341
+ if options.key? 'replication_group_id'
342
+ return replgroups[0].node_groups[0].node_group_members.map { |ngm| ngm.read_endpoint.address }
343
+ else
344
+ Hiera.warn('Requested to return array of read endpoints for replication group, but no replication_group_id specified')
345
+ return nil
346
+ end
347
+
348
+ end
349
+
350
+ if options['return'] == :read_endpoints_and_ports
351
+
352
+ if options.key? 'replication_group_id'
353
+ return replgroups[0].node_groups[0].node_group_members.map { |ngm| "#{ngm.read_endpoint.address}:#{ngm.read_endpoint.port}" }
354
+ else
355
+ Hiera.warn('Requested to return array of read endpoints and ports for replication group, but no replication_group_id specified')
356
+ return nil
357
+ end
358
+
359
+ end
360
+
361
+ if options['return'] == :primary_endpoint
362
+
363
+ primary_endpoints = []
364
+
365
+ replgroups.each do |rg|
366
+ primary_endpoints.push(rg.node_groups[0].primary_endpoint.address)
367
+ end
368
+
369
+ return primary_endpoints
370
+
371
+ elsif options['return'] == :primary_endpoint_and_port
372
+
373
+ primary_endpoints = []
374
+
375
+ replgroups.each do |rg|
376
+ primary_endpoints.push( [ rg.node_groups[0].primary_endpoint.address, rg.node_groups[0].primary_endpoint.port ].join(':') )
377
+ end
378
+
379
+ return primary_endpoints
380
+
381
+ end
382
+
383
+ end
306
384
  end
307
385
  end
308
386
  end
data/sf-hiera-aws.gemspec CHANGED
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'sf-hiera-aws'
7
- spec.version = '0.0.6'
8
- spec.authors = ['Jon Topper']
9
- spec.email = ['jon@scalefactory.com']
7
+ spec.version = '0.0.7'
8
+ spec.authors = ['Jon Topper','Mike Griffiths']
9
+ spec.email = ['jon@scalefactory.com','mike@scalefactory.com']
10
10
 
11
11
  spec.summary = 'Hiera backend for querying AWS resources'
12
12
  spec.homepage = 'https://github.com/scalefactory/sf-hiera-aws'
metadata CHANGED
@@ -1,67 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sf-hiera-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Topper
8
+ - Mike Griffiths
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2016-03-22 00:00:00.000000000 Z
12
+ date: 2016-06-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - "~>"
18
+ - - ~>
18
19
  - !ruby/object:Gem::Version
19
20
  version: '1.8'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - "~>"
25
+ - - ~>
25
26
  - !ruby/object:Gem::Version
26
27
  version: '1.8'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ~>
32
33
  - !ruby/object:Gem::Version
33
34
  version: '10.0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - "~>"
39
+ - - ~>
39
40
  - !ruby/object:Gem::Version
40
41
  version: '10.0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: aws-sdk-resources
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ">="
46
+ - - '>='
46
47
  - !ruby/object:Gem::Version
47
48
  version: 2.2.6
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ">="
53
+ - - '>='
53
54
  - !ruby/object:Gem::Version
54
55
  version: 2.2.6
55
56
  description:
56
57
  email:
57
58
  - jon@scalefactory.com
59
+ - mike@scalefactory.com
58
60
  executables: []
59
61
  extensions: []
60
62
  extra_rdoc_files: []
61
63
  files:
62
- - ".gitignore"
63
- - ".rubocop.yml"
64
+ - .gitignore
65
+ - .rubocop.yml
64
66
  - CHANGELOG.md
67
+ - CONTRIBUTING.md
65
68
  - Gemfile
66
69
  - LICENSE.txt
67
70
  - README.md
@@ -78,17 +81,17 @@ require_paths:
78
81
  - lib
79
82
  required_ruby_version: !ruby/object:Gem::Requirement
80
83
  requirements:
81
- - - ">="
84
+ - - '>='
82
85
  - !ruby/object:Gem::Version
83
86
  version: '0'
84
87
  required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  requirements:
86
- - - ">="
89
+ - - '>='
87
90
  - !ruby/object:Gem::Version
88
91
  version: '0'
89
92
  requirements: []
90
93
  rubyforge_project:
91
- rubygems_version: 2.2.2
94
+ rubygems_version: 2.0.14.1
92
95
  signing_key:
93
96
  specification_version: 4
94
97
  summary: Hiera backend for querying AWS resources