terraforming 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/README.md +12 -2
- data/lib/terraforming.rb +4 -0
- data/lib/terraforming/cli.rb +33 -20
- data/lib/terraforming/resource/db_parameter_group.rb +5 -5
- data/lib/terraforming/resource/db_security_group.rb +5 -5
- data/lib/terraforming/resource/db_subnet_group.rb +5 -5
- data/lib/terraforming/resource/ec2.rb +5 -5
- data/lib/terraforming/resource/elb.rb +9 -5
- data/lib/terraforming/resource/iam_group.rb +5 -5
- data/lib/terraforming/resource/iam_group_policy.rb +6 -6
- data/lib/terraforming/resource/iam_instance_profile.rb +52 -0
- data/lib/terraforming/resource/iam_policy.rb +6 -6
- data/lib/terraforming/resource/iam_role.rb +53 -0
- data/lib/terraforming/resource/iam_role_policy.rb +69 -0
- data/lib/terraforming/resource/iam_user.rb +5 -5
- data/lib/terraforming/resource/iam_user_policy.rb +6 -6
- data/lib/terraforming/resource/network_acl.rb +10 -5
- data/lib/terraforming/resource/rds.rb +5 -5
- data/lib/terraforming/resource/route53_record.rb +5 -5
- data/lib/terraforming/resource/route53_zone.rb +5 -5
- data/lib/terraforming/resource/s3.rb +5 -5
- data/lib/terraforming/resource/security_group.rb +86 -7
- data/lib/terraforming/resource/subnet.rb +5 -5
- data/lib/terraforming/resource/vpc.rb +5 -5
- data/lib/terraforming/template/tf/elb.erb +4 -1
- data/lib/terraforming/template/tf/iam_group_policy.erb +1 -1
- data/lib/terraforming/template/tf/iam_instance_profile.erb +8 -0
- data/lib/terraforming/template/tf/iam_policy.erb +1 -1
- data/lib/terraforming/template/tf/iam_role.erb +10 -0
- data/lib/terraforming/template/tf/iam_role_policy.erb +10 -0
- data/lib/terraforming/template/tf/iam_user_policy.erb +1 -1
- data/lib/terraforming/template/tf/network_acl.erb +2 -1
- data/lib/terraforming/template/tf/security_group.erb +11 -2
- data/lib/terraforming/util.rb +21 -6
- data/lib/terraforming/version.rb +1 -1
- data/terraforming.gemspec +1 -1
- metadata +11 -12
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class IAMGroupPolicy
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,13 +19,13 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_group_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = iam_group_policies.inject({}) do |result, 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
|
-
"policy" =>
|
28
|
+
"policy" => prettify_policy(policy.policy_document, true)
|
29
29
|
}
|
30
30
|
result["aws_iam_group_policy.#{policy.policy_name}"] = {
|
31
31
|
"type" => "aws_iam_group_policy",
|
@@ -38,7 +38,7 @@ module Terraforming
|
|
38
38
|
result
|
39
39
|
end
|
40
40
|
|
41
|
-
generate_tfstate(resources)
|
41
|
+
generate_tfstate(resources, tfstate_base)
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMInstanceProfile
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/iam_instance_profile")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate(tfstate_base)
|
23
|
+
resources = iam_instance_profiles.inject({}) do |result, profile|
|
24
|
+
attributes = {
|
25
|
+
"arn" => profile.arn,
|
26
|
+
"id" => profile.instance_profile_name,
|
27
|
+
"name" => profile.instance_profile_name,
|
28
|
+
"path" => profile.path,
|
29
|
+
"roles.#" => profile.roles.length.to_s,
|
30
|
+
}
|
31
|
+
result["aws_iam_instance_profile.#{profile.instance_profile_name}"] = {
|
32
|
+
"type" => "aws_iam_instance_profile",
|
33
|
+
"primary" => {
|
34
|
+
"id" => profile.instance_profile_name,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
generate_tfstate(resources, tfstate_base)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def iam_instance_profiles
|
48
|
+
@client.list_instance_profiles.instance_profiles
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class IAMPolicy
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,14 +19,14 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = iam_policies.inject({}) do |result, policy|
|
24
24
|
version = iam_policy_version_of(policy)
|
25
25
|
attributes = {
|
26
26
|
"id" => policy.arn,
|
27
27
|
"name" => policy.policy_name,
|
28
28
|
"path" => policy.path,
|
29
|
-
"policy" =>
|
29
|
+
"policy" => prettify_policy(version.document, true),
|
30
30
|
}
|
31
31
|
result["aws_iam_policy.#{policy.policy_name}"] = {
|
32
32
|
"type" => "aws_iam_policy",
|
@@ -39,7 +39,7 @@ module Terraforming
|
|
39
39
|
result
|
40
40
|
end
|
41
41
|
|
42
|
-
generate_tfstate(resources)
|
42
|
+
generate_tfstate(resources, tfstate_base)
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMRole
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/iam_role")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate(tfstate_base)
|
23
|
+
resources = iam_roles.inject({}) do |result, role|
|
24
|
+
attributes = {
|
25
|
+
"arn" => role.arn,
|
26
|
+
"assume_role_policy" => prettify_policy(role.assume_role_policy_document, true),
|
27
|
+
"id" => role.role_name,
|
28
|
+
"name" => role.role_name,
|
29
|
+
"path" => role.path,
|
30
|
+
"unique_id" => role.role_id,
|
31
|
+
}
|
32
|
+
result["aws_iam_role.#{role.role_name}"] = {
|
33
|
+
"type" => "aws_iam_role",
|
34
|
+
"primary" => {
|
35
|
+
"id" => role.role_name,
|
36
|
+
"attributes" => attributes
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
generate_tfstate(resources, tfstate_base)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def iam_roles
|
49
|
+
@client.list_roles.roles
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMRolePolicy
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/iam_role_policy")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate(tfstate_base)
|
23
|
+
resources = iam_role_policies.inject({}) do |result, policy|
|
24
|
+
attributes = {
|
25
|
+
"id" => iam_role_policy_id_of(policy),
|
26
|
+
"name" => policy.policy_name,
|
27
|
+
"policy" => prettify_policy(policy.policy_document, true),
|
28
|
+
"role" => policy.role_name,
|
29
|
+
}
|
30
|
+
result["aws_iam_role_policy.#{policy.policy_name}"] = {
|
31
|
+
"type" => "aws_iam_role_policy",
|
32
|
+
"primary" => {
|
33
|
+
"id" => iam_role_policy_id_of(policy),
|
34
|
+
"attributes" => attributes
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
generate_tfstate(resources, tfstate_base)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def iam_roles
|
47
|
+
@client.list_roles.roles
|
48
|
+
end
|
49
|
+
|
50
|
+
def iam_role_policy_id_of(policy)
|
51
|
+
"#{policy.role_name}:#{policy.policy_name}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def iam_role_policy_names_in(role)
|
55
|
+
@client.list_role_policies(role_name: role.role_name).policy_names
|
56
|
+
end
|
57
|
+
|
58
|
+
def iam_role_policy_of(role, policy_name)
|
59
|
+
@client.get_role_policy(role_name: role.role_name, policy_name: policy_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def iam_role_policies
|
63
|
+
iam_roles.map do |role|
|
64
|
+
iam_role_policy_names_in(role).map { |policy_name| iam_role_policy_of(role, policy_name) }
|
65
|
+
end.flatten
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class IAMUser
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,7 +19,7 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_user")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = iam_users.inject({}) do |result, user|
|
24
24
|
attributes = {
|
25
25
|
"arn"=> user.arn,
|
@@ -39,7 +39,7 @@ module Terraforming
|
|
39
39
|
result
|
40
40
|
end
|
41
41
|
|
42
|
-
generate_tfstate(resources)
|
42
|
+
generate_tfstate(resources, tfstate_base)
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class IAMUserPolicy
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::IAM::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::IAM::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,12 +19,12 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/iam_user_policy")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = iam_user_policies.inject({}) do |result, policy|
|
24
24
|
attributes = {
|
25
25
|
"id" => iam_user_policy_id_of(policy),
|
26
26
|
"name" => policy.policy_name,
|
27
|
-
"policy" =>
|
27
|
+
"policy" => prettify_policy(policy.policy_document, true),
|
28
28
|
"user" => policy.user_name,
|
29
29
|
}
|
30
30
|
result["aws_iam_user_policy.#{policy.policy_name}"] = {
|
@@ -38,7 +38,7 @@ module Terraforming
|
|
38
38
|
result
|
39
39
|
end
|
40
40
|
|
41
|
-
generate_tfstate(resources)
|
41
|
+
generate_tfstate(resources, tfstate_base)
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class NetworkACL
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::EC2::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,12 +19,13 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/network_acl")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = network_acls.inject({}) do |result, network_acl|
|
24
24
|
attributes = {
|
25
25
|
"egress.#" => egresses_of(network_acl).length.to_s,
|
26
26
|
"id" => network_acl.network_acl_id,
|
27
27
|
"ingress.#" => ingresses_of(network_acl).length.to_s,
|
28
|
+
"subnet_ids.#" => subnet_ids_of(network_acl).length.to_s,
|
28
29
|
"tags.#" => network_acl.tags.length.to_s,
|
29
30
|
"vpc_id" => network_acl.vpc_id,
|
30
31
|
}
|
@@ -39,7 +40,7 @@ module Terraforming
|
|
39
40
|
result
|
40
41
|
end
|
41
42
|
|
42
|
-
generate_tfstate(resources)
|
43
|
+
generate_tfstate(resources, tfstate_base)
|
43
44
|
end
|
44
45
|
|
45
46
|
private
|
@@ -72,6 +73,10 @@ module Terraforming
|
|
72
73
|
@client.describe_network_acls.network_acls
|
73
74
|
end
|
74
75
|
|
76
|
+
def subnet_ids_of(network_acl)
|
77
|
+
network_acl.associations.map { |association| association.subnet_id }
|
78
|
+
end
|
79
|
+
|
75
80
|
def to_port_of(entry)
|
76
81
|
entry.port_range ? entry.port_range.to : 0
|
77
82
|
end
|
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class RDS
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::RDS::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::RDS::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,7 +19,7 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/rds")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = db_instances.inject({}) do |result, instance|
|
24
24
|
attributes = {
|
25
25
|
"address" => instance.endpoint.address,
|
@@ -59,7 +59,7 @@ module Terraforming
|
|
59
59
|
result
|
60
60
|
end
|
61
61
|
|
62
|
-
generate_tfstate(resources)
|
62
|
+
generate_tfstate(resources, tfstate_base)
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
@@ -3,12 +3,12 @@ module Terraforming
|
|
3
3
|
class Route53Record
|
4
4
|
include Terraforming::Util
|
5
5
|
|
6
|
-
def self.tf(client
|
6
|
+
def self.tf(client: Aws::Route53::Client.new)
|
7
7
|
self.new(client).tf
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.tfstate(client
|
11
|
-
self.new(client).tfstate
|
10
|
+
def self.tfstate(client: Aws::Route53::Client.new, tfstate_base: nil)
|
11
|
+
self.new(client).tfstate(tfstate_base)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
@@ -19,7 +19,7 @@ module Terraforming
|
|
19
19
|
apply_template(@client, "tf/route53_record")
|
20
20
|
end
|
21
21
|
|
22
|
-
def tfstate
|
22
|
+
def tfstate(tfstate_base)
|
23
23
|
resources = records.inject({}) do |result, r|
|
24
24
|
record, zone_id = r[:record], r[:zone_id]
|
25
25
|
record_id = record_id_of(record, zone_id)
|
@@ -48,7 +48,7 @@ module Terraforming
|
|
48
48
|
result
|
49
49
|
end
|
50
50
|
|
51
|
-
generate_tfstate(resources)
|
51
|
+
generate_tfstate(resources, tfstate_base)
|
52
52
|
end
|
53
53
|
|
54
54
|
private
|