idlc-sdk-deploy 1.0.11 → 1.0.12
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 +5 -5
- data/lib/idlc-sdk-deploy.rb +2 -0
- data/lib/idlc-sdk-deploy/config.rb +101 -34
- data/lib/idlc-sdk-deploy/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0a80d2a39a02c2bdc8c471068b422f9511794ac368bed6051217270746cfbd21
|
4
|
+
data.tar.gz: b404bd025951c6b183672aebd8b50d2d280114128ebf85c13b5ab166e6ceae03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e471ff597f02e73f0a2435f51c3adde4dd627ba51ceaad8805b4cade420f096ae1fc5b9473a98e4adecda6c376d4c3215675a88ba1b208cd570ae8167b0fdbb1
|
7
|
+
data.tar.gz: df78e0e97c73a1959b9b5554f3c7126112510833a130347bdd2a2e4d03896db90d9226ff534c1d3117ce2c389c91f6cd8421e9ea8b600d996622c791d456cf53
|
data/lib/idlc-sdk-deploy.rb
CHANGED
@@ -22,43 +22,23 @@ module Idlc
|
|
22
22
|
`#{Terraform::Binary::Command.binary} output #{key}`.strip!
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
request = {
|
29
|
-
service: 'deploy',
|
30
|
-
method: 'GET',
|
31
|
-
lambda: 'metadata',
|
32
|
-
pathParameters: {
|
33
|
-
jobName: env_key
|
34
|
-
}
|
35
|
-
}
|
36
|
-
metadata = client.fetch(request)['deployments'].first
|
37
|
-
|
38
|
-
request = {
|
39
|
-
service: 'config',
|
40
|
-
method: 'GET',
|
41
|
-
lambda: "accounts",
|
42
|
-
pathParameters: {
|
43
|
-
accountName: metadata['environment']['account_alias']
|
44
|
-
}
|
45
|
-
}
|
46
|
-
account = client.fetch(request)
|
25
|
+
def whoami
|
26
|
+
# This method is meant to be run on an instance inside of a chef run to
|
27
|
+
# provision instance and environment metadata.
|
47
28
|
|
48
|
-
|
29
|
+
# `default` is a reserved var available in a Chef run
|
49
30
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
appName: metadata['environment']['application_name'].downcase
|
56
|
-
}
|
57
|
-
}
|
58
|
-
application = client.fetch(request)
|
31
|
+
ENV['AWS_REGION'] = 'us-east-1' if ENV['AWS_REGION'].nil?
|
32
|
+
default['aws']['region'] = ENV['AWS_REGION']
|
33
|
+
|
34
|
+
# Get the current instance id from the instance metadata.
|
35
|
+
instance = get_instance
|
59
36
|
|
60
|
-
|
61
|
-
|
37
|
+
default['environment_key'] = instance['tags']['environment_key']
|
38
|
+
default['curr_node']['hostname'] = set_hostname(instance)
|
39
|
+
|
40
|
+
# return environment metadata
|
41
|
+
get_env_metadata(instance['tags']['environment_key'])
|
62
42
|
end
|
63
43
|
end
|
64
44
|
|
@@ -99,6 +79,93 @@ module Idlc
|
|
99
79
|
|
100
80
|
private
|
101
81
|
|
82
|
+
def get_instance
|
83
|
+
# Get the current instance id from the instance metadata.
|
84
|
+
metadata_endpoint = 'http://169.254.169.254/latest/meta-data/'
|
85
|
+
instance_id = Net::HTTP.get( URI.parse( metadata_endpoint + 'instance-id' ) )
|
86
|
+
|
87
|
+
# Create instance object with instance id.
|
88
|
+
instance = Aws::EC2::Instance.new( id: instance_id, region: ENV['AWS_REGION'] )
|
89
|
+
instance['instance_id'] = instance_id
|
90
|
+
|
91
|
+
instance.tags.each do |tag|
|
92
|
+
# Grab all of the tags as node attributes
|
93
|
+
instance['tags'][tag.key] = tag.value
|
94
|
+
end
|
95
|
+
|
96
|
+
instance
|
97
|
+
end
|
98
|
+
|
99
|
+
def set_hostname (instance)
|
100
|
+
hostname = instance['tags']['Name']
|
101
|
+
|
102
|
+
unless (instance['tags']['Name'].start_with? 'db')
|
103
|
+
# Use instance id for unique hostname
|
104
|
+
hostname = instance['tags']['Name'][0..4] + '-' + instance['instance_id'][2..10]
|
105
|
+
end
|
106
|
+
|
107
|
+
instance.create_tags(
|
108
|
+
dry_run: false,
|
109
|
+
tags: [ # required
|
110
|
+
{
|
111
|
+
key: 'hostname',
|
112
|
+
value: hostname
|
113
|
+
}
|
114
|
+
]
|
115
|
+
)
|
116
|
+
|
117
|
+
#return
|
118
|
+
hostname
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_env_metadata(env_key)
|
122
|
+
client = Idlc::AWSLambdaProxy.new()
|
123
|
+
|
124
|
+
request = {
|
125
|
+
service: 'deploy',
|
126
|
+
method: 'GET',
|
127
|
+
lambda: 'metadata',
|
128
|
+
pathParameters: {
|
129
|
+
jobName: env_key
|
130
|
+
}
|
131
|
+
}
|
132
|
+
metadata = client.fetch(request)['deployments'].first
|
133
|
+
|
134
|
+
request = {
|
135
|
+
service: 'config',
|
136
|
+
method: 'GET',
|
137
|
+
lambda: "accounts",
|
138
|
+
pathParameters: {
|
139
|
+
accountName: metadata['environment']['account_alias']
|
140
|
+
}
|
141
|
+
}
|
142
|
+
account = client.fetch(request)
|
143
|
+
|
144
|
+
metadata['account'] = account['accounts'].first
|
145
|
+
|
146
|
+
request = {
|
147
|
+
service: 'config',
|
148
|
+
method: 'GET',
|
149
|
+
lambda: "applications",
|
150
|
+
pathParameters: {
|
151
|
+
appName: metadata['environment']['application_name'].downcase
|
152
|
+
}
|
153
|
+
}
|
154
|
+
application = client.fetch(request)
|
155
|
+
|
156
|
+
metadata['application'] = application['applications'].first
|
157
|
+
|
158
|
+
# find db instance
|
159
|
+
metadata['instances'].each do |instance|
|
160
|
+
if instance['hostname'].start_with? 'db'
|
161
|
+
metadata['db_instance'] = instance
|
162
|
+
break
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
metadata
|
167
|
+
end
|
168
|
+
|
102
169
|
def configure_tfstatev8(bucket, sub_bucket, working_directory)
|
103
170
|
args = []
|
104
171
|
args << '-backend=s3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idlc-sdk-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Cazell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
requirements: []
|
226
226
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.7.3
|
228
228
|
signing_key:
|
229
229
|
specification_version: 4
|
230
230
|
summary: IDLC SDK for AWS resources - Deploy
|