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 +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,56 +1,58 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class ELB
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::ElasticLoadBalancing::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::ElasticLoadBalancing::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/elb")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
"id" => load_balancer.load_balancer_name,
|
28
|
-
"instances.#" => load_balancer.instances.length.to_s,
|
29
|
-
"listener.#" => load_balancer.listener_descriptions.length.to_s,
|
30
|
-
"name" => load_balancer.load_balancer_name,
|
31
|
-
"security_groups.#" => load_balancer.security_groups.length.to_s,
|
32
|
-
"subnets.#" => load_balancer.subnets.length.to_s,
|
33
|
-
}
|
34
|
-
result["aws_elb.#{module_name_of(load_balancer)}"] = {
|
35
|
-
"type" => "aws_elb",
|
36
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = load_balancers.inject({}) do |result, load_balancer|
|
24
|
+
attributes = {
|
25
|
+
"availability_zones.#" => load_balancer.availability_zones.length.to_s,
|
26
|
+
"dns_name" => load_balancer.dns_name,
|
27
|
+
"health_check.#" => "1",
|
37
28
|
"id" => load_balancer.load_balancer_name,
|
38
|
-
"
|
29
|
+
"instances.#" => load_balancer.instances.length.to_s,
|
30
|
+
"listener.#" => load_balancer.listener_descriptions.length.to_s,
|
31
|
+
"name" => load_balancer.load_balancer_name,
|
32
|
+
"security_groups.#" => load_balancer.security_groups.length.to_s,
|
33
|
+
"subnets.#" => load_balancer.subnets.length.to_s,
|
34
|
+
}
|
35
|
+
result["aws_elb.#{module_name_of(load_balancer)}"] = {
|
36
|
+
"type" => "aws_elb",
|
37
|
+
"primary" => {
|
38
|
+
"id" => load_balancer.load_balancer_name,
|
39
|
+
"attributes" => attributes
|
40
|
+
}
|
39
41
|
}
|
40
|
-
}
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
result
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
generate_tfstate(resources)
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def load_balancers
|
50
|
+
@client.describe_load_balancers.load_balancer_descriptions
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
def module_name_of(load_balancer)
|
54
|
+
normalize_module_name(load_balancer.load_balancer_name)
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class NetworkACL
|
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_acl")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
resources = network_acls.inject({}) do |result, network_acl|
|
24
|
+
attributes = {
|
25
|
+
"egress.#" => egresses_of(network_acl).length.to_s,
|
26
|
+
"id" => network_acl.network_acl_id,
|
27
|
+
"ingress.#" => ingresses_of(network_acl).length.to_s,
|
28
|
+
"tags.#" => network_acl.tags.length.to_s,
|
29
|
+
"vpc_id" => network_acl.vpc_id,
|
30
|
+
}
|
31
|
+
result["aws_network_acl.#{module_name_of(network_acl)}"] = {
|
32
|
+
"type" => "aws_network_acl",
|
33
|
+
"primary" => {
|
34
|
+
"id" => network_acl.network_acl_id,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
generate_tfstate(resources)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def egresses_of(network_acl)
|
48
|
+
network_acl.entries.select { |entry| entry.egress }
|
49
|
+
end
|
50
|
+
|
51
|
+
def from_port_of(entry)
|
52
|
+
entry.port_range ? entry.port_range.from : 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def ingresses_of(network_acl)
|
56
|
+
network_acl.entries.select { |entry| !entry.egress }
|
57
|
+
end
|
58
|
+
|
59
|
+
def module_name_of(network_acl)
|
60
|
+
normalize_module_name(name_from_tag(network_acl, network_acl.network_acl_id))
|
61
|
+
end
|
62
|
+
|
63
|
+
def network_acls
|
64
|
+
@client.describe_network_acls.network_acls
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_port_of(entry)
|
68
|
+
entry.port_range ? entry.port_range.to : 65535
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,74 +1,76 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class RDS
|
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/rds")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
"id" => instance.db_instance_identifier,
|
35
|
-
"identifier" => instance.db_instance_identifier,
|
36
|
-
"instance_class" => instance.db_instance_class,
|
37
|
-
"maintenance_window" => instance.preferred_maintenance_window,
|
38
|
-
"multi_az" => instance.multi_az.to_s,
|
39
|
-
"name" => instance.db_name,
|
40
|
-
"parameter_group_name" => instance.db_parameter_groups[0].db_parameter_group_name,
|
41
|
-
"password" => "xxxxxxxx",
|
42
|
-
"port" => instance.endpoint.port.to_s,
|
43
|
-
"publicly_accessible" => instance.publicly_accessible.to_s,
|
44
|
-
"security_group_names.#" => instance.db_security_groups.length.to_s,
|
45
|
-
"status" => instance.db_instance_status,
|
46
|
-
"storage_type" => instance.storage_type,
|
47
|
-
"username" => instance.master_username,
|
48
|
-
"vpc_security_group_ids.#" => instance.vpc_security_groups.length.to_s,
|
49
|
-
}
|
50
|
-
result["aws_db_instance.#{module_name_of(instance)}"] = {
|
51
|
-
"type" => "aws_db_instance",
|
52
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = db_instances.inject({}) do |result, instance|
|
24
|
+
attributes = {
|
25
|
+
"address" => instance.endpoint.address,
|
26
|
+
"allocated_storage" => instance.allocated_storage.to_s,
|
27
|
+
"availability_zone" => instance.availability_zone,
|
28
|
+
"backup_retention_period" => instance.backup_retention_period.to_s,
|
29
|
+
"backup_window" => instance.preferred_backup_window,
|
30
|
+
"db_subnet_group_name" => instance.db_subnet_group ? instance.db_subnet_group.db_subnet_group_name : "",
|
31
|
+
"endpoint" => instance.endpoint.address,
|
32
|
+
"engine" => instance.engine,
|
33
|
+
"engine_version" => instance.engine_version,
|
34
|
+
"final_snapshot_identifier" => "#{instance.db_instance_identifier}-final",
|
53
35
|
"id" => instance.db_instance_identifier,
|
54
|
-
"
|
36
|
+
"identifier" => instance.db_instance_identifier,
|
37
|
+
"instance_class" => instance.db_instance_class,
|
38
|
+
"maintenance_window" => instance.preferred_maintenance_window,
|
39
|
+
"multi_az" => instance.multi_az.to_s,
|
40
|
+
"name" => instance.db_name,
|
41
|
+
"parameter_group_name" => instance.db_parameter_groups[0].db_parameter_group_name,
|
42
|
+
"password" => "xxxxxxxx",
|
43
|
+
"port" => instance.endpoint.port.to_s,
|
44
|
+
"publicly_accessible" => instance.publicly_accessible.to_s,
|
45
|
+
"security_group_names.#" => instance.db_security_groups.length.to_s,
|
46
|
+
"status" => instance.db_instance_status,
|
47
|
+
"storage_type" => instance.storage_type,
|
48
|
+
"username" => instance.master_username,
|
49
|
+
"vpc_security_group_ids.#" => instance.vpc_security_groups.length.to_s,
|
50
|
+
}
|
51
|
+
result["aws_db_instance.#{module_name_of(instance)}"] = {
|
52
|
+
"type" => "aws_db_instance",
|
53
|
+
"primary" => {
|
54
|
+
"id" => instance.db_instance_identifier,
|
55
|
+
"attributes" => attributes
|
56
|
+
}
|
55
57
|
}
|
56
|
-
}
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
result
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
generate_tfstate(resources)
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
+
private
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
def db_instances
|
68
|
+
@client.describe_db_instances.db_instances
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
71
|
+
def module_name_of(instance)
|
72
|
+
normalize_module_name(instance.db_instance_identifier)
|
73
|
+
end
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
@@ -1,51 +1,53 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class S3
|
4
|
+
include Terraforming::Util
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def self.tf(client = Aws::S3::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.tfstate(client = Aws::S3::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/s3")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
def tfstate
|
23
|
+
resources = buckets.inject({}) do |result, bucket|
|
24
|
+
result["aws_s3_bucket.#{module_name_of(bucket)}"] = {
|
25
|
+
"type" => "aws_s3_bucket",
|
26
|
+
"primary" => {
|
27
|
+
"id" => bucket.name,
|
28
|
+
"attributes" => {
|
29
|
+
"acl" => "private",
|
30
|
+
"bucket" => bucket.name,
|
31
|
+
"id" => bucket.name
|
32
|
+
}
|
31
33
|
}
|
32
34
|
}
|
33
|
-
}
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
result
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
39
|
+
generate_tfstate(resources)
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
+
private
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def buckets
|
45
|
+
@client.list_buckets.buckets
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
def module_name_of(bucket)
|
49
|
+
normalize_module_name(bucket.name)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -1,56 +1,58 @@
|
|
1
|
-
module Terraforming
|
2
|
-
|
3
|
-
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class SecurityGroup
|
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/security_group")
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"id" => security_group.group_id,
|
27
|
-
"ingress.#" => security_group.ip_permissions.length.to_s,
|
28
|
-
"name" => security_group.group_name,
|
29
|
-
"owner_id" => security_group.owner_id,
|
30
|
-
"vpc_id" => security_group.vpc_id || "",
|
31
|
-
}
|
32
|
-
result["aws_security_group.#{module_name_of(security_group)}"] = {
|
33
|
-
"type" => "aws_security_group",
|
34
|
-
"primary" => {
|
22
|
+
def tfstate
|
23
|
+
resources = security_groups.inject({}) do |result, security_group|
|
24
|
+
attributes = {
|
25
|
+
"description" => security_group.description,
|
26
|
+
"egress.#" => security_group.ip_permissions_egress.length.to_s,
|
35
27
|
"id" => security_group.group_id,
|
36
|
-
"
|
28
|
+
"ingress.#" => security_group.ip_permissions.length.to_s,
|
29
|
+
"name" => security_group.group_name,
|
30
|
+
"owner_id" => security_group.owner_id,
|
31
|
+
"vpc_id" => security_group.vpc_id || "",
|
32
|
+
}
|
33
|
+
result["aws_security_group.#{module_name_of(security_group)}"] = {
|
34
|
+
"type" => "aws_security_group",
|
35
|
+
"primary" => {
|
36
|
+
"id" => security_group.group_id,
|
37
|
+
"attributes" => attributes
|
38
|
+
}
|
37
39
|
}
|
38
|
-
}
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
result
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
generate_tfstate(resources)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
+
private
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def module_name_of(security_group)
|
50
|
+
normalize_module_name(security_group.group_name)
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
def security_groups
|
54
|
+
@client.describe_security_groups.security_groups
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|