terraforming 0.0.1 → 0.0.2

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: cd7e2563a8bdca0e28d2ce67043ef45de9371c68
4
- data.tar.gz: ed9d20b570d77f232511563e529a9b7fe2a94837
3
+ metadata.gz: 98a4283e9ec68191bb76845061e9d990c8265684
4
+ data.tar.gz: 849118d11012f17491c2b88460b57b2f40fa6a8a
5
5
  SHA512:
6
- metadata.gz: a0cb8f5bfb4b9417a0cac3b1798f3098d4d804f1e9310fae5a75b9b3513cf138509075f8218b4ae089a8be43cd2deca43860c9e53388560e2bf4a3c3c948a0c5
7
- data.tar.gz: 766a117c13ca47faa4ceeb5fb6697135374978cfaad7df3463d7c2682e10bb6cb4f98b6924d725bc04ab20385e50f8ded7b94bb52824bebb2d8bcc74798d20cf
6
+ metadata.gz: 8ab684ad1cc0796cc085d97de0c8319261742edf6bc2d66f9e9e99d4e64d47834214499c98cadeb09e583481cceb57077da23709844fb9ed25c73427b84ed8f0
7
+ data.tar.gz: 6ae32eb13bfe952a9b3853940f4bc01e9b1016474ec7e134d1d5395059c84c6ebccdf5aeef16ce800bc5729e0195408860d768da9ecc55c3f42c166ca3cd9d26
data/README.md CHANGED
@@ -3,8 +3,9 @@
3
3
  [![Build Status](https://travis-ci.org/dtan4/terraforming.svg?branch=master)](https://travis-ci.org/dtan4/terraforming)
4
4
  [![Code Climate](https://codeclimate.com/github/dtan4/terraforming/badges/gpa.svg)](https://codeclimate.com/github/dtan4/terraforming)
5
5
  [![Test Coverage](https://codeclimate.com/github/dtan4/terraforming/badges/coverage.svg)](https://codeclimate.com/github/dtan4/terraforming)
6
+ [![Gem Version](https://badge.fury.io/rb/terraforming.svg)](http://badge.fury.io/rb/terraforming)
6
7
 
7
- Export existing AWS resources to [Terraform](https://terraform.io/) style (tf, tfstate)
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"
@@ -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::Resource
2
- class DBParameterGroup
3
- include Terraforming::Util
1
+ module Terraforming
2
+ module Resource
3
+ class DBParameterGroup
4
+ include Terraforming::Util
4
5
 
5
- def self.tf(client = Aws::RDS::Client.new)
6
- self.new(client).tf
7
- end
6
+ def self.tf(client = Aws::RDS::Client.new)
7
+ self.new(client).tf
8
+ end
8
9
 
9
- def self.tfstate(client = Aws::RDS::Client.new)
10
- self.new(client).tfstate
11
- end
10
+ def self.tfstate(client = Aws::RDS::Client.new)
11
+ self.new(client).tfstate
12
+ end
12
13
 
13
- def initialize(client)
14
- @client = client
15
- end
14
+ def initialize(client)
15
+ @client = client
16
+ end
16
17
 
17
- def tf
18
- apply_template(@client, "tf/db_parameter_group")
19
- end
18
+ def tf
19
+ apply_template(@client, "tf/db_parameter_group")
20
+ end
20
21
 
21
- def tfstate
22
- resources = db_parameter_groups.inject({}) do |result, parameter_group|
23
- attributes = {
24
- "description" => parameter_group.description,
25
- "family" => parameter_group.db_parameter_group_family,
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
- "attributes" => attributes
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
- result
39
- end
39
+ result
40
+ end
40
41
 
41
- generate_tfstate(resources)
42
- end
42
+ generate_tfstate(resources)
43
+ end
43
44
 
44
- private
45
+ private
45
46
 
46
- def db_parameter_groups
47
- @client.describe_db_parameter_groups.db_parameter_groups
48
- end
47
+ def db_parameter_groups
48
+ @client.describe_db_parameter_groups.db_parameter_groups
49
+ end
49
50
 
50
- def db_parameters_in(parameter_group)
51
- @client.describe_db_parameters(db_parameter_group_name: parameter_group.db_parameter_group_name).parameters
52
- end
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
- def module_name_of(parameter_group)
55
- normalize_module_name(parameter_group.db_parameter_group_name)
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::Resource
2
- class DBSecurityGroup
3
- include Terraforming::Util
1
+ module Terraforming
2
+ module Resource
3
+ class DBSecurityGroup
4
+ include Terraforming::Util
4
5
 
5
- def self.tf(client = Aws::RDS::Client.new)
6
- self.new(client).tf
7
- end
6
+ def self.tf(client = Aws::RDS::Client.new)
7
+ self.new(client).tf
8
+ end
8
9
 
9
- def self.tfstate(client = Aws::RDS::Client.new)
10
- self.new(client).tfstate
11
- end
10
+ def self.tfstate(client = Aws::RDS::Client.new)
11
+ self.new(client).tfstate
12
+ end
12
13
 
13
- def initialize(client)
14
- @client = client
15
- end
14
+ def initialize(client)
15
+ @client = client
16
+ end
16
17
 
17
- def tf
18
- apply_template(@client, "tf/db_security_group")
19
- end
18
+ def tf
19
+ apply_template(@client, "tf/db_security_group")
20
+ end
20
21
 
21
- def tfstate
22
- resources = db_security_groups.inject({}) do |result, security_group|
23
- attributes = {
24
- "db_subnet_group_name" => security_group.db_security_group_name,
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
- "attributes" => attributes
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
- result
38
- end
38
+ result
39
+ end
39
40
 
40
- generate_tfstate(resources)
41
- end
41
+ generate_tfstate(resources)
42
+ end
42
43
 
43
- private
44
+ private
44
45
 
45
- def db_security_groups
46
- @client.describe_db_security_groups.db_security_groups
47
- end
46
+ def db_security_groups
47
+ @client.describe_db_security_groups.db_security_groups
48
+ end
48
49
 
49
- def module_name_of(security_group)
50
- normalize_module_name(security_group.db_security_group_name)
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::Resource
2
- class DBSubnetGroup
3
- include Terraforming::Util
1
+ module Terraforming
2
+ module Resource
3
+ class DBSubnetGroup
4
+ include Terraforming::Util
4
5
 
5
- def self.tf(client = Aws::RDS::Client.new)
6
- self.new(client).tf
7
- end
6
+ def self.tf(client = Aws::RDS::Client.new)
7
+ self.new(client).tf
8
+ end
8
9
 
9
- def self.tfstate(client = Aws::RDS::Client.new)
10
- self.new(client).tfstate
11
- end
10
+ def self.tfstate(client = Aws::RDS::Client.new)
11
+ self.new(client).tfstate
12
+ end
12
13
 
13
- def initialize(client)
14
- @client = client
15
- end
14
+ def initialize(client)
15
+ @client = client
16
+ end
16
17
 
17
- def tf
18
- apply_template(@client, "tf/db_subnet_group")
19
- end
18
+ def tf
19
+ apply_template(@client, "tf/db_subnet_group")
20
+ end
20
21
 
21
- def tfstate
22
- resources = db_subnet_groups.inject({}) do |result, subnet_group|
23
- attributes = {
24
- "description" => subnet_group.db_subnet_group_description,
25
- "name" => subnet_group.db_subnet_group_name,
26
- "subnet_ids.#" => subnet_group.subnets.length.to_s
27
- }
28
- result["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
29
- "type" => "aws_db_subnet_group",
30
- "primary" => {
31
- "id" => subnet_group.db_subnet_group_name,
32
- "attributes" => attributes
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
- result
37
- end
37
+ result
38
+ end
38
39
 
39
- generate_tfstate(resources)
40
- end
40
+ generate_tfstate(resources)
41
+ end
41
42
 
42
- private
43
+ private
43
44
 
44
- def db_subnet_groups
45
- @client.describe_db_subnet_groups.db_subnet_groups
46
- end
45
+ def db_subnet_groups
46
+ @client.describe_db_subnet_groups.db_subnet_groups
47
+ end
47
48
 
48
- def module_name_of(subnet_group)
49
- normalize_module_name(subnet_group.db_subnet_group_name)
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::Resource
2
- class EC2
3
- include Terraforming::Util
1
+ module Terraforming
2
+ module Resource
3
+ class EC2
4
+ include Terraforming::Util
4
5
 
5
- def self.tf(client = Aws::EC2::Client.new)
6
- self.new(client).tf
7
- end
6
+ def self.tf(client = Aws::EC2::Client.new)
7
+ self.new(client).tf
8
+ end
8
9
 
9
- def self.tfstate(client = Aws::EC2::Client.new)
10
- self.new(client).tfstate
11
- end
10
+ def self.tfstate(client = Aws::EC2::Client.new)
11
+ self.new(client).tfstate
12
+ end
12
13
 
13
- def initialize(client)
14
- @client = client
15
- end
14
+ def initialize(client)
15
+ @client = client
16
+ end
16
17
 
17
- def tf
18
- apply_template(@client, "tf/ec2")
19
- end
18
+ def tf
19
+ apply_template(@client, "tf/ec2")
20
+ end
20
21
 
21
- def tfstate
22
- resources = instances.inject({}) do |result, instance|
23
- attributes = {
24
- "ami"=> instance.image_id,
25
- "associate_public_ip_address"=> "true",
26
- "availability_zone"=> instance.placement.availability_zone,
27
- "ebs_block_device.#"=> instance.block_device_mappings.length.to_s,
28
- "ebs_optimized"=> instance.ebs_optimized.to_s,
29
- "ephemeral_block_device.#"=> "0",
30
- "id"=> instance.instance_id,
31
- "instance_type"=> instance.instance_type,
32
- "private_dns"=> instance.private_dns_name,
33
- "private_ip"=> instance.private_ip_address,
34
- "public_dns"=> instance.public_dns_name,
35
- "public_ip"=> instance.public_ip_address,
36
- "root_block_device.#"=> instance.root_device_name ? "1" : "0",
37
- "security_groups.#"=> instance.security_groups.length.to_s,
38
- "source_dest_check"=> instance.source_dest_check.to_s,
39
- "subnet_id"=> instance.subnet_id,
40
- "tenancy"=> instance.placement.tenancy
41
- }
42
- result["aws_instance.#{module_name_of(instance)}"] = {
43
- "type" => "aws_instance",
44
- "primary" => {
45
- "id" => instance.instance_id,
46
- "attributes" => attributes,
47
- "meta" => {
48
- "schema_version" => "1"
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
- result
54
- end
54
+ result
55
+ end
55
56
 
56
- generate_tfstate(resources)
57
- end
57
+ generate_tfstate(resources)
58
+ end
58
59
 
59
- private
60
+ private
60
61
 
61
- def instances
62
- @client.describe_instances.reservations.map(&:instances).flatten
63
- end
62
+ def instances
63
+ @client.describe_instances.reservations.map(&:instances).flatten
64
+ end
64
65
 
65
- def module_name_of(instance)
66
- normalize_module_name(name_from_tag(instance, instance.instance_id))
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