terraforming 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +4 -1
- data/lib/terraforming.rb +1 -0
- data/lib/terraforming/cli.rb +6 -0
- data/lib/terraforming/resource/db_parameter_group.rb +44 -42
- data/lib/terraforming/resource/db_security_group.rb +40 -38
- data/lib/terraforming/resource/db_subnet_group.rb +40 -38
- data/lib/terraforming/resource/ec2.rb +56 -54
- data/lib/terraforming/resource/elb.rb +44 -42
- data/lib/terraforming/resource/network_acl.rb +72 -0
- data/lib/terraforming/resource/rds.rb +61 -59
- data/lib/terraforming/resource/s3.rb +38 -36
- data/lib/terraforming/resource/security_group.rb +43 -41
- data/lib/terraforming/resource/subnet.rb +42 -40
- data/lib/terraforming/resource/vpc.rb +51 -49
- data/lib/terraforming/template/tf/network_acl.erb +34 -0
- data/lib/terraforming/util.rb +28 -26
- data/lib/terraforming/version.rb +1 -1
- data/terraforming.gemspec +2 -2
- metadata +6 -4
@@ -1,55 +1,57 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class Subnet
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::EC2::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/subnet")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"id" => subnet.subnet_id,
|
27
|
-
"map_public_ip_on_launch" => subnet.map_public_ip_on_launch.to_s,
|
28
|
-
"tags.#" => subnet.tags.length.to_s,
|
29
|
-
"vpc_id" => subnet.vpc_id,
|
30
|
-
}
|
31
|
-
result["aws_subnet.#{module_name_of(subnet)}"] = {
|
32
|
-
"type" => "aws_subnet",
|
33
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = subnets.inject({}) do |result, subnet|
|
24
|
+
attributes = {
|
25
|
+
"availability_zone" => subnet.availability_zone,
|
26
|
+
"cidr_block" => subnet.cidr_block,
|
34
27
|
"id" => subnet.subnet_id,
|
35
|
-
"
|
28
|
+
"map_public_ip_on_launch" => subnet.map_public_ip_on_launch.to_s,
|
29
|
+
"tags.#" => subnet.tags.length.to_s,
|
30
|
+
"vpc_id" => subnet.vpc_id,
|
31
|
+
}
|
32
|
+
result["aws_subnet.#{module_name_of(subnet)}"] = {
|
33
|
+
"type" => "aws_subnet",
|
34
|
+
"primary" => {
|
35
|
+
"id" => subnet.subnet_id,
|
36
|
+
"attributes" => attributes
|
37
|
+
}
|
36
38
|
}
|
37
|
-
}
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
result
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
generate_tfstate(resources)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
+
private
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def subnets
|
49
|
+
@client.describe_subnets.subnets
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
def module_name_of(subnet)
|
53
|
+
normalize_module_name(name_from_tag(subnet, subnet.subnet_id))
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -1,67 +1,69 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class VPC
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::EC2::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/vpc")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
"id" => vpc.vpc_id,
|
28
|
-
"instance_tenancy" => vpc.instance_tenancy,
|
29
|
-
"tags.#" => vpc.tags.length.to_s,
|
30
|
-
}
|
31
|
-
result["aws_vpc.#{module_name_of(vpc)}"] = {
|
32
|
-
"type" => "aws_vpc",
|
33
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = vpcs.inject({}) do |result, vpc|
|
24
|
+
attributes = {
|
25
|
+
"cidr_block" => vpc.cidr_block,
|
26
|
+
"enable_dns_hostnames" => enable_dns_hostnames?(vpc).to_s,
|
27
|
+
"enable_dns_support" => enable_dns_support?(vpc).to_s,
|
34
28
|
"id" => vpc.vpc_id,
|
35
|
-
"
|
29
|
+
"instance_tenancy" => vpc.instance_tenancy,
|
30
|
+
"tags.#" => vpc.tags.length.to_s,
|
31
|
+
}
|
32
|
+
result["aws_vpc.#{module_name_of(vpc)}"] = {
|
33
|
+
"type" => "aws_vpc",
|
34
|
+
"primary" => {
|
35
|
+
"id" => vpc.vpc_id,
|
36
|
+
"attributes" => attributes
|
37
|
+
}
|
36
38
|
}
|
37
|
-
}
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
result
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
generate_tfstate(resources)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
+
private
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def enable_dns_hostnames?(vpc)
|
49
|
+
vpc_attribute(vpc, :enableDnsHostnames).enable_dns_hostnames.value
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def enable_dns_support?(vpc)
|
53
|
+
vpc_attribute(vpc, :enableDnsSupport).enable_dns_support.value
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
def module_name_of(vpc)
|
57
|
+
normalize_module_name(name_from_tag(vpc, vpc.vpc_id))
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def vpcs
|
61
|
+
@client.describe_vpcs.vpcs
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
def vpc_attribute(vpc, attribute)
|
65
|
+
@client.describe_vpc_attribute(vpc_id: vpc.vpc_id, attribute: attribute)
|
66
|
+
end
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<% network_acls.each do |network_acl| -%>
|
2
|
+
resource "aws_network_acl" "<%= module_name_of(network_acl) %>" {
|
3
|
+
vpc_id = "<%= network_acl.vpc_id %>"
|
4
|
+
|
5
|
+
<% ingresses_of(network_acl).each do |ingress| -%>
|
6
|
+
ingress {
|
7
|
+
from_port = <%= from_port_of(ingress) %>
|
8
|
+
to_port = <%= to_port_of(ingress) %>
|
9
|
+
rule_no = <%= ingress.rule_number %>
|
10
|
+
action = "<%= ingress.rule_action %>"
|
11
|
+
protocol = "<%= ingress.protocol %>"
|
12
|
+
cidr_block = "<%= ingress.cidr_block %>"
|
13
|
+
}
|
14
|
+
|
15
|
+
<% end -%>
|
16
|
+
<% egresses_of(network_acl).each do |egress| -%>
|
17
|
+
egress {
|
18
|
+
from_port = <%= from_port_of(egress) %>
|
19
|
+
to_port = <%= to_port_of(egress) %>
|
20
|
+
rule_no = <%= egress.rule_number %>
|
21
|
+
action = "<%= egress.rule_action %>"
|
22
|
+
protocol = "<%= egress.protocol %>"
|
23
|
+
cidr_block = "<%= egress.cidr_block %>"
|
24
|
+
}
|
25
|
+
|
26
|
+
<% end -%>
|
27
|
+
tags {
|
28
|
+
<% network_acl.tags.each do |tag| -%>
|
29
|
+
<%= tag.key %> = "<%= tag.value %>"
|
30
|
+
<% end -%>
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
<% end -%>
|
data/lib/terraforming/util.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Util
|
3
|
+
def apply_template(client, erb)
|
4
|
+
ERB.new(open(template_path(erb)).read, nil, "-").result(binding)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def name_from_tag(resource, default_name)
|
8
|
+
name_tag = resource.tags.find { |tag| tag.key == "Name" }
|
9
|
+
name_tag ? name_tag.value : default_name
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def normalize_module_name(name)
|
13
|
+
name.gsub(/[^a-zA-Z0-9_-]/, "-")
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def template_path(template_name)
|
17
|
+
File.join(File.expand_path(File.dirname(__FILE__)), "template", template_name) << ".erb"
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
def generate_tfstate(resources)
|
21
|
+
tfstate = {
|
22
|
+
"version" => 1,
|
23
|
+
"serial" => 1,
|
24
|
+
"modules" => {
|
25
|
+
"path" => [
|
26
|
+
"root"
|
27
|
+
],
|
28
|
+
"outputs" => {},
|
29
|
+
"resources" => resources
|
30
|
+
}
|
29
31
|
}
|
30
|
-
}
|
31
32
|
|
32
|
-
|
33
|
+
JSON.pretty_generate(tfstate)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
data/lib/terraforming/version.rb
CHANGED
data/terraforming.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Daisuke Fujita"]
|
10
10
|
spec.email = ["dtanshi45@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{Import existing AWS resources into Terraform style (tf, tfstate)}
|
13
|
+
spec.description = %q{Import existing AWS resources into Terraform style (tf, tfstate)}
|
14
14
|
spec.homepage = "https://github.com/dtan4/terraforming"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
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.0.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -170,7 +170,7 @@ dependencies:
|
|
170
170
|
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
|
-
description:
|
173
|
+
description: Import existing AWS resources into Terraform style (tf, tfstate)
|
174
174
|
email:
|
175
175
|
- dtanshi45@gmail.com
|
176
176
|
executables:
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/terraforming/resource/db_subnet_group.rb
|
196
196
|
- lib/terraforming/resource/ec2.rb
|
197
197
|
- lib/terraforming/resource/elb.rb
|
198
|
+
- lib/terraforming/resource/network_acl.rb
|
198
199
|
- lib/terraforming/resource/rds.rb
|
199
200
|
- lib/terraforming/resource/s3.rb
|
200
201
|
- lib/terraforming/resource/security_group.rb
|
@@ -205,6 +206,7 @@ files:
|
|
205
206
|
- lib/terraforming/template/tf/db_subnet_group.erb
|
206
207
|
- lib/terraforming/template/tf/ec2.erb
|
207
208
|
- lib/terraforming/template/tf/elb.erb
|
209
|
+
- lib/terraforming/template/tf/network_acl.erb
|
208
210
|
- lib/terraforming/template/tf/rds.erb
|
209
211
|
- lib/terraforming/template/tf/s3.erb
|
210
212
|
- lib/terraforming/template/tf/security_group.erb
|
@@ -238,5 +240,5 @@ rubyforge_project:
|
|
238
240
|
rubygems_version: 2.4.5
|
239
241
|
signing_key:
|
240
242
|
specification_version: 4
|
241
|
-
summary:
|
243
|
+
summary: Import existing AWS resources into Terraform style (tf, tfstate)
|
242
244
|
test_files: []
|