build-cloud 1.1.2 → 1.1.3

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
  SHA256:
3
- metadata.gz: fb00e8848e9205bae96b54c380b62c62159f2f38116ac6f4786ff52efab7173c
4
- data.tar.gz: 23375d3dd6df3a8a4a48a36370891e0a2b460b547577c09a83d80d26a0d077eb
3
+ metadata.gz: ad8c7b556fc7107ea38511b167401391c61b05f7b41b7c690ebf5cb49401c1d3
4
+ data.tar.gz: 0baf22d231dcab8c8e41312cce20fb616a4e7d50115f30f250e8ea13f2715887
5
5
  SHA512:
6
- metadata.gz: a019d4ab77af8be41c80502f60980ae3df2655260aa1a0a4552788e87c9b8cf4144736ffdcd3454de635fbc5a7b6b58756b616fdbda9a260f9b6efc0cbd7f603
7
- data.tar.gz: 3b31d034ab11827faaba18630962faa13a649dddbed4dd921e71459e120557db1e2700f48d91d4b2215c25f3d3bb3dbfcfde2a561201e43b04645d6400465c45
6
+ metadata.gz: 833765e82f0b1314bbc8e9a076c1fe9095269d81fa81d465bcb51483304e5a42197c8b8c34117cbfe127707139777bef1acff6cdb4160f7894a046cb733ce554
7
+ data.tar.gz: e242267e725571e67db99de3a9949871126c09a3a81a1ee1acec0ad279abbe6c102604d4343521dee1ce3f8c5bc4c7a12ad91956237888d150d5906a77ed2733
data/CHANGELOG.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ 2018-04-12 - version 1.1.3 - EC2 instances and ASG now add missing tags.
4
+
3
5
  2018-04-12 - version 1.1.2 - version bump.
4
6
 
5
- 2018-04-12 - version 1.0.1 - VPC's now lifecycle tags.
7
+ 2018-04-12 - version 1.0.1 - VPC's now add missing tags.
6
8
 
7
9
  2017-11-13 - version 0.0.24 - Fix a bug which prevented working with IAM roles in AWS accounts with more than 100 roles. Thank you @markchalloner!
8
10
 
data/build-cloud.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "build-cloud"
7
- spec.version = "1.1.2"
7
+ spec.version = "1.1.3"
8
8
  spec.authors = ["The Scale Factory"]
9
9
  spec.email = ["info@scalefactory.com"]
10
10
  spec.summary = %q{Tools for building resources in AWS}
@@ -19,13 +19,19 @@ class BuildCloud::ASGroup
19
19
  end
20
20
 
21
21
  def create
22
-
23
- return if exists?
24
-
25
- @log.info( "Creating AS Group #{@options[:id]}" )
26
22
 
27
23
  options = @options.dup
28
24
 
25
+ if exists?
26
+ # If exists update tags
27
+ if options[:tags]
28
+ create_tags(options[:tags])
29
+ end
30
+ return
31
+ end
32
+
33
+ @log.info( "Creating AS Group #{options[:id]}" )
34
+
29
35
  unless options[:vpc_zone_identifier]
30
36
 
31
37
  subnet_ids = []
@@ -69,4 +75,30 @@ class BuildCloud::ASGroup
69
75
 
70
76
  end
71
77
 
78
+ def create_tags(tags)
79
+ @log.debug("Tags passed in: #{tags.inspect}")
80
+ @log.debug("Current tags: #{fog_object.tags.inspect}")
81
+ tag_array = fog_object.tags.dup
82
+ tags.each do |k,v|
83
+ if tag_array.find {|t| t['Key'] == k }
84
+ unless tag_array.find {|t| t['Value'] == v }
85
+ tag_array.find {|t| t['Value'] = v }
86
+ end
87
+ else
88
+ tag_array << {
89
+ "ResourceId" => fog_object.id,
90
+ "PropagateAtLaunch" => true,
91
+ "Key" => k,
92
+ "Value" => v,
93
+ "ResourceType" => "auto-scaling-group"
94
+ }
95
+ end
96
+ end
97
+ @log.debug("Tags to act on: #{tag_array.inspect}")
98
+ if tag_array != fog_object.tags
99
+ @log.info("Updating tags for ASG #{fog_object.id}")
100
+ @as.create_or_update_tags( tag_array )
101
+ end
102
+ end
103
+
72
104
  end
@@ -47,13 +47,19 @@ class BuildCloud::Instance
47
47
  end
48
48
 
49
49
  def create
50
-
51
- return if exists?
52
-
53
- @log.info( "Creating instance #{@options[:name]}" )
54
50
 
55
51
  options = @options.dup
56
52
 
53
+ if exists?
54
+ # If exists update tags
55
+ if options[:tags]
56
+ create_tags(options[:tags])
57
+ end
58
+ return
59
+ end
60
+
61
+ @log.info( "Creating instance #{options[:name]}" )
62
+
57
63
  if options[:security_group_names] or options[:security_group_ids]
58
64
  unless options[:security_group_ids]
59
65
 
@@ -223,4 +229,13 @@ class BuildCloud::Instance
223
229
 
224
230
  end
225
231
 
232
+ def create_tags(tags)
233
+ # force symbols to strings in yaml tags
234
+ resolved_tags = fog_object.tags.dup.merge(tags.collect{|k,v| [k.to_s, v]}.to_h)
235
+ if resolved_tags != fog_object.tags
236
+ @log.info("Updating tags for EC2 instance #{fog_object.id}")
237
+ @ec2.create_tags( fog_object.id, tags )
238
+ end
239
+ end
240
+
226
241
  end
@@ -50,7 +50,7 @@ class BuildCloud::VPC
50
50
  end
51
51
 
52
52
 
53
- @log.info( "Creating new VPC for #{@options[:cidr_block]}" )
53
+ @log.info( "Creating new VPC for #{options[:cidr_block]}" )
54
54
 
55
55
  vpc = @compute.vpcs.new( options )
56
56
  vpc.save
@@ -93,9 +93,11 @@ class BuildCloud::VPC
93
93
  end
94
94
 
95
95
  def create_tags(tags)
96
- if tags != fog_object.tags
97
- @log.info("Updating tags")
98
- @compute.create_tags( fog_object.id, tags )
96
+ # force symbols to strings in yaml tags
97
+ resolved_tags = fog_object.tags.dup.merge(tags.collect{|k,v| [k.to_s, v]}.to_h)
98
+ if resolved_tags != fog_object.tags
99
+ @log.info("Updating tags for VPC #{fog_object.id}")
100
+ @ec2.create_tags( fog_object.id, tags )
99
101
  end
100
102
  end
101
103
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Scale Factory
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-20 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.7.6
150
+ rubygems_version: 2.7.7
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Tools for building resources in AWS