terraforming 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/terraforming/cli.rb +25 -10
- data/lib/terraforming/resource/db_parameter_group.rb +6 -8
- data/lib/terraforming/resource/db_security_group.rb +6 -8
- data/lib/terraforming/resource/db_subnet_group.rb +6 -8
- data/lib/terraforming/resource/ec2.rb +6 -8
- data/lib/terraforming/resource/elasti_cache_cluster.rb +6 -8
- data/lib/terraforming/resource/elasti_cache_subnet_group.rb +6 -8
- data/lib/terraforming/resource/elb.rb +6 -8
- data/lib/terraforming/resource/iam_group.rb +6 -8
- data/lib/terraforming/resource/iam_group_membership.rb +6 -8
- data/lib/terraforming/resource/iam_group_policy.rb +6 -8
- data/lib/terraforming/resource/iam_instance_profile.rb +6 -8
- data/lib/terraforming/resource/iam_policy.rb +6 -8
- data/lib/terraforming/resource/iam_role.rb +6 -8
- data/lib/terraforming/resource/iam_role_policy.rb +6 -8
- data/lib/terraforming/resource/iam_user.rb +6 -8
- data/lib/terraforming/resource/iam_user_policy.rb +6 -8
- data/lib/terraforming/resource/network_acl.rb +6 -8
- data/lib/terraforming/resource/rds.rb +6 -8
- data/lib/terraforming/resource/route53_record.rb +6 -8
- data/lib/terraforming/resource/route53_zone.rb +6 -8
- data/lib/terraforming/resource/s3.rb +6 -8
- data/lib/terraforming/resource/security_group.rb +31 -46
- data/lib/terraforming/resource/subnet.rb +6 -8
- data/lib/terraforming/resource/vpc.rb +6 -8
- data/lib/terraforming/template/tf/security_group.erb +2 -2
- data/lib/terraforming/util.rb +0 -23
- data/lib/terraforming/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0d4e58b3e575b0651e800cad36a2fb8c58780cc
|
4
|
+
data.tar.gz: 12a4b4fb459f47b28089fcd063bad8b4e720b94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a56a65bff72645122cfd3191dd5354fb9c133528e4d3c4374e84a356ab8621bb31ec5d64d1371d8fa4294484f719f8f3981e9b6825c6f074bd0be105a861270
|
7
|
+
data.tar.gz: 347f65090624c3eac681ed58a8e66dcd0c84a4d47606811e428261449dae95232037d48e2f19db3adba69ce6e0178978dce55ac17e404a53b9a53fd8470678c3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [v0.1.4](https://github.com/dtan4/terraforming/releases/tag/v0.1.4) (2015-08-07)
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
- Refactor internal implements to reduce code #106
|
6
|
+
- Add tests and improvement for Security Group #105
|
7
|
+
|
1
8
|
# [v0.1.3](https://github.com/dtan4/terraforming/releases/tag/v0.1.3) (2015-08-01)
|
2
9
|
|
3
10
|
### Fixed
|
data/lib/terraforming/cli.rb
CHANGED
@@ -126,20 +126,35 @@ module Terraforming
|
|
126
126
|
private
|
127
127
|
|
128
128
|
def execute(klass, options)
|
129
|
-
result =
|
130
|
-
tfstate(klass, options[:merge])
|
131
|
-
else
|
132
|
-
klass.tf
|
133
|
-
end
|
134
|
-
|
129
|
+
result = options[:tfstate] ? tfstate(klass, options[:merge]) : tf(klass)
|
135
130
|
puts result
|
136
131
|
end
|
137
132
|
|
138
|
-
def
|
139
|
-
|
133
|
+
def tf(klass)
|
134
|
+
klass.tf
|
135
|
+
end
|
140
136
|
|
141
|
-
|
142
|
-
|
137
|
+
def tfstate(klass, tfstate_path)
|
138
|
+
tfstate = tfstate_path ? JSON.parse(open(tfstate_path).read) : tfstate_skeleton
|
139
|
+
tfstate["serial"] = tfstate["serial"] + 1
|
140
|
+
tfstate["modules"][0]["resources"] = tfstate["modules"][0]["resources"].merge(klass.tfstate)
|
141
|
+
JSON.pretty_generate(tfstate)
|
142
|
+
end
|
143
|
+
|
144
|
+
def tfstate_skeleton
|
145
|
+
{
|
146
|
+
"version" => 1,
|
147
|
+
"serial" => 0,
|
148
|
+
"modules" => [
|
149
|
+
{
|
150
|
+
"path" => [
|
151
|
+
"root"
|
152
|
+
],
|
153
|
+
"outputs" => {},
|
154
|
+
"resources" => {},
|
155
|
+
}
|
156
|
+
]
|
157
|
+
}
|
143
158
|
end
|
144
159
|
end
|
145
160
|
end
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::RDS::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::RDS::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/db_parameter_group")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
db_parameter_groups.inject({}) do |resources, parameter_group|
|
24
24
|
attributes = {
|
25
25
|
"description" => parameter_group.description,
|
26
26
|
"family" => parameter_group.db_parameter_group_family,
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"name" => parameter_group.db_parameter_group_name,
|
29
29
|
"parameter.#" => db_parameters_in(parameter_group).length.to_s
|
30
30
|
}
|
31
|
-
|
31
|
+
resources["aws_db_parameter_group.#{module_name_of(parameter_group)}"] = {
|
32
32
|
"type" => "aws_db_parameter_group",
|
33
33
|
"primary" => {
|
34
34
|
"id" => parameter_group.db_parameter_group_name,
|
@@ -36,10 +36,8 @@ module Terraforming
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
resources
|
40
40
|
end
|
41
|
-
|
42
|
-
generate_tfstate(resources, tfstate_base)
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::RDS::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::RDS::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,15 +19,15 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/db_security_group")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
db_security_groups.inject({}) do |resources, security_group|
|
24
24
|
attributes = {
|
25
25
|
"db_subnet_group_name" => security_group.db_security_group_name,
|
26
26
|
"id" => security_group.db_security_group_name,
|
27
27
|
"ingress.#" => (security_group.ec2_security_groups.length + security_group.ip_ranges.length).to_s,
|
28
28
|
"name" => security_group.db_security_group_name,
|
29
29
|
}
|
30
|
-
|
30
|
+
resources["aws_db_security_group.#{module_name_of(security_group)}"] = {
|
31
31
|
"type" => "aws_db_security_group",
|
32
32
|
"primary" => {
|
33
33
|
"id" => security_group.db_security_group_name,
|
@@ -35,10 +35,8 @@ module Terraforming
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
|
38
|
+
resources
|
39
39
|
end
|
40
|
-
|
41
|
-
generate_tfstate(resources, tfstate_base)
|
42
40
|
end
|
43
41
|
|
44
42
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::RDS::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::RDS::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,14 +19,14 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/db_subnet_group")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
db_subnet_groups.inject({}) do |resources, subnet_group|
|
24
24
|
attributes = {
|
25
25
|
"description" => subnet_group.db_subnet_group_description,
|
26
26
|
"name" => subnet_group.db_subnet_group_name,
|
27
27
|
"subnet_ids.#" => subnet_group.subnets.length.to_s
|
28
28
|
}
|
29
|
-
|
29
|
+
resources["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
|
30
30
|
"type" => "aws_db_subnet_group",
|
31
31
|
"primary" => {
|
32
32
|
"id" => subnet_group.db_subnet_group_name,
|
@@ -34,10 +34,8 @@ module Terraforming
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
-
|
37
|
+
resources
|
38
38
|
end
|
39
|
-
|
40
|
-
generate_tfstate(resources, tfstate_base)
|
41
39
|
end
|
42
40
|
|
43
41
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::EC2::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/ec2")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
instances.inject({}) do |resources, instance|
|
24
24
|
in_vpc = in_vpc?(instance)
|
25
25
|
block_devices = block_devices_of(instance)
|
26
26
|
|
@@ -46,7 +46,7 @@ module Terraforming
|
|
46
46
|
|
47
47
|
attributes["subnet_id"] = instance.subnet_id if in_vpc?(instance)
|
48
48
|
|
49
|
-
|
49
|
+
resources["aws_instance.#{module_name_of(instance)}"] = {
|
50
50
|
"type" => "aws_instance",
|
51
51
|
"primary" => {
|
52
52
|
"id" => instance.instance_id,
|
@@ -57,10 +57,8 @@ module Terraforming
|
|
57
57
|
}
|
58
58
|
}
|
59
59
|
|
60
|
-
|
60
|
+
resources
|
61
61
|
end
|
62
|
-
|
63
|
-
generate_tfstate(resources, tfstate_base)
|
64
62
|
end
|
65
63
|
|
66
64
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::ElastiCache::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::ElastiCache::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/elasti_cache_cluster")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
cache_clusters.inject({}) do |resources, cache_cluster|
|
24
24
|
attributes = {
|
25
25
|
"cache_nodes.#" => cache_cluster.cache_nodes.length.to_s,
|
26
26
|
"cluster_id" => cache_cluster.cache_cluster_id,
|
@@ -36,7 +36,7 @@ module Terraforming
|
|
36
36
|
"subnet_group_name" => cache_cluster.cache_subnet_group_name,
|
37
37
|
"tags.#" => "0",
|
38
38
|
}
|
39
|
-
|
39
|
+
resources["aws_elasticache_cluster.#{cache_cluster.cache_cluster_id}"] = {
|
40
40
|
"type" => "aws_elasticache_cluster",
|
41
41
|
"primary" => {
|
42
42
|
"id" => cache_cluster.cache_cluster_id,
|
@@ -44,10 +44,8 @@ module Terraforming
|
|
44
44
|
}
|
45
45
|
}
|
46
46
|
|
47
|
-
|
47
|
+
resources
|
48
48
|
end
|
49
|
-
|
50
|
-
generate_tfstate(resources, tfstate_base)
|
51
49
|
end
|
52
50
|
|
53
51
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::ElastiCache::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::ElastiCache::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,14 +19,14 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/elasti_cache_subnet_group")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
cache_subnet_groups.inject({}) do |resources, cache_subnet_group|
|
24
24
|
attributes = {
|
25
25
|
"description" => cache_subnet_group.cache_subnet_group_description,
|
26
26
|
"name" => cache_subnet_group.cache_subnet_group_name,
|
27
27
|
"subnet_ids.#" => subnet_ids_of(cache_subnet_group).length.to_s,
|
28
28
|
}
|
29
|
-
|
29
|
+
resources["aws_elasticache_subnet_group.#{cache_subnet_group.cache_subnet_group_name}"] = {
|
30
30
|
"type" => "aws_elasticache_subnet_group",
|
31
31
|
"primary" => {
|
32
32
|
"id" => cache_subnet_group.cache_subnet_group_name,
|
@@ -34,10 +34,8 @@ module Terraforming
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
-
|
37
|
+
resources
|
38
38
|
end
|
39
|
-
|
40
|
-
generate_tfstate(resources, tfstate_base)
|
41
39
|
end
|
42
40
|
|
43
41
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::ElasticLoadBalancing::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::ElasticLoadBalancing::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/elb")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
load_balancers.inject({}) do |resources, load_balancer|
|
24
24
|
load_balancer_attributes = load_balancer_attributes_of(load_balancer)
|
25
25
|
attributes = {
|
26
26
|
"availability_zones.#" => load_balancer.availability_zones.length.to_s,
|
@@ -43,7 +43,7 @@ module Terraforming
|
|
43
43
|
attributes.merge!(tags_attributes_of(load_balancer))
|
44
44
|
|
45
45
|
|
46
|
-
|
46
|
+
resources["aws_elb.#{module_name_of(load_balancer)}"] = {
|
47
47
|
"type" => "aws_elb",
|
48
48
|
"primary" => {
|
49
49
|
"id" => load_balancer.load_balancer_name,
|
@@ -51,10 +51,8 @@ module Terraforming
|
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
54
|
-
|
54
|
+
resources
|
55
55
|
end
|
56
|
-
|
57
|
-
generate_tfstate(resources, tfstate_base)
|
58
56
|
end
|
59
57
|
|
60
58
|
def healthcheck_attributes_of(elb)
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_group")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_groups.inject({}) do |resources, group|
|
24
24
|
attributes = {
|
25
25
|
"arn"=> group.arn,
|
26
26
|
"id" => group.group_name,
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"path" => group.path,
|
29
29
|
"unique_id" => group.group_id,
|
30
30
|
}
|
31
|
-
|
31
|
+
resources["aws_iam_group.#{group.group_name}"] = {
|
32
32
|
"type" => "aws_iam_group",
|
33
33
|
"primary" => {
|
34
34
|
"id" => group.group_name,
|
@@ -36,10 +36,8 @@ module Terraforming
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
resources
|
40
40
|
end
|
41
|
-
|
42
|
-
generate_tfstate(resources, tfstate_base)
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_group_membership")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_groups.inject({}) do |resources, group|
|
24
24
|
membership_name = membership_name_of(group)
|
25
25
|
|
26
26
|
attributes = {
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"name" => membership_name,
|
30
30
|
"users.#" => group_members_of(group).length.to_s,
|
31
31
|
}
|
32
|
-
|
32
|
+
resources["aws_iam_group_membership.#{group.group_name}"] = {
|
33
33
|
"type" => "aws_iam_group_membership",
|
34
34
|
"primary" => {
|
35
35
|
"id" => membership_name,
|
@@ -37,10 +37,8 @@ module Terraforming
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
|
40
|
+
resources
|
41
41
|
end
|
42
|
-
|
43
|
-
generate_tfstate(resources, tfstate_base)
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,15 +19,15 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_group_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_group_policies.inject({}) do |resources, policy|
|
24
24
|
attributes = {
|
25
25
|
"group" => policy.group_name,
|
26
26
|
"id" => iam_group_policy_id_of(policy),
|
27
27
|
"name" => policy.policy_name,
|
28
28
|
"policy" => prettify_policy(policy.policy_document, true)
|
29
29
|
}
|
30
|
-
|
30
|
+
resources["aws_iam_group_policy.#{policy.policy_name}"] = {
|
31
31
|
"type" => "aws_iam_group_policy",
|
32
32
|
"primary" => {
|
33
33
|
"id" => iam_group_policy_id_of(policy),
|
@@ -35,10 +35,8 @@ module Terraforming
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
|
38
|
+
resources
|
39
39
|
end
|
40
|
-
|
41
|
-
generate_tfstate(resources, tfstate_base)
|
42
40
|
end
|
43
41
|
|
44
42
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_instance_profile")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_instance_profiles.inject({}) do |resources, profile|
|
24
24
|
attributes = {
|
25
25
|
"arn" => profile.arn,
|
26
26
|
"id" => profile.instance_profile_name,
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"path" => profile.path,
|
29
29
|
"roles.#" => profile.roles.length.to_s,
|
30
30
|
}
|
31
|
-
|
31
|
+
resources["aws_iam_instance_profile.#{profile.instance_profile_name}"] = {
|
32
32
|
"type" => "aws_iam_instance_profile",
|
33
33
|
"primary" => {
|
34
34
|
"id" => profile.instance_profile_name,
|
@@ -36,10 +36,8 @@ module Terraforming
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
resources
|
40
40
|
end
|
41
|
-
|
42
|
-
generate_tfstate(resources, tfstate_base)
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_policies.inject({}) do |resources, policy|
|
24
24
|
version = iam_policy_version_of(policy)
|
25
25
|
attributes = {
|
26
26
|
"id" => policy.arn,
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"path" => policy.path,
|
29
29
|
"policy" => prettify_policy(version.document, true),
|
30
30
|
}
|
31
|
-
|
31
|
+
resources["aws_iam_policy.#{policy.policy_name}"] = {
|
32
32
|
"type" => "aws_iam_policy",
|
33
33
|
"primary" => {
|
34
34
|
"id" => policy.arn,
|
@@ -36,10 +36,8 @@ module Terraforming
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
resources
|
40
40
|
end
|
41
|
-
|
42
|
-
generate_tfstate(resources, tfstate_base)
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_role")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_roles.inject({}) do |resources, role|
|
24
24
|
attributes = {
|
25
25
|
"arn" => role.arn,
|
26
26
|
"assume_role_policy" => prettify_policy(role.assume_role_policy_document, true),
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"path" => role.path,
|
30
30
|
"unique_id" => role.role_id,
|
31
31
|
}
|
32
|
-
|
32
|
+
resources["aws_iam_role.#{role.role_name}"] = {
|
33
33
|
"type" => "aws_iam_role",
|
34
34
|
"primary" => {
|
35
35
|
"id" => role.role_name,
|
@@ -37,10 +37,8 @@ module Terraforming
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
|
40
|
+
resources
|
41
41
|
end
|
42
|
-
|
43
|
-
generate_tfstate(resources, tfstate_base)
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,15 +19,15 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_role_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_role_policies.inject({}) do |resources, policy|
|
24
24
|
attributes = {
|
25
25
|
"id" => iam_role_policy_id_of(policy),
|
26
26
|
"name" => policy.policy_name,
|
27
27
|
"policy" => prettify_policy(policy.policy_document, true),
|
28
28
|
"role" => policy.role_name,
|
29
29
|
}
|
30
|
-
|
30
|
+
resources["aws_iam_role_policy.#{policy.policy_name}"] = {
|
31
31
|
"type" => "aws_iam_role_policy",
|
32
32
|
"primary" => {
|
33
33
|
"id" => iam_role_policy_id_of(policy),
|
@@ -35,10 +35,8 @@ module Terraforming
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
|
38
|
+
resources
|
39
39
|
end
|
40
|
-
|
41
|
-
generate_tfstate(resources, tfstate_base)
|
42
40
|
end
|
43
41
|
|
44
42
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_user")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_users.inject({}) do |resources, user|
|
24
24
|
attributes = {
|
25
25
|
"arn"=> user.arn,
|
26
26
|
"id" => user.user_name,
|
@@ -28,7 +28,7 @@ module Terraforming
|
|
28
28
|
"path" => user.path,
|
29
29
|
"unique_id" => user.user_id,
|
30
30
|
}
|
31
|
-
|
31
|
+
resources["aws_iam_user.#{user.user_name}"] = {
|
32
32
|
"type" => "aws_iam_user",
|
33
33
|
"primary" => {
|
34
34
|
"id" => user.user_name,
|
@@ -36,10 +36,8 @@ module Terraforming
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
resources
|
40
40
|
end
|
41
|
-
|
42
|
-
generate_tfstate(resources, tfstate_base)
|
43
41
|
end
|
44
42
|
|
45
43
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::IAM::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,15 +19,15 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_user_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
iam_user_policies.inject({}) do |resources, policy|
|
24
24
|
attributes = {
|
25
25
|
"id" => iam_user_policy_id_of(policy),
|
26
26
|
"name" => policy.policy_name,
|
27
27
|
"policy" => prettify_policy(policy.policy_document, true),
|
28
28
|
"user" => policy.user_name,
|
29
29
|
}
|
30
|
-
|
30
|
+
resources["aws_iam_user_policy.#{policy.policy_name}"] = {
|
31
31
|
"type" => "aws_iam_user_policy",
|
32
32
|
"primary" => {
|
33
33
|
"id" => iam_user_policy_id_of(policy),
|
@@ -35,10 +35,8 @@ module Terraforming
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
|
38
|
-
|
38
|
+
resources
|
39
39
|
end
|
40
|
-
|
41
|
-
generate_tfstate(resources, tfstate_base)
|
42
40
|
end
|
43
41
|
|
44
42
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::EC2::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/network_acl")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
network_acls.inject({}) do |resources, network_acl|
|
24
24
|
attributes = {
|
25
25
|
"egress.#" => egresses_of(network_acl).length.to_s,
|
26
26
|
"id" => network_acl.network_acl_id,
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"tags.#" => network_acl.tags.length.to_s,
|
30
30
|
"vpc_id" => network_acl.vpc_id,
|
31
31
|
}
|
32
|
-
|
32
|
+
resources["aws_network_acl.#{module_name_of(network_acl)}"] = {
|
33
33
|
"type" => "aws_network_acl",
|
34
34
|
"primary" => {
|
35
35
|
"id" => network_acl.network_acl_id,
|
@@ -37,10 +37,8 @@ module Terraforming
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
|
40
|
+
resources
|
41
41
|
end
|
42
|
-
|
43
|
-
generate_tfstate(resources, tfstate_base)
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::RDS::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::RDS::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/rds")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
db_instances.inject({}) do |resources, instance|
|
24
24
|
attributes = {
|
25
25
|
"address" => instance.endpoint.address,
|
26
26
|
"allocated_storage" => instance.allocated_storage.to_s,
|
@@ -48,7 +48,7 @@ module Terraforming
|
|
48
48
|
"username" => instance.master_username,
|
49
49
|
"vpc_security_group_ids.#" => instance.vpc_security_groups.length.to_s,
|
50
50
|
}
|
51
|
-
|
51
|
+
resources["aws_db_instance.#{module_name_of(instance)}"] = {
|
52
52
|
"type" => "aws_db_instance",
|
53
53
|
"primary" => {
|
54
54
|
"id" => instance.db_instance_identifier,
|
@@ -56,10 +56,8 @@ module Terraforming
|
|
56
56
|
}
|
57
57
|
}
|
58
58
|
|
59
|
-
|
59
|
+
resources
|
60
60
|
end
|
61
|
-
|
62
|
-
generate_tfstate(resources, tfstate_base)
|
63
61
|
end
|
64
62
|
|
65
63
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::Route53::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::Route53::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/route53_record")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
records.inject({}) do |resources, r|
|
24
24
|
record, zone_id = r[:record], r[:zone_id]
|
25
25
|
record_id = record_id_of(record, zone_id)
|
26
26
|
|
@@ -37,7 +37,7 @@ module Terraforming
|
|
37
37
|
attributes["weight"] = record.weight.to_s if record.weight
|
38
38
|
attributes["set_identifier"] = record.set_identifier if record.set_identifier
|
39
39
|
|
40
|
-
|
40
|
+
resources["aws_route53_record.#{module_name_of(record)}"] = {
|
41
41
|
"type" => "aws_route53_record",
|
42
42
|
"primary" => {
|
43
43
|
"id" => record_id,
|
@@ -45,10 +45,8 @@ module Terraforming
|
|
45
45
|
}
|
46
46
|
}
|
47
47
|
|
48
|
-
|
48
|
+
resources
|
49
49
|
end
|
50
|
-
|
51
|
-
generate_tfstate(resources, tfstate_base)
|
52
50
|
end
|
53
51
|
|
54
52
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::Route53::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::Route53::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/route53_zone")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
hosted_zones.inject({}) do |resources, hosted_zone|
|
24
24
|
zone_id = zone_id_of(hosted_zone)
|
25
25
|
|
26
26
|
attributes = {
|
@@ -30,7 +30,7 @@ module Terraforming
|
|
30
30
|
"tags.#" => tags_of(hosted_zone).length.to_s,
|
31
31
|
"zone_id" => zone_id,
|
32
32
|
}
|
33
|
-
|
33
|
+
resources["aws_route53_zone.#{module_name_of(hosted_zone)}"] = {
|
34
34
|
"type" => "aws_route53_zone",
|
35
35
|
"primary" => {
|
36
36
|
"id" => zone_id,
|
@@ -38,10 +38,8 @@ module Terraforming
|
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
41
|
-
|
41
|
+
resources
|
42
42
|
end
|
43
|
-
|
44
|
-
generate_tfstate(resources, tfstate_base)
|
45
43
|
end
|
46
44
|
|
47
45
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::S3::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::S3::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,9 +19,9 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/s3")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
24
|
-
|
22
|
+
def tfstate
|
23
|
+
buckets.inject({}) do |resources, bucket|
|
24
|
+
resources["aws_s3_bucket.#{module_name_of(bucket)}"] = {
|
25
25
|
"type" => "aws_s3_bucket",
|
26
26
|
"primary" => {
|
27
27
|
"id" => bucket.name,
|
@@ -33,10 +33,8 @@ module Terraforming
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
-
|
36
|
+
resources
|
37
37
|
end
|
38
|
-
|
39
|
-
generate_tfstate(resources, tfstate_base)
|
40
38
|
end
|
41
39
|
|
42
40
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::EC2::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/security_group")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
security_groups.inject({}) do |resources, security_group|
|
24
24
|
attributes = {
|
25
25
|
"description" => security_group.description,
|
26
26
|
"id" => security_group.group_id,
|
@@ -33,7 +33,7 @@ module Terraforming
|
|
33
33
|
attributes.merge!(egress_attributes_of(security_group))
|
34
34
|
attributes.merge!(ingress_attributes_of(security_group))
|
35
35
|
|
36
|
-
|
36
|
+
resources["aws_security_group.#{module_name_of(security_group)}"] = {
|
37
37
|
"type" => "aws_security_group",
|
38
38
|
"primary" => {
|
39
39
|
"id" => security_group.group_id,
|
@@ -41,18 +41,17 @@ module Terraforming
|
|
41
41
|
}
|
42
42
|
}
|
43
43
|
|
44
|
-
|
44
|
+
resources
|
45
45
|
end
|
46
|
-
|
47
|
-
generate_tfstate(resources, tfstate_base)
|
48
46
|
end
|
49
47
|
|
50
48
|
private
|
51
49
|
|
52
50
|
def ingress_attributes_of(security_group)
|
53
|
-
|
51
|
+
ingresses = dedup_permissions(security_group.ip_permissions, security_group.group_id)
|
52
|
+
attributes = { "ingress.#" => ingresses.length.to_s }
|
54
53
|
|
55
|
-
|
54
|
+
ingresses.each do |permission|
|
56
55
|
attributes.merge!(permission_attributes_of(security_group, permission, "ingress"))
|
57
56
|
end
|
58
57
|
|
@@ -60,9 +59,10 @@ module Terraforming
|
|
60
59
|
end
|
61
60
|
|
62
61
|
def egress_attributes_of(security_group)
|
63
|
-
|
62
|
+
egresses = dedup_permissions(security_group.ip_permissions_egress, security_group.group_id)
|
63
|
+
attributes = { "egress.#" => egresses.length.to_s }
|
64
64
|
|
65
|
-
|
65
|
+
egresses.each do |permission|
|
66
66
|
attributes.merge!(permission_attributes_of(security_group, permission, "egress"))
|
67
67
|
end
|
68
68
|
|
@@ -101,48 +101,33 @@ module Terraforming
|
|
101
101
|
attributes
|
102
102
|
end
|
103
103
|
|
104
|
-
def dedup_permissions(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
security_group.ip_permissions = []
|
109
|
-
security_group.ip_permissions_egress = []
|
104
|
+
def dedup_permissions(permissions, group_id)
|
105
|
+
group_permissions(permissions).inject([]) do |result, (_, perms)|
|
106
|
+
group_ids = perms.map(&:user_id_group_pairs).flatten.map(&:group_id)
|
110
107
|
|
111
|
-
|
112
|
-
|
113
|
-
security_group.ip_permissions << perms.first
|
108
|
+
if group_ids.length == 1 && group_ids.first == group_id
|
109
|
+
result << merge_permissions(perms)
|
114
110
|
else
|
115
|
-
|
116
|
-
if g_ids.length == 1 && g_ids.first == security_group.group_id
|
117
|
-
security_group.ip_permissions << merge_perms(perms)
|
118
|
-
else
|
119
|
-
security_group.ip_permissions.concat(perms)
|
120
|
-
end
|
111
|
+
result.concat(perms)
|
121
112
|
end
|
122
|
-
end
|
123
113
|
|
124
|
-
|
125
|
-
if perms.length == 1
|
126
|
-
security_group.ip_permissions_egress << perms.first
|
127
|
-
else
|
128
|
-
g_ids = perms.map {|perm| perm.user_id_group_pairs}.flatten.map {|gp| gp.group_id}
|
129
|
-
if g_ids.length == 1 && g_ids.first == security_group.group_id
|
130
|
-
security_group.ip_permissions_egress << merge_perms(perms)
|
131
|
-
else
|
132
|
-
security_group.ip_permissions_egress.concat(perms)
|
133
|
-
end
|
134
|
-
end
|
114
|
+
result
|
135
115
|
end
|
136
|
-
security_group
|
137
116
|
end
|
138
117
|
|
139
|
-
def
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
118
|
+
def group_permissions(permissions)
|
119
|
+
permissions.group_by { |permission| [permission.ip_protocol, permission.to_port, permission.from_port] }
|
120
|
+
end
|
121
|
+
|
122
|
+
def merge_permissions(permissions)
|
123
|
+
master_permission = permissions.pop
|
124
|
+
|
125
|
+
permissions.each do |permission|
|
126
|
+
master_permission.user_id_group_pairs.concat(permission.user_id_group_pairs)
|
127
|
+
master_permission.ip_ranges.concat(permission.ip_ranges)
|
144
128
|
end
|
145
|
-
|
129
|
+
|
130
|
+
master_permission
|
146
131
|
end
|
147
132
|
|
148
133
|
def permission_hashcode_of(security_group, permission)
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::EC2::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/subnet")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
subnets.inject({}) do |resources, subnet|
|
24
24
|
attributes = {
|
25
25
|
"availability_zone" => subnet.availability_zone,
|
26
26
|
"cidr_block" => subnet.cidr_block,
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"tags.#" => subnet.tags.length.to_s,
|
30
30
|
"vpc_id" => subnet.vpc_id,
|
31
31
|
}
|
32
|
-
|
32
|
+
resources["aws_subnet.#{module_name_of(subnet)}"] = {
|
33
33
|
"type" => "aws_subnet",
|
34
34
|
"primary" => {
|
35
35
|
"id" => subnet.subnet_id,
|
@@ -37,10 +37,8 @@ module Terraforming
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
|
40
|
+
resources
|
41
41
|
end
|
42
|
-
|
43
|
-
generate_tfstate(resources, tfstate_base)
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
@@ -7,8 +7,8 @@ module Terraforming
|
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client: Aws::EC2::Client.new
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,8 +19,8 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/vpc")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
23
|
-
|
22
|
+
def tfstate
|
23
|
+
vpcs.inject({}) do |resources, vpc|
|
24
24
|
attributes = {
|
25
25
|
"cidr_block" => vpc.cidr_block,
|
26
26
|
"enable_dns_hostnames" => enable_dns_hostnames?(vpc).to_s,
|
@@ -29,7 +29,7 @@ module Terraforming
|
|
29
29
|
"instance_tenancy" => vpc.instance_tenancy,
|
30
30
|
"tags.#" => vpc.tags.length.to_s,
|
31
31
|
}
|
32
|
-
|
32
|
+
resources["aws_vpc.#{module_name_of(vpc)}"] = {
|
33
33
|
"type" => "aws_vpc",
|
34
34
|
"primary" => {
|
35
35
|
"id" => vpc.vpc_id,
|
@@ -37,10 +37,8 @@ module Terraforming
|
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
|
40
|
+
resources
|
41
41
|
end
|
42
|
-
|
43
|
-
generate_tfstate(resources, tfstate_base)
|
44
42
|
end
|
45
43
|
|
46
44
|
private
|
@@ -4,7 +4,7 @@ resource "aws_security_group" "<%= module_name_of(security_group) %>" {
|
|
4
4
|
description = "<%= security_group.description %>"
|
5
5
|
vpc_id = "<%= security_group.vpc_id || '' %>"
|
6
6
|
|
7
|
-
<% dedup_permissions(security_group
|
7
|
+
<% dedup_permissions(security_group.ip_permissions, security_group.group_id).each do |permission| -%>
|
8
8
|
<%- security_groups = security_groups_in(permission).reject { |group_id| group_id == security_group.group_id } -%>
|
9
9
|
ingress {
|
10
10
|
from_port = <%= permission.from_port || 0 %>
|
@@ -24,7 +24,7 @@ resource "aws_security_group" "<%= module_name_of(security_group) %>" {
|
|
24
24
|
|
25
25
|
<% end -%>
|
26
26
|
|
27
|
-
<% dedup_permissions(security_group
|
27
|
+
<% dedup_permissions(security_group.ip_permissions_egress, security_group.group_id).each do |permission| -%>
|
28
28
|
egress {
|
29
29
|
from_port = <%= permission.from_port || 0 %>
|
30
30
|
to_port = <%= permission.to_port || 0 %>
|
data/lib/terraforming/util.rb
CHANGED
@@ -17,13 +17,6 @@ module Terraforming
|
|
17
17
|
File.join(File.expand_path(File.dirname(__FILE__)), "template", template_name) << ".erb"
|
18
18
|
end
|
19
19
|
|
20
|
-
def generate_tfstate(resources, tfstate_base = nil)
|
21
|
-
tfstate = tfstate_base || tfstate_skeleton
|
22
|
-
tfstate["serial"] = tfstate["serial"] + 1
|
23
|
-
tfstate["modules"][0]["resources"] = tfstate["modules"][0]["resources"].merge(resources)
|
24
|
-
JSON.pretty_generate(tfstate)
|
25
|
-
end
|
26
|
-
|
27
20
|
def prettify_policy(policy_document, breakline = false)
|
28
21
|
json = JSON.pretty_generate(JSON.parse(CGI.unescape(policy_document)))
|
29
22
|
|
@@ -33,21 +26,5 @@ module Terraforming
|
|
33
26
|
json.strip
|
34
27
|
end
|
35
28
|
end
|
36
|
-
|
37
|
-
def tfstate_skeleton
|
38
|
-
{
|
39
|
-
"version" => 1,
|
40
|
-
"serial" => 0,
|
41
|
-
"modules" => [
|
42
|
-
{
|
43
|
-
"path" => [
|
44
|
-
"root"
|
45
|
-
],
|
46
|
-
"outputs" => {},
|
47
|
-
"resources" => {},
|
48
|
-
}
|
49
|
-
]
|
50
|
-
}
|
51
|
-
end
|
52
29
|
end
|
53
30
|
end
|
data/lib/terraforming/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.4
|
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-
|
11
|
+
date: 2015-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -258,8 +258,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
260
|
rubyforge_project:
|
261
|
-
rubygems_version: 2.4.
|
261
|
+
rubygems_version: 2.4.7
|
262
262
|
signing_key:
|
263
263
|
specification_version: 4
|
264
264
|
summary: Export existing AWS resources to Terraform style (tf, tfstate)
|
265
265
|
test_files: []
|
266
|
+
has_rdoc:
|