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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98a4283e9ec68191bb76845061e9d990c8265684
|
4
|
+
data.tar.gz: 849118d11012f17491c2b88460b57b2f40fa6a8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ab684ad1cc0796cc085d97de0c8319261742edf6bc2d66f9e9e99d4e64d47834214499c98cadeb09e583481cceb57077da23709844fb9ed25c73427b84ed8f0
|
7
|
+
data.tar.gz: 6ae32eb13bfe952a9b3853940f4bc01e9b1016474ec7e134d1d5395059c84c6ebccdf5aeef16ce800bc5729e0195408860d768da9ecc55c3f42c166ca3cd9d26
|
data/README.md
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
[](https://travis-ci.org/dtan4/terraforming)
|
4
4
|
[](https://codeclimate.com/github/dtan4/terraforming)
|
5
5
|
[](https://codeclimate.com/github/dtan4/terraforming)
|
6
|
+
[](http://badge.fury.io/rb/terraforming)
|
6
7
|
|
7
|
-
|
8
|
+
Import existing AWS resources into [Terraform](https://terraform.io/) style (tf, tfstate)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -43,9 +44,11 @@ Commands:
|
|
43
44
|
terraforming ec2 # EC2
|
44
45
|
terraforming elb # ELB
|
45
46
|
terraforming help [COMMAND] # Describe available commands or one specific command
|
47
|
+
terraforming nacl # Network ACL
|
46
48
|
terraforming rds # RDS
|
47
49
|
terraforming s3 # S3
|
48
50
|
terraforming sg # SecurityGroup
|
51
|
+
terraforming sn # Subnet
|
49
52
|
terraforming vpc # VPC
|
50
53
|
```
|
51
54
|
|
data/lib/terraforming.rb
CHANGED
@@ -15,6 +15,7 @@ require "terraforming/resource/db_security_group"
|
|
15
15
|
require "terraforming/resource/db_subnet_group"
|
16
16
|
require "terraforming/resource/ec2"
|
17
17
|
require "terraforming/resource/elb"
|
18
|
+
require "terraforming/resource/network_acl"
|
18
19
|
require "terraforming/resource/rds"
|
19
20
|
require "terraforming/resource/s3"
|
20
21
|
require "terraforming/resource/security_group"
|
data/lib/terraforming/cli.rb
CHANGED
@@ -30,6 +30,12 @@ module Terraforming
|
|
30
30
|
execute(Terraforming::Resource::ELB, options)
|
31
31
|
end
|
32
32
|
|
33
|
+
desc "nacl", "Network ACL"
|
34
|
+
option :tfstate, type: :boolean
|
35
|
+
def nacl
|
36
|
+
execute(Terraforming::Resource::NetworkACL, options)
|
37
|
+
end
|
38
|
+
|
33
39
|
desc "rds", "RDS"
|
34
40
|
option :tfstate, type: :boolean
|
35
41
|
def rds
|
@@ -1,58 +1,60 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class DBParameterGroup
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::RDS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::RDS::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/db_parameter_group")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"id" => parameter_group.db_parameter_group_name,
|
27
|
-
"name" => parameter_group.db_parameter_group_name,
|
28
|
-
"parameter.#" => db_parameters_in(parameter_group).length.to_s
|
29
|
-
}
|
30
|
-
result["aws_db_parameter_group.#{module_name_of(parameter_group)}"] = {
|
31
|
-
"type" => "aws_db_parameter_group",
|
32
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = db_parameter_groups.inject({}) do |result, parameter_group|
|
24
|
+
attributes = {
|
25
|
+
"description" => parameter_group.description,
|
26
|
+
"family" => parameter_group.db_parameter_group_family,
|
33
27
|
"id" => parameter_group.db_parameter_group_name,
|
34
|
-
"
|
28
|
+
"name" => parameter_group.db_parameter_group_name,
|
29
|
+
"parameter.#" => db_parameters_in(parameter_group).length.to_s
|
30
|
+
}
|
31
|
+
result["aws_db_parameter_group.#{module_name_of(parameter_group)}"] = {
|
32
|
+
"type" => "aws_db_parameter_group",
|
33
|
+
"primary" => {
|
34
|
+
"id" => parameter_group.db_parameter_group_name,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
35
37
|
}
|
36
|
-
}
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
result
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
generate_tfstate(resources)
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
+
private
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def db_parameter_groups
|
48
|
+
@client.describe_db_parameter_groups.db_parameter_groups
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def db_parameters_in(parameter_group)
|
52
|
+
@client.describe_db_parameters(db_parameter_group_name: parameter_group.db_parameter_group_name).parameters
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
def module_name_of(parameter_group)
|
56
|
+
normalize_module_name(parameter_group.db_parameter_group_name)
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -1,53 +1,55 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class DBSecurityGroup
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::RDS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::RDS::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/db_security_group")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"id" => security_group.db_security_group_name,
|
26
|
-
"ingress.#" => (security_group.ec2_security_groups.length + security_group.ip_ranges.length).to_s,
|
27
|
-
"name" => security_group.db_security_group_name,
|
28
|
-
}
|
29
|
-
result["aws_db_security_group.#{module_name_of(security_group)}"] = {
|
30
|
-
"type" => "aws_db_security_group",
|
31
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = db_security_groups.inject({}) do |result, security_group|
|
24
|
+
attributes = {
|
25
|
+
"db_subnet_group_name" => security_group.db_security_group_name,
|
32
26
|
"id" => security_group.db_security_group_name,
|
33
|
-
"
|
27
|
+
"ingress.#" => (security_group.ec2_security_groups.length + security_group.ip_ranges.length).to_s,
|
28
|
+
"name" => security_group.db_security_group_name,
|
29
|
+
}
|
30
|
+
result["aws_db_security_group.#{module_name_of(security_group)}"] = {
|
31
|
+
"type" => "aws_db_security_group",
|
32
|
+
"primary" => {
|
33
|
+
"id" => security_group.db_security_group_name,
|
34
|
+
"attributes" => attributes
|
35
|
+
}
|
34
36
|
}
|
35
|
-
}
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
result
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
generate_tfstate(resources)
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
+
private
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def db_security_groups
|
47
|
+
@client.describe_db_security_groups.db_security_groups
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
def module_name_of(security_group)
|
51
|
+
normalize_module_name(security_group.db_security_group_name)
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -1,52 +1,54 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class DBSubnetGroup
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::RDS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::RDS::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/db_subnet_group")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
def tfstate
|
23
|
+
resources = db_subnet_groups.inject({}) do |result, subnet_group|
|
24
|
+
attributes = {
|
25
|
+
"description" => subnet_group.db_subnet_group_description,
|
26
|
+
"name" => subnet_group.db_subnet_group_name,
|
27
|
+
"subnet_ids.#" => subnet_group.subnets.length.to_s
|
28
|
+
}
|
29
|
+
result["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
|
30
|
+
"type" => "aws_db_subnet_group",
|
31
|
+
"primary" => {
|
32
|
+
"id" => subnet_group.db_subnet_group_name,
|
33
|
+
"attributes" => attributes
|
34
|
+
}
|
33
35
|
}
|
34
|
-
}
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
result
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
generate_tfstate(resources)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
+
private
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def db_subnet_groups
|
46
|
+
@client.describe_db_subnet_groups.db_subnet_groups
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
def module_name_of(subnet_group)
|
50
|
+
normalize_module_name(subnet_group.db_subnet_group_name)
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -1,69 +1,71 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class EC2
|
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/ec2")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
22
|
+
def tfstate
|
23
|
+
resources = instances.inject({}) do |result, instance|
|
24
|
+
attributes = {
|
25
|
+
"ami"=> instance.image_id,
|
26
|
+
"associate_public_ip_address"=> "true",
|
27
|
+
"availability_zone"=> instance.placement.availability_zone,
|
28
|
+
"ebs_block_device.#"=> instance.block_device_mappings.length.to_s,
|
29
|
+
"ebs_optimized"=> instance.ebs_optimized.to_s,
|
30
|
+
"ephemeral_block_device.#"=> "0",
|
31
|
+
"id"=> instance.instance_id,
|
32
|
+
"instance_type"=> instance.instance_type,
|
33
|
+
"private_dns"=> instance.private_dns_name,
|
34
|
+
"private_ip"=> instance.private_ip_address,
|
35
|
+
"public_dns"=> instance.public_dns_name,
|
36
|
+
"public_ip"=> instance.public_ip_address,
|
37
|
+
"root_block_device.#"=> instance.root_device_name ? "1" : "0",
|
38
|
+
"security_groups.#"=> instance.security_groups.length.to_s,
|
39
|
+
"source_dest_check"=> instance.source_dest_check.to_s,
|
40
|
+
"subnet_id"=> instance.subnet_id,
|
41
|
+
"tenancy"=> instance.placement.tenancy
|
42
|
+
}
|
43
|
+
result["aws_instance.#{module_name_of(instance)}"] = {
|
44
|
+
"type" => "aws_instance",
|
45
|
+
"primary" => {
|
46
|
+
"id" => instance.instance_id,
|
47
|
+
"attributes" => attributes,
|
48
|
+
"meta" => {
|
49
|
+
"schema_version" => "1"
|
50
|
+
}
|
49
51
|
}
|
50
52
|
}
|
51
|
-
}
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
result
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
generate_tfstate(resources)
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
+
private
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
def instances
|
63
|
+
@client.describe_instances.reservations.map(&:instances).flatten
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
def module_name_of(instance)
|
67
|
+
normalize_module_name(name_from_tag(instance, instance.instance_id))
|
68
|
+
end
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|