autostacker24 1.0.56 → 1.0.57

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: 7a292522f66a4a0c65a49548c90d5de96d25e6eb
4
- data.tar.gz: 3c28395eb048674ab82d701a93ba7672f065c120
3
+ metadata.gz: 6b9061f0245437aac8fb55ed942950963c637d01
4
+ data.tar.gz: 2dd618bddd219ffd00c0f66e807816ce9ed6afc8
5
5
  SHA512:
6
- metadata.gz: e17384a0e173a5c35842e2c61175920e0a076bab2bc6ae51bd1b6754693683b52d6d784714e474b5a5100042d22fba632ddc30169910f288f63b31d6db2591a7
7
- data.tar.gz: 5d5624920bc31371884d7d78de9946185dd9d0b80a4ebb2e484204ad68e98b94514bfc46a137a3a9fc74c25b67fcf9326431c403fa6a0b6dd4d164c541b2487b
6
+ metadata.gz: 37a4b4685dd4736ca2ce1ec30e784f4b827996714381e33294d64ff70b44f318ebf0228fb0ff301b031c0f2cb83d328354182195a32e0a9658338c838f7636c0
7
+ data.tar.gz: dd10f37cddeebb519fb9c1ca8110e7eb5f020367661775173a38e74550e91149710f1307f2132617c16b145ff1b8958866a7cf7a0fc236019c9f180993fc363d
@@ -22,30 +22,30 @@ module Stacker
22
22
  end
23
23
  end
24
24
 
25
- def create_or_update_stack(stack_name, template, parameters, parent_stack_name = nil)
25
+ def create_or_update_stack(stack_name, template, parameters, parent_stack_name = nil, tags = nil)
26
26
  if find_stack(stack_name).nil?
27
- create_stack(stack_name, template, parameters, parent_stack_name)
27
+ create_stack(stack_name, template, parameters, parent_stack_name, tags)
28
28
  else
29
- update_stack(stack_name, template, parameters, parent_stack_name)
29
+ update_stack(stack_name, template, parameters, parent_stack_name, tags)
30
30
  end
31
31
  end
32
32
 
33
- def create_stack(stack_name, template, parameters, parent_stack_name = nil)
33
+ def create_stack(stack_name, template, parameters, parent_stack_name = nil, tags = nil)
34
34
  merge_and_validate(template, parameters, parent_stack_name)
35
35
  cloud_formation.create_stack(stack_name: stack_name,
36
- template_body: template_body(template),
36
+ template_body: template_body(template, tags),
37
37
  on_failure: 'DELETE',
38
38
  parameters: transform_input(parameters),
39
39
  capabilities: ['CAPABILITY_IAM'])
40
40
  wait_for_stack(stack_name, :create)
41
41
  end
42
42
 
43
- def update_stack(stack_name, template, parameters, parent_stack_name = nil)
43
+ def update_stack(stack_name, template, parameters, parent_stack_name = nil, tags = nil)
44
44
  seen_events = get_stack_events(stack_name).map {|e| e[:event_id]}
45
45
  begin
46
46
  merge_and_validate(template, parameters, parent_stack_name)
47
47
  cloud_formation.update_stack(stack_name: stack_name,
48
- template_body: template_body(template),
48
+ template_body: template_body(template, tags),
49
49
  parameters: transform_input(parameters),
50
50
  capabilities: ['CAPABILITY_IAM'])
51
51
  rescue Aws::CloudFormation::Errors::ValidationError => error
@@ -74,8 +74,8 @@ module Stacker
74
74
  end
75
75
  private :merge_and_validate
76
76
 
77
- def validate_template(template)
78
- cloud_formation.validate_template(template_body: template_body(template))
77
+ def validate_template(template, tags = nil)
78
+ cloud_formation.validate_template(template_body: template_body(template, tags))
79
79
  end
80
80
 
81
81
  def delete_stack(stack_name)
@@ -111,6 +111,10 @@ module Stacker
111
111
  raise "waiting for #{operation} stack #{stack_name} timed out after #{timeout_in_minutes} minutes"
112
112
  end
113
113
 
114
+ def get_template(stack_name)
115
+ cloud_formation.get_template(stack_name: stack_name).template_body
116
+ end
117
+
114
118
  def find_stack(stack_name)
115
119
  cloud_formation.describe_stacks(stack_name: stack_name).stacks.first
116
120
  rescue Aws::CloudFormation::Errors::ValidationError => error
@@ -169,9 +173,9 @@ module Stacker
169
173
  @lazy_cloud_formation
170
174
  end
171
175
 
172
- def template_body(template)
176
+ def template_body(template, tags = nil)
173
177
  template = File.read(template) if File.exists?(template)
174
- AutoStacker24::Preprocessor.preprocess(template)
178
+ AutoStacker24::Preprocessor.preprocess(template, tags)
175
179
  end
176
180
 
177
181
  extend self
@@ -5,14 +5,80 @@ module AutoStacker24
5
5
 
6
6
  module Preprocessor
7
7
 
8
- def self.preprocess(template)
8
+ def self.preprocess(template, tags = nil)
9
9
  if template =~ /^\s*\/{2}\s*/i
10
10
  template = template.gsub(/(\s*\/\/.*$)|(".*")/) {|m| m[0] == '"' ? m : ''} # replace comments
11
- template = preprocess_json(JSON(template)).to_json
11
+ template = preprocess_json(JSON(template))
12
+ template = preprocess_tags(template, tags).to_json
12
13
  end
13
14
  template
14
15
  end
15
16
 
17
+ def self.preprocess_tags(template, tags = nil)
18
+
19
+ supportedTypes = [
20
+ 'AWS::AutoScaling::AutoScalingGroup',
21
+ 'AWS::CloudTrail::Trail',
22
+ 'AWS::EC2::CustomerGateway',
23
+ 'AWS::EC2::DHCPOptions',
24
+ 'AWS::EC2::Instance',
25
+ 'AWS::EC2::InternetGateway',
26
+ 'AWS::EC2::NetworkAcl',
27
+ 'AWS::EC2::NetworkInterface',
28
+ 'AWS::EC2::RouteTable',
29
+ 'AWS::EC2::SecurityGroup',
30
+ 'AWS::EC2::Subnet',
31
+ 'AWS::EC2::Volume',
32
+ 'AWS::EC2::VPC',
33
+ 'AWS::EC2::VPCPeeringConnection',
34
+ 'AWS::EC2::VPNConnection',
35
+ 'AWS::EC2::VPNGateway',
36
+ 'AWS::ElasticBeanstalk::Environment',
37
+ 'AWS::ElasticLoadBalancing::LoadBalancer',
38
+ 'AWS::RDS::DBCluster',
39
+ 'AWS::RDS::DBClusterParameterGroup',
40
+ 'AWS::RDS::DBInstance',
41
+ 'AWS::RDS::DBParameterGroup',
42
+ 'AWS::RDS::DBSecurityGroup',
43
+ 'AWS::RDS::DBSubnetGroup',
44
+ 'AWS::RDS::OptionGroup',
45
+ 'AWS::S3::Bucket'
46
+ ]
47
+
48
+ unless tags.nil?
49
+
50
+ tags_for_asg = adjust_tags_for_asg(tags)
51
+
52
+ template["Resources"].each {|(key, value)|
53
+
54
+ tags_to_apply = tags
55
+ if value["Type"] == 'AWS::AutoScaling::AutoScalingGroup'
56
+ tags_to_apply = tags_for_asg
57
+ end
58
+
59
+ if supportedTypes.include? value["Type"]
60
+ if value["Properties"]["Tags"].nil?
61
+ value["Properties"]["Tags"] = tags_to_apply
62
+ else
63
+ value["Properties"]["Tags"] = (tags_to_apply + value["Properties"]["Tags"]).uniq { |s| s.first }
64
+ end
65
+ end
66
+ }
67
+ end
68
+
69
+ template
70
+ end
71
+
72
+ def self.adjust_tags_for_asg(tags)
73
+ asg_tags = tags.inject([]) { |t,element| t << element.dup }
74
+
75
+ asg_tags.each {|(tag)|
76
+ tag["PropagateAtLaunch"] = "true"
77
+ }
78
+
79
+ asg_tags
80
+ end
81
+
16
82
  def self.preprocess_json(json)
17
83
  if json.is_a?(Hash)
18
84
  json.inject({}){|m, (k, v)| m.merge(k => preprocess_json(v))}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autostacker24
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.56
4
+ version: 1.0.57
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Mueller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-06 00:00:00.000000000 Z
12
+ date: 2016-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-core