terraforming 0.1.2 → 0.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
  SHA1:
3
- metadata.gz: 3a6da3b6025e72dbde110224ba597ae281004e64
4
- data.tar.gz: a8ab14e29325070270895d2bd7d9dfc1f456bb64
3
+ metadata.gz: 0f2efd2fcc749aae8e786423ae3e8d46be4cf852
4
+ data.tar.gz: b99a7cfe20ed485d646fe455b1e38c225bdbbf9d
5
5
  SHA512:
6
- metadata.gz: 7611a6cc8554f7661ff3c579306becffc4da9ed077e8087b7c1e68e57b14eed25cbdb7d1e8d342fd4c547daf1c1788ed9ec30b22c4eba19c46d66458d8bfbc67
7
- data.tar.gz: 8435e655557d88686a783ae7045a0ecd8a5deb10514be0645372caf92eb7855f49024b10294be8faeb78caaf6d49be1f18b39009c6d2997611fcfd205de4c1ec
6
+ metadata.gz: 1caa9dd2b3d02d284643323c9cc0c3977e7765dec2efe61b517e9da24d084313b5b20e6731d5a691cf967576a870ce41d23c57d38c0f70eb9da18a42e40a145a
7
+ data.tar.gz: a369651650377159062123d710077bc9529177a110c94488d33ca41fc9dd59e55396e686de6f59b0d237479508614bfff8747a69e46bd09d12aa3135bb693d5b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
+ # [v0.1.3](https://github.com/dtan4/terraforming/releases/tag/v0.1.3) (2015-08-01)
2
+
3
+ ### Fixed
4
+
5
+ - Generate correct tf and tfstate if EC2 instance has no attached EBS #104
6
+ - Generate correct tfstate of Security Group #101 (thanks @grosendorf)
7
+
1
8
  # [v0.1.2](https://github.com/dtan4/terraforming/releases/tag/v0.1.2) (2015-07-30)
2
9
 
3
- ## Fixed
10
+ ### Fixed
4
11
 
5
12
  - Generate correct tf and tfstate of EC2 #94, #102
6
13
  - Handle multiple Route53 record types #99 (thanks @nicgrayson)
@@ -70,6 +70,7 @@ module Terraforming
70
70
  end
71
71
 
72
72
  def block_devices_of(instance)
73
+ return [] unless instance.block_device_mappings.length > 0
73
74
  @client.describe_volumes(volume_ids: block_device_ids_of(instance)).volumes
74
75
  end
75
76
 
@@ -52,7 +52,7 @@ module Terraforming
52
52
  def ingress_attributes_of(security_group)
53
53
  attributes = { "ingress.#" => security_group.ip_permissions.length.to_s }
54
54
 
55
- security_group.ip_permissions.each do |permission|
55
+ dedup_permissions(security_group).ip_permissions.each do |permission|
56
56
  attributes.merge!(permission_attributes_of(security_group, permission, "ingress"))
57
57
  end
58
58
 
@@ -62,7 +62,7 @@ module Terraforming
62
62
  def egress_attributes_of(security_group)
63
63
  attributes = { "egress.#" => security_group.ip_permissions_egress.length.to_s }
64
64
 
65
- security_group.ip_permissions_egress.each do |permission|
65
+ dedup_permissions(security_group).ip_permissions_egress.each do |permission|
66
66
  attributes.merge!(permission_attributes_of(security_group, permission, "egress"))
67
67
  end
68
68
 
@@ -101,6 +101,50 @@ module Terraforming
101
101
  attributes
102
102
  end
103
103
 
104
+ def dedup_permissions(security_group)
105
+ grouped_ingress = security_group.ip_permissions.group_by {|perm| [perm.ip_protocol, perm.to_port, perm.from_port]}
106
+ grouped_egress = security_group.ip_permissions_egress.group_by {|perm| [perm.ip_protocol, perm.to_port, perm.from_port]}
107
+
108
+ security_group.ip_permissions = []
109
+ security_group.ip_permissions_egress = []
110
+
111
+ grouped_ingress.each do |range, perms|
112
+ if perms.length == 1
113
+ security_group.ip_permissions << perms.first
114
+ else
115
+ g_ids = perms.map {|perm| perm.user_id_group_pairs}.flatten.map {|gp| gp.group_id}
116
+ if g_ids.length == 1 && g_ids.first == security_group.group_id
117
+ security_group.ip_permissions << merge_perms(perms)
118
+ else
119
+ security_group.ip_permissions.concat(perms)
120
+ end
121
+ end
122
+ end
123
+
124
+ grouped_egress.each do |range, perms|
125
+ if perms.length == 1
126
+ security_group.ip_permissions_egress << perms.first
127
+ else
128
+ g_ids = perms.map {|perm| perm.user_id_group_pairs}.flatten.map {|gp| gp.group_id}
129
+ if g_ids.length == 1 && g_ids.first == security_group.group_id
130
+ security_group.ip_permissions_egress << merge_perms(perms)
131
+ else
132
+ security_group.ip_permissions_egress.concat(perms)
133
+ end
134
+ end
135
+ end
136
+ security_group
137
+ end
138
+
139
+ def merge_perms(permissions)
140
+ master_perm = permissions.pop
141
+ permissions.each do |perm|
142
+ master_perm.user_id_group_pairs.concat(perm.user_id_group_pairs)
143
+ master_perm.ip_ranges.concat(perm.ip_ranges)
144
+ end
145
+ master_perm
146
+ end
147
+
104
148
  def permission_hashcode_of(security_group, permission)
105
149
  string =
106
150
  "#{permission.from_port || 0}-" <<
@@ -4,7 +4,7 @@ resource "aws_security_group" "<%= module_name_of(security_group) %>" {
4
4
  description = "<%= security_group.description %>"
5
5
  vpc_id = "<%= security_group.vpc_id || '' %>"
6
6
 
7
- <% security_group.ip_permissions.each do |permission| -%>
7
+ <% dedup_permissions(security_group).ip_permissions.each do |permission| -%>
8
8
  <%- security_groups = security_groups_in(permission).reject { |group_id| group_id == security_group.group_id } -%>
9
9
  ingress {
10
10
  from_port = <%= permission.from_port || 0 %>
@@ -24,7 +24,7 @@ resource "aws_security_group" "<%= module_name_of(security_group) %>" {
24
24
 
25
25
  <% end -%>
26
26
 
27
- <% security_group.ip_permissions_egress.each do |permission| -%>
27
+ <% dedup_permissions(security_group).ip_permissions_egress.each do |permission| -%>
28
28
  egress {
29
29
  from_port = <%= permission.from_port || 0 %>
30
30
  to_port = <%= permission.to_port || 0 %>
@@ -1,3 +1,3 @@
1
1
  module Terraforming
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraforming
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Fujita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2015-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk