terraforming 0.2.0 → 0.3.0

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: 579938c93e511511d9d81db6dc0832eee5300fea
4
- data.tar.gz: 91c1d9a93cf0e2381cab45436c33d5ea4113708f
3
+ metadata.gz: a06eef6162629702c7d05c7c0db5925f7935888b
4
+ data.tar.gz: 258afec05eb52e63b257660bfc4db4197240c0df
5
5
  SHA512:
6
- metadata.gz: e7ea11e17c9334bb607ae216ccc5429b9a7ee54b24d2f3322e5204f5a7b751af26ac9018edcfe174bc581b679fa6c860eb8d2ccf41eebfd3e48ca22fbbd9ea7b
7
- data.tar.gz: c3f17f500258953ad9f5150b806ca0f5ecafee13edc25dcd7e96074e1334f32fed8045fe514205178b791f1bbf8362d94d8a2fda5550bf620b82e54b8442ebe1
6
+ metadata.gz: 0d5cd22e89677dd168ebeb2883d47f9bdf98b47c76e0a42ea3b0e913c01d65df6bcf2ddf616b3e998312fd7c3b924b28d1281d1284d68f558fa7db50a579d9ff
7
+ data.tar.gz: db7af6de24c20eb6a78e2495fae54856955938960015d9f640e6d3c999ff669accbc1c09457e109a68bab8271300d773a02f92ff169f7894b38da2de70637818
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
- - 2.1
3
+ - 2.2.3
4
+ - 2.1.7
5
5
  - 2.0
6
6
  env:
7
7
  - secure: n0mxwnyjuXI4mJO4mp++2TnsPJ+XgCF/J1U2L5piE5j3xMhSU+5V0JrA1uFlS0Pemb44M7BjgmF9S4G35BwyAQpctpCYhqy9tFa6+Y6nxEv5hCv2cZz7BSAZM6eb+zq20409hxTHRaQOr1DBeE4R5S2PrmOXRqvYfTRv3LNSLFk=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # [v0.3.0](https://github.com/dtan4/terraforming/releases/tag/v0.3.0) (2015-08-23)
2
+
3
+ ## Resource
4
+
5
+ - AWS Network Interface #127 (thanks @sakazuki)
6
+ - AWS Elastic IP #124 (thanks @sakazuki)
7
+
8
+ ## Fixed
9
+
10
+ - Normalize module name of IAM user #129
11
+
1
12
  # [v0.2.0](https://github.com/dtan4/terraforming/releases/tag/v0.2.0) (2015-08-22)
2
13
 
3
14
  ## New feature
@@ -11,10 +22,6 @@
11
22
  - Include associated VPC parameters in Route53 hosted zone #119
12
23
  - Support Route53 hosted zone with empty delegation set #118
13
24
 
14
- ### Fixed
15
-
16
- - Stop including ElastiCache port at any time #112
17
-
18
25
  # [v0.1.6](https://github.com/dtan4/terraforming/releases/tag/v0.1.6) (2015-08-10)
19
26
 
20
27
  ### Fixed
@@ -34,6 +34,11 @@ module Terraforming
34
34
  execute(Terraforming::Resource::ElastiCacheSubnetGroup, options)
35
35
  end
36
36
 
37
+ desc "eip", "EIP"
38
+ def eip
39
+ execute(Terraforming::Resource::EIP, options)
40
+ end
41
+
37
42
  desc "elb", "ELB"
38
43
  def elb
39
44
  execute(Terraforming::Resource::ELB, options)
@@ -89,6 +94,11 @@ module Terraforming
89
94
  execute(Terraforming::Resource::NetworkACL, options)
90
95
  end
91
96
 
97
+ desc "nif", "Network Interface"
98
+ def nif
99
+ execute(Terraforming::Resource::NetworkInterface, options)
100
+ end
101
+
92
102
  desc "r53r", "Route53 Record"
93
103
  def r53r
94
104
  execute(Terraforming::Resource::Route53Record, options)
@@ -0,0 +1,58 @@
1
+ module Terraforming
2
+ module Resource
3
+ class EIP
4
+ include Terraforming::Util
5
+
6
+ def self.tf(client: Aws::EC2::Client.new)
7
+ self.new(client).tf
8
+ end
9
+
10
+ def self.tfstate(client: Aws::EC2::Client.new)
11
+ self.new(client).tfstate
12
+ end
13
+
14
+ def initialize(client)
15
+ @client = client
16
+ end
17
+
18
+ def tf
19
+ apply_template(@client, "tf/eip")
20
+ end
21
+
22
+ def tfstate
23
+ eips.inject({}) do |resources, addr|
24
+ attributes = {
25
+ "association_id" => addr.association_id,
26
+ "domain" => addr.domain,
27
+ "id" => addr.allocation_id,
28
+ "instance" => addr.instance_id,
29
+ "network_interface" => addr.network_interface_id,
30
+ "private_ip" => addr.private_ip_address,
31
+ "public_ip" => addr.public_ip,
32
+ "vpc" => is_vpc?(addr).to_s,
33
+ }
34
+ attributes.delete_if{|k, v| v.nil?}
35
+ resources["aws_eip.#{addr.allocation_id}"] = {
36
+ "type" => "aws_eip",
37
+ "primary" => {
38
+ "id" => addr.allocation_id,
39
+ "attributes" => attributes
40
+ }
41
+ }
42
+
43
+ resources
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def eips
50
+ @client.describe_addresses.addresses
51
+ end
52
+
53
+ def is_vpc?(addr)
54
+ addr.domain.eql?("vpc")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -28,7 +28,7 @@ module Terraforming
28
28
  "path" => user.path,
29
29
  "unique_id" => user.user_id,
30
30
  }
31
- resources["aws_iam_user.#{user.user_name}"] = {
31
+ resources["aws_iam_user.#{module_name_of(user)}"] = {
32
32
  "type" => "aws_iam_user",
33
33
  "primary" => {
34
34
  "id" => user.user_name,
@@ -45,6 +45,10 @@ module Terraforming
45
45
  def iam_users
46
46
  @client.list_users.users
47
47
  end
48
+
49
+ def module_name_of(user)
50
+ normalize_module_name(user.user_name)
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -0,0 +1,69 @@
1
+ module Terraforming
2
+ module Resource
3
+ class NetworkInterface
4
+ include Terraforming::Util
5
+
6
+ def self.tf(client: Aws::EC2::Client.new)
7
+ self.new(client).tf
8
+ end
9
+
10
+ def self.tfstate(client: Aws::EC2::Client.new)
11
+ self.new(client).tfstate
12
+ end
13
+
14
+ def initialize(client)
15
+ @client = client
16
+ end
17
+
18
+ def tf
19
+ apply_template(@client, "tf/network_interface")
20
+ end
21
+
22
+ def tfstate
23
+ network_interfaces.inject({}) do |resources, network_interface|
24
+ attributes = {
25
+ "attachment.#" => attachment_of(network_interface) ? "1" : "0",
26
+ "id" => network_interface.network_interface_id,
27
+ "private_ips.#" => private_ips_of(network_interface).length.to_s,
28
+ "security_groups.#" => security_groups_of(network_interface).length.to_s,
29
+ "source_dest_check" => network_interface.source_dest_check.to_s,
30
+ "subnet_id" => network_interface.subnet_id,
31
+ "tags.#" => network_interface.tag_set.length.to_s,
32
+ }
33
+ resources["aws_network_interface.#{module_name_of(network_interface)}"] = {
34
+ "type" => "aws_network_interface",
35
+ "primary" => {
36
+ "id" => network_interface.network_interface_id,
37
+ "attributes" => attributes
38
+ }
39
+ }
40
+
41
+ resources
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def attachment_of(network_interface)
48
+ network_interface.attachment
49
+ end
50
+
51
+ def private_ips_of(network_interface)
52
+ network_interface.private_ip_addresses.map{|addr| addr.private_ip_address }
53
+ end
54
+
55
+ def security_groups_of(network_interface)
56
+ network_interface.groups.map { |group| group.group_id }
57
+ end
58
+
59
+ def module_name_of(network_interface)
60
+ network_interface.network_interface_id
61
+ end
62
+
63
+ def network_interfaces
64
+ @client.describe_network_interfaces.network_interfaces
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ <% eips.each do |addr| -%>
2
+ resource "aws_eip" "<%= addr.allocation_id %>" {
3
+ <% if addr.instance_id -%>
4
+ instance = "<%= addr.instance_id %>"
5
+ <% elsif addr.network_interface_id -%>
6
+ network_interface_id = "<%= addr.network_interface_id %>"
7
+ <% end -%>
8
+ vpc = <%= is_vpc?(addr) %>
9
+ }
10
+
11
+ <% end -%>
@@ -1,5 +1,5 @@
1
1
  <% iam_users.each do |user| -%>
2
- resource "aws_iam_user" "<%= user.user_name %>" {
2
+ resource "aws_iam_user" "<%= module_name_of(user) %>" {
3
3
  name = "<%= user.user_name %>"
4
4
  path = "<%= user.path %>"
5
5
  }
@@ -0,0 +1,22 @@
1
+ <% network_interfaces.each do |network_interface| -%>
2
+ resource "aws_network_interface" "<%= module_name_of(network_interface) %>" {
3
+ subnet_id = "<%= network_interface.subnet_id %>"
4
+ private_ips = <%= private_ips_of(network_interface).inspect %>
5
+ security_groups = <%= security_groups_of(network_interface).inspect %>
6
+ source_dest_check = <%= network_interface.source_dest_check %>
7
+ <% if network_interface.attachment && network_interface.attachment.instance_id -%>
8
+ attachment {
9
+ instance = "<%= network_interface.attachment.instance_id %>"
10
+ device_index = <%= network_interface.attachment.device_index %>
11
+ }
12
+ <% end -%>
13
+ <% if network_interface.tag_set.length > 0 -%>
14
+ tags {
15
+ <% network_interface.tag_set.each do |tag| -%>
16
+ "<%= tag.key %>" = "<%= tag.value %>"
17
+ <% end -%>
18
+ }
19
+ <% end -%>
20
+ }
21
+
22
+ <% end -%>
@@ -1,3 +1,3 @@
1
1
  module Terraforming
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/terraforming.rb CHANGED
@@ -15,6 +15,7 @@ require "terraforming/resource/db_parameter_group"
15
15
  require "terraforming/resource/db_security_group"
16
16
  require "terraforming/resource/db_subnet_group"
17
17
  require "terraforming/resource/ec2"
18
+ require "terraforming/resource/eip"
18
19
  require "terraforming/resource/elasti_cache_cluster"
19
20
  require "terraforming/resource/elasti_cache_subnet_group"
20
21
  require "terraforming/resource/elb"
@@ -28,6 +29,7 @@ require "terraforming/resource/iam_role_policy"
28
29
  require "terraforming/resource/iam_user"
29
30
  require "terraforming/resource/iam_user_policy"
30
31
  require "terraforming/resource/network_acl"
32
+ require "terraforming/resource/network_interface"
31
33
  require "terraforming/resource/rds"
32
34
  require "terraforming/resource/route53_record"
33
35
  require "terraforming/resource/route53_zone"
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.2.0
4
+ version: 0.3.0
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-08-22 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -189,6 +189,7 @@ files:
189
189
  - lib/terraforming/resource/db_security_group.rb
190
190
  - lib/terraforming/resource/db_subnet_group.rb
191
191
  - lib/terraforming/resource/ec2.rb
192
+ - lib/terraforming/resource/eip.rb
192
193
  - lib/terraforming/resource/elasti_cache_cluster.rb
193
194
  - lib/terraforming/resource/elasti_cache_subnet_group.rb
194
195
  - lib/terraforming/resource/elb.rb
@@ -202,6 +203,7 @@ files:
202
203
  - lib/terraforming/resource/iam_user.rb
203
204
  - lib/terraforming/resource/iam_user_policy.rb
204
205
  - lib/terraforming/resource/network_acl.rb
206
+ - lib/terraforming/resource/network_interface.rb
205
207
  - lib/terraforming/resource/rds.rb
206
208
  - lib/terraforming/resource/route53_record.rb
207
209
  - lib/terraforming/resource/route53_zone.rb
@@ -213,6 +215,7 @@ files:
213
215
  - lib/terraforming/template/tf/db_security_group.erb
214
216
  - lib/terraforming/template/tf/db_subnet_group.erb
215
217
  - lib/terraforming/template/tf/ec2.erb
218
+ - lib/terraforming/template/tf/eip.erb
216
219
  - lib/terraforming/template/tf/elasti_cache_cluster.erb
217
220
  - lib/terraforming/template/tf/elasti_cache_subnet_group.erb
218
221
  - lib/terraforming/template/tf/elb.erb
@@ -226,6 +229,7 @@ files:
226
229
  - lib/terraforming/template/tf/iam_user.erb
227
230
  - lib/terraforming/template/tf/iam_user_policy.erb
228
231
  - lib/terraforming/template/tf/network_acl.erb
232
+ - lib/terraforming/template/tf/network_interface.erb
229
233
  - lib/terraforming/template/tf/rds.erb
230
234
  - lib/terraforming/template/tf/route53_record.erb
231
235
  - lib/terraforming/template/tf/route53_zone.erb
@@ -258,9 +262,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
262
  version: '0'
259
263
  requirements: []
260
264
  rubyforge_project:
261
- rubygems_version: 2.4.7
265
+ rubygems_version: 2.4.5.1
262
266
  signing_key:
263
267
  specification_version: 4
264
268
  summary: Export existing AWS resources to Terraform style (tf, tfstate)
265
269
  test_files: []
266
- has_rdoc: