hiera-aws 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/hiera/backend/aws/base.rb +1 -1
- data/lib/hiera/backend/aws/elasticache.rb +4 -4
- data/lib/hiera/backend/aws/rds.rb +1 -1
- data/lib/hiera/backend/aws/version.rb +1 -1
- data/lib/hiera/backend/aws_backend.rb +19 -8
- data/spec/aws_backend_spec.rb +14 -6
- data/spec/aws_base_spec.rb +3 -8
- data/spec/aws_rds_spec.rb +24 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eed5fc6fc7e3723477b66a94f61fb6f9192320dc
|
4
|
+
data.tar.gz: 0c7263e0a1706423950e1b2492d523066cb12293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31a9141fbe5a274ff9e978446c4a87f57b5353c3ff9c77140ffca86dc1dfd74ffa50d92bc6c70a1a17f17a645e5e5899b5bffed9eafb0f972e74c3daa740958d
|
7
|
+
data.tar.gz: f131c2343c0fb05f3de4c48a8a39b73dcfb91a2e6544a61ac394946636223d2e086549dd713dd937bbf37ac0d094617fd5157db2af98b881a4aae2d0cb46094e
|
data/README.md
CHANGED
@@ -51,6 +51,14 @@ the backend configuration in `hiera.yml`:
|
|
51
51
|
:secret_access_key: your_aws_secret_access_key_here
|
52
52
|
```
|
53
53
|
|
54
|
+
In addition to credentials, you can also specify a particular AWS region that
|
55
|
+
will be used for all AWS API operations:
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
:aws:
|
59
|
+
:region: eu-west-1
|
60
|
+
```
|
61
|
+
|
54
62
|
## Hiera Keys
|
55
63
|
|
56
64
|
The backend currently supports the following keys that you can pass to the
|
@@ -6,7 +6,7 @@ class Hiera
|
|
6
6
|
# Implementation of Hiera keys for aws/elasticache
|
7
7
|
class ElastiCache < Base
|
8
8
|
def cache_nodes_by_cache_cluster_id
|
9
|
-
client = AWS::ElastiCache::Client.new
|
9
|
+
client = AWS::ElastiCache::Client.new
|
10
10
|
cache_cluster_id = scope["cache_cluster_id"]
|
11
11
|
raise MissingFactError, "cache_cluster_id not found" unless cache_cluster_id
|
12
12
|
options = { :cache_cluster_id => cache_cluster_id, :show_cache_node_info => true }
|
@@ -18,13 +18,13 @@ class Hiera
|
|
18
18
|
# XXX: Lots of spiked code ahead that MUST be refactored.
|
19
19
|
#
|
20
20
|
def cfn_stack_name(instance_id)
|
21
|
-
client = AWS::EC2.new
|
21
|
+
client = AWS::EC2.new
|
22
22
|
instances = client.instances[instance_id]
|
23
23
|
instances.tags["aws:cloudformation:stack-name"]
|
24
24
|
end
|
25
25
|
|
26
26
|
def cache_cluster_info(cluster_id)
|
27
|
-
client = AWS::ElastiCache::Client.new
|
27
|
+
client = AWS::ElastiCache::Client.new
|
28
28
|
options = { :cache_cluster_id => cluster_id, :show_cache_node_info => true }
|
29
29
|
info = client.describe_cache_clusters(options)
|
30
30
|
info.fetch(:cache_clusters).first
|
@@ -32,7 +32,7 @@ class Hiera
|
|
32
32
|
|
33
33
|
# rubocop:disable MultilineBlockChain
|
34
34
|
def cache_clusters_in_cfn_stack(stack_name, cluster_engine = nil)
|
35
|
-
client = AWS::CloudFormation.new
|
35
|
+
client = AWS::CloudFormation.new
|
36
36
|
|
37
37
|
stack = client.stacks[stack_name]
|
38
38
|
stack.resources.select do |r|
|
@@ -13,7 +13,7 @@ class Hiera
|
|
13
13
|
require "aws-sdk"
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
setup_aws_config
|
17
17
|
|
18
18
|
Hiera.debug("AWS backend initialized")
|
19
19
|
end
|
@@ -40,17 +40,28 @@ class Hiera
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
43
|
+
def setup_aws_config
|
44
|
+
return unless Config[:aws]
|
45
|
+
|
46
|
+
aws_config = {}
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
if Config[:aws][:access_key_id] && Config[:aws][:secret_access_key]
|
49
|
+
Hiera.debug("Using AWS credentials from backend configuration")
|
50
|
+
aws_config[:access_key_id] = Config[:aws][:access_key_id]
|
51
|
+
aws_config[:secret_access_key] = Config[:aws][:secret_access_key]
|
51
52
|
else
|
52
53
|
Hiera.debug("Using AWS credentials from environment or IAM role")
|
53
54
|
end
|
55
|
+
|
56
|
+
region = Config[:aws][:region]
|
57
|
+
if region
|
58
|
+
Hiera.debug("Using AWS region '#{region}' from backend configuration")
|
59
|
+
aws_config[:region] = region
|
60
|
+
else
|
61
|
+
Hiera.debug("Using default AWS region")
|
62
|
+
end
|
63
|
+
|
64
|
+
AWS.config(aws_config)
|
54
65
|
end
|
55
66
|
|
56
67
|
def find_service_class(source)
|
data/spec/aws_backend_spec.rb
CHANGED
@@ -8,20 +8,28 @@ class Hiera
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#initialize" do
|
11
|
-
it "
|
11
|
+
it "does not change AWS configuration by default" do
|
12
12
|
Config.stub(:[]).with(:aws)
|
13
13
|
expect(AWS).to_not receive(:config)
|
14
14
|
Aws_backend.new
|
15
15
|
end
|
16
16
|
|
17
17
|
it "uses AWS credentials from backend configuration if provided" do
|
18
|
-
|
19
|
-
:access_key_id => "
|
20
|
-
:secret_access_key => "
|
18
|
+
aws_config = {
|
19
|
+
:access_key_id => "some-access-key-id",
|
20
|
+
:secret_access_key => "some-secret-access-key"
|
21
21
|
}
|
22
|
+
Config.stub(:[]).with(:aws).and_return(aws_config)
|
23
|
+
expect(AWS).to receive(:config).with(aws_config)
|
24
|
+
Aws_backend.new
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
it "uses particular AWS region if provided" do
|
28
|
+
aws_config = {
|
29
|
+
:region => "some-aws-region"
|
30
|
+
}
|
31
|
+
Config.stub(:[]).with(:aws).and_return(aws_config)
|
32
|
+
expect(AWS).to receive(:config).with(aws_config)
|
25
33
|
Aws_backend.new
|
26
34
|
end
|
27
35
|
end
|
data/spec/aws_base_spec.rb
CHANGED
@@ -25,15 +25,10 @@ class Hiera
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#aws_region" do
|
28
|
-
it "
|
28
|
+
it "returns the region set by global AWS config" do
|
29
|
+
AWS.stub(:config).and_return(double(:region => "some-region"))
|
29
30
|
service = Aws::Base.new
|
30
|
-
expect(service.aws_region).to eq "
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can be set via Puppet fact" do
|
34
|
-
scope = { "location" => "some-aws-region" }
|
35
|
-
service = Aws::Base.new scope
|
36
|
-
expect(service.aws_region).to eq "some-aws-region"
|
31
|
+
expect(service.aws_region).to eq "some-region"
|
37
32
|
end
|
38
33
|
end
|
39
34
|
|
data/spec/aws_rds_spec.rb
CHANGED
@@ -9,17 +9,17 @@ class Hiera
|
|
9
9
|
:db_instances => [
|
10
10
|
{
|
11
11
|
:db_instance_identifier => "db1",
|
12
|
-
:endpoint => { :address => "db1.
|
12
|
+
:endpoint => { :address => "db1.some-region.rds.amazonaws.com" },
|
13
13
|
:engine => "mysql"
|
14
14
|
},
|
15
15
|
{
|
16
16
|
:db_instance_identifier => "db2",
|
17
|
-
:endpoint => { :address => "db2.
|
17
|
+
:endpoint => { :address => "db2.some-region.rds.amazonaws.com" },
|
18
18
|
:engine => "mysql"
|
19
19
|
},
|
20
20
|
{
|
21
21
|
:db_instance_identifier => "db3",
|
22
|
-
:endpoint => { :address => "db3.
|
22
|
+
:endpoint => { :address => "db3.some-region.rds.amazonaws.com" },
|
23
23
|
:engine => "mysql"
|
24
24
|
}
|
25
25
|
]
|
@@ -27,18 +27,18 @@ class Hiera
|
|
27
27
|
end
|
28
28
|
let(:rds_tags) do
|
29
29
|
{
|
30
|
-
"arn:aws:rds:
|
30
|
+
"arn:aws:rds:some-region:12345678:db:db1" => {
|
31
31
|
:tag_list => [
|
32
32
|
{ :key => "environment", :value => "dev" }
|
33
33
|
]
|
34
34
|
},
|
35
|
-
"arn:aws:rds:
|
35
|
+
"arn:aws:rds:some-region:12345678:db:db2" => {
|
36
36
|
:tag_list => [
|
37
37
|
{ :key => "environment", :value => "dev" },
|
38
38
|
{ :key => "role", :value => "mgmt-db" }
|
39
39
|
]
|
40
40
|
},
|
41
|
-
"arn:aws:rds:
|
41
|
+
"arn:aws:rds:some-region:12345678:db:db3" => {
|
42
42
|
:tag_list => [
|
43
43
|
{ :key => "environment", :value => "production" },
|
44
44
|
{ :key => "role", :value => "mgmt-db" }
|
@@ -48,6 +48,8 @@ class Hiera
|
|
48
48
|
end
|
49
49
|
|
50
50
|
before do
|
51
|
+
AWS.stub(:config).and_return(double(:region => "some-region"))
|
52
|
+
|
51
53
|
rds_client = double
|
52
54
|
AWS::RDS::Client.stub(:new).and_return(rds_client)
|
53
55
|
allow(rds_client).to receive(:describe_db_instances).and_return(rds_instances)
|
@@ -67,17 +69,17 @@ class Hiera
|
|
67
69
|
end
|
68
70
|
|
69
71
|
it "returns all database instances if no tags are provided" do
|
70
|
-
expect(rds.lookup("rds", scope)).to eq ["db1.
|
71
|
-
"db2.
|
72
|
-
"db3.
|
72
|
+
expect(rds.lookup("rds", scope)).to eq ["db1.some-region.rds.amazonaws.com",
|
73
|
+
"db2.some-region.rds.amazonaws.com",
|
74
|
+
"db3.some-region.rds.amazonaws.com"]
|
73
75
|
end
|
74
76
|
|
75
77
|
it "returns database instances with specific tags" do
|
76
|
-
expect(rds.lookup("rds role=mgmt-db", scope)).to eq ["db2.
|
77
|
-
"db3.
|
78
|
-
expect(rds.lookup("rds environment=dev", scope)).to eq ["db1.
|
79
|
-
"db2.
|
80
|
-
expect(rds.lookup("rds environment=production role=mgmt-db", scope)).to eq ["db3.
|
78
|
+
expect(rds.lookup("rds role=mgmt-db", scope)).to eq ["db2.some-region.rds.amazonaws.com",
|
79
|
+
"db3.some-region.rds.amazonaws.com"]
|
80
|
+
expect(rds.lookup("rds environment=dev", scope)).to eq ["db1.some-region.rds.amazonaws.com",
|
81
|
+
"db2.some-region.rds.amazonaws.com"]
|
82
|
+
expect(rds.lookup("rds environment=production role=mgmt-db", scope)).to eq ["db3.some-region.rds.amazonaws.com"]
|
81
83
|
end
|
82
84
|
|
83
85
|
it "returns empty array if no database instances can be found" do
|
@@ -96,17 +98,17 @@ class Hiera
|
|
96
98
|
expect(rds.lookup("rds_instances", scope)).to eq [
|
97
99
|
{
|
98
100
|
"db_instance_identifier" => "db1",
|
99
|
-
"endpoint" => { "address" => "db1.
|
101
|
+
"endpoint" => { "address" => "db1.some-region.rds.amazonaws.com" },
|
100
102
|
"engine" => "mysql"
|
101
103
|
},
|
102
104
|
{
|
103
105
|
"db_instance_identifier" => "db2",
|
104
|
-
"endpoint" => { "address" => "db2.
|
106
|
+
"endpoint" => { "address" => "db2.some-region.rds.amazonaws.com" },
|
105
107
|
"engine" => "mysql"
|
106
108
|
},
|
107
109
|
{
|
108
110
|
"db_instance_identifier" => "db3",
|
109
|
-
"endpoint" => { "address" => "db3.
|
111
|
+
"endpoint" => { "address" => "db3.some-region.rds.amazonaws.com" },
|
110
112
|
"engine" => "mysql"
|
111
113
|
}
|
112
114
|
]
|
@@ -116,12 +118,12 @@ class Hiera
|
|
116
118
|
expect(rds.lookup("rds_instances role=mgmt-db", scope)).to eq [
|
117
119
|
{
|
118
120
|
"db_instance_identifier" => "db2",
|
119
|
-
"endpoint" => { "address" => "db2.
|
121
|
+
"endpoint" => { "address" => "db2.some-region.rds.amazonaws.com" },
|
120
122
|
"engine" => "mysql"
|
121
123
|
},
|
122
124
|
{
|
123
125
|
"db_instance_identifier" => "db3",
|
124
|
-
"endpoint" => { "address" => "db3.
|
126
|
+
"endpoint" => { "address" => "db3.some-region.rds.amazonaws.com" },
|
125
127
|
"engine" => "mysql"
|
126
128
|
}
|
127
129
|
]
|
@@ -131,12 +133,12 @@ class Hiera
|
|
131
133
|
expect(rds.lookup("rds_instances environment=dev", scope)).to eq [
|
132
134
|
{
|
133
135
|
"db_instance_identifier" => "db1",
|
134
|
-
"endpoint" => { "address" => "db1.
|
136
|
+
"endpoint" => { "address" => "db1.some-region.rds.amazonaws.com" },
|
135
137
|
"engine" => "mysql"
|
136
138
|
},
|
137
139
|
{
|
138
140
|
"db_instance_identifier" => "db2",
|
139
|
-
"endpoint" => { "address" => "db2.
|
141
|
+
"endpoint" => { "address" => "db2.some-region.rds.amazonaws.com" },
|
140
142
|
"engine" => "mysql"
|
141
143
|
}
|
142
144
|
]
|
@@ -146,7 +148,7 @@ class Hiera
|
|
146
148
|
expect(rds.lookup("rds_instances environment=production role=mgmt-db", scope)).to eq [
|
147
149
|
{
|
148
150
|
"db_instance_identifier" => "db3",
|
149
|
-
"endpoint" => { "address" => "db3.
|
151
|
+
"endpoint" => { "address" => "db3.some-region.rds.amazonaws.com" },
|
150
152
|
"engine" => "mysql"
|
151
153
|
}
|
152
154
|
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Lafeldt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|