aws-insight 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +84 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +336 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +62 -0
- data/Gemfile +19 -0
- data/Guardfile +12 -0
- data/LICENSE +22 -0
- data/README.md +393 -0
- data/Rakefile +6 -0
- data/bin/terraforming +5 -0
- data/contrib/zsh-completion/_terraforming +65 -0
- data/lib/terraforming.rb +54 -0
- data/lib/terraforming/cli.rb +340 -0
- data/lib/terraforming/resource/alb.rb +98 -0
- data/lib/terraforming/resource/auto_scaling_group.rb +90 -0
- data/lib/terraforming/resource/cloud_watch_alarm.rb +87 -0
- data/lib/terraforming/resource/config.rb +98 -0
- data/lib/terraforming/resource/db_parameter_group.rb +58 -0
- data/lib/terraforming/resource/db_security_group.rb +57 -0
- data/lib/terraforming/resource/db_subnet_group.rb +52 -0
- data/lib/terraforming/resource/ec2.rb +130 -0
- data/lib/terraforming/resource/efs_file_system.rb +60 -0
- data/lib/terraforming/resource/eip.rb +66 -0
- data/lib/terraforming/resource/elasti_cache_cluster.rb +80 -0
- data/lib/terraforming/resource/elasti_cache_subnet_group.rb +56 -0
- data/lib/terraforming/resource/elb.rb +203 -0
- data/lib/terraforming/resource/iam_group.rb +54 -0
- data/lib/terraforming/resource/iam_group_membership.rb +63 -0
- data/lib/terraforming/resource/iam_group_policy.rb +71 -0
- data/lib/terraforming/resource/iam_instance_profile.rb +54 -0
- data/lib/terraforming/resource/iam_policy.rb +63 -0
- data/lib/terraforming/resource/iam_policy_attachment.rb +86 -0
- data/lib/terraforming/resource/iam_role.rb +56 -0
- data/lib/terraforming/resource/iam_role_policy.rb +71 -0
- data/lib/terraforming/resource/iam_user.rb +55 -0
- data/lib/terraforming/resource/iam_user_policy.rb +71 -0
- data/lib/terraforming/resource/internet_gateway.rb +54 -0
- data/lib/terraforming/resource/kms_alias.rb +55 -0
- data/lib/terraforming/resource/kms_key.rb +84 -0
- data/lib/terraforming/resource/launch_configuration.rb +106 -0
- data/lib/terraforming/resource/nat_gateway.rb +57 -0
- data/lib/terraforming/resource/network_acl.rb +83 -0
- data/lib/terraforming/resource/network_interface.rb +68 -0
- data/lib/terraforming/resource/rds.rb +74 -0
- data/lib/terraforming/resource/redshift.rb +67 -0
- data/lib/terraforming/resource/route53_record.rb +106 -0
- data/lib/terraforming/resource/route53_zone.rb +89 -0
- data/lib/terraforming/resource/route_table.rb +122 -0
- data/lib/terraforming/resource/route_table_association.rb +59 -0
- data/lib/terraforming/resource/s3.rb +69 -0
- data/lib/terraforming/resource/security_group.rb +188 -0
- data/lib/terraforming/resource/sns_topic.rb +75 -0
- data/lib/terraforming/resource/sns_topic_subscription.rb +83 -0
- data/lib/terraforming/resource/sqs.rb +70 -0
- data/lib/terraforming/resource/subnet.rb +55 -0
- data/lib/terraforming/resource/vpc.rb +67 -0
- data/lib/terraforming/resource/vpn_gateway.rb +55 -0
- data/lib/terraforming/template/tf/alb.erb +28 -0
- data/lib/terraforming/template/tf/auto_scaling_group.erb +28 -0
- data/lib/terraforming/template/tf/cloud_watch_alarm.erb +33 -0
- data/lib/terraforming/template/tf/db_parameter_group.erb +17 -0
- data/lib/terraforming/template/tf/db_security_group.erb +26 -0
- data/lib/terraforming/template/tf/db_subnet_group.erb +8 -0
- data/lib/terraforming/template/tf/ec2.erb +56 -0
- data/lib/terraforming/template/tf/eip.erb +11 -0
- data/lib/terraforming/template/tf/elasti_cache_cluster.erb +22 -0
- data/lib/terraforming/template/tf/elasti_cache_subnet_group.erb +8 -0
- data/lib/terraforming/template/tf/elastic_filesystem.erb +18 -0
- data/lib/terraforming/template/tf/elb.erb +51 -0
- data/lib/terraforming/template/tf/iam_group.erb +7 -0
- data/lib/terraforming/template/tf/iam_group_membership.erb +8 -0
- data/lib/terraforming/template/tf/iam_group_policy.erb +10 -0
- data/lib/terraforming/template/tf/iam_instance_profile.erb +8 -0
- data/lib/terraforming/template/tf/iam_policy.erb +12 -0
- data/lib/terraforming/template/tf/iam_policy_attachment.erb +10 -0
- 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.erb +7 -0
- data/lib/terraforming/template/tf/iam_user_policy.erb +10 -0
- data/lib/terraforming/template/tf/internet_gateway.erb +14 -0
- data/lib/terraforming/template/tf/kms_alias.erb +7 -0
- data/lib/terraforming/template/tf/kms_key.erb +13 -0
- data/lib/terraforming/template/tf/launch_configuration.erb +68 -0
- data/lib/terraforming/template/tf/nat_gateway.erb +9 -0
- data/lib/terraforming/template/tf/network_acl.erb +43 -0
- data/lib/terraforming/template/tf/network_interface.erb +22 -0
- data/lib/terraforming/template/tf/rds.erb +25 -0
- data/lib/terraforming/template/tf/redshift.erb +23 -0
- data/lib/terraforming/template/tf/route53_record.erb +52 -0
- data/lib/terraforming/template/tf/route53_zone.erb +18 -0
- data/lib/terraforming/template/tf/route_table.erb +34 -0
- data/lib/terraforming/template/tf/route_table_association.erb +9 -0
- data/lib/terraforming/template/tf/s3.erb +12 -0
- data/lib/terraforming/template/tf/security_group.erb +56 -0
- data/lib/terraforming/template/tf/sns_topic.erb +17 -0
- data/lib/terraforming/template/tf/sns_topic_subscription.erb +23 -0
- data/lib/terraforming/template/tf/sqs.erb +21 -0
- data/lib/terraforming/template/tf/subnet.erb +15 -0
- data/lib/terraforming/template/tf/vpc.erb +15 -0
- data/lib/terraforming/template/tf/vpn_gateway.erb +14 -0
- data/lib/terraforming/util.rb +30 -0
- data/lib/terraforming/version.rb +3 -0
- data/script/console +14 -0
- data/script/generate +97 -0
- data/script/setup +7 -0
- data/templates/resource.erb.erb +3 -0
- data/templates/resource.rb.erb +31 -0
- data/templates/resource_spec.rb.erb +39 -0
- data/terraforming.gemspec +31 -0
- metadata +271 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class ELB
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::ElasticLoadBalancing::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::ElasticLoadBalancing::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/elb")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
load_balancers.inject({}) do |resources, load_balancer|
|
24
|
+
load_balancer_attributes = load_balancer_attributes_of(load_balancer)
|
25
|
+
attributes = {
|
26
|
+
"availability_zones.#" => load_balancer.availability_zones.length.to_s,
|
27
|
+
"connection_draining" => load_balancer_attributes.connection_draining.enabled.to_s,
|
28
|
+
"connection_draining_timeout" => load_balancer_attributes.connection_draining.timeout.to_s,
|
29
|
+
"cross_zone_load_balancing" => load_balancer_attributes.cross_zone_load_balancing.enabled.to_s,
|
30
|
+
"dns_name" => load_balancer.dns_name,
|
31
|
+
"id" => load_balancer.load_balancer_name,
|
32
|
+
"idle_timeout" => load_balancer_attributes.connection_settings.idle_timeout.to_s,
|
33
|
+
"instances.#" => load_balancer.instances.length.to_s,
|
34
|
+
"internal" => internal?(load_balancer).to_s,
|
35
|
+
"name" => load_balancer.load_balancer_name,
|
36
|
+
"source_security_group" => load_balancer.source_security_group.group_name,
|
37
|
+
}
|
38
|
+
|
39
|
+
if load_balancer_attributes.access_log.enabled
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
attributes.merge!(access_logs_attributes_of(load_balancer_attributes))
|
44
|
+
attributes.merge!(healthcheck_attributes_of(load_balancer))
|
45
|
+
attributes.merge!(listeners_attributes_of(load_balancer))
|
46
|
+
attributes.merge!(sg_attributes_of(load_balancer))
|
47
|
+
attributes.merge!(subnets_attributes_of(load_balancer))
|
48
|
+
attributes.merge!(instances_attributes_of(load_balancer))
|
49
|
+
attributes.merge!(tags_attributes_of(load_balancer))
|
50
|
+
|
51
|
+
resources["aws_elb.#{module_name_of(load_balancer)}"] = {
|
52
|
+
"type" => "aws_elb",
|
53
|
+
"primary" => {
|
54
|
+
"id" => load_balancer.load_balancer_name,
|
55
|
+
"attributes" => attributes
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
resources
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def access_logs_attributes_of(load_balancer_attributes)
|
64
|
+
access_log = load_balancer_attributes.access_log
|
65
|
+
|
66
|
+
if access_log.enabled
|
67
|
+
{
|
68
|
+
"access_logs.#" => "1",
|
69
|
+
"access_logs.0.bucket" => access_log.s3_bucket_name,
|
70
|
+
"access_logs.0.bucket_prefix" => access_log.s3_bucket_prefix,
|
71
|
+
"access_logs.0.interval" => access_log.emit_interval.to_s,
|
72
|
+
}
|
73
|
+
else
|
74
|
+
{
|
75
|
+
"access_logs.#" => "0",
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def healthcheck_attributes_of(elb)
|
81
|
+
hashcode = healthcheck_hashcode_of(elb.health_check)
|
82
|
+
attributes = {
|
83
|
+
# Now each ELB supports one heatlhcheck
|
84
|
+
"health_check.#" => "1",
|
85
|
+
"health_check.#{hashcode}.healthy_threshold" => elb.health_check.healthy_threshold.to_s,
|
86
|
+
"health_check.#{hashcode}.interval" => elb.health_check.interval.to_s,
|
87
|
+
"health_check.#{hashcode}.target" => elb.health_check.target,
|
88
|
+
"health_check.#{hashcode}.timeout" => elb.health_check.timeout.to_s,
|
89
|
+
"health_check.#{hashcode}.unhealthy_threshold" => elb.health_check.unhealthy_threshold.to_s
|
90
|
+
}
|
91
|
+
|
92
|
+
attributes
|
93
|
+
end
|
94
|
+
|
95
|
+
def healthcheck_hashcode_of(health_check)
|
96
|
+
string =
|
97
|
+
"#{health_check.healthy_threshold}-" <<
|
98
|
+
"#{health_check.unhealthy_threshold}-" <<
|
99
|
+
"#{health_check.target}-" <<
|
100
|
+
"#{health_check.interval}-" <<
|
101
|
+
"#{health_check.timeout}-"
|
102
|
+
|
103
|
+
Zlib.crc32(string)
|
104
|
+
end
|
105
|
+
|
106
|
+
def tags_attributes_of(elb)
|
107
|
+
tags = @client.describe_tags(load_balancer_names: [elb.load_balancer_name]).tag_descriptions.first.tags
|
108
|
+
attributes = { "tags.#" => tags.length.to_s }
|
109
|
+
|
110
|
+
tags.each do |tag|
|
111
|
+
attributes["tags.#{tag.key}"] = tag.value
|
112
|
+
end
|
113
|
+
|
114
|
+
attributes
|
115
|
+
end
|
116
|
+
|
117
|
+
def instances_attributes_of(elb)
|
118
|
+
attributes = { "instances.#" => elb.instances.length.to_s }
|
119
|
+
|
120
|
+
elb.instances.each do |instance|
|
121
|
+
attributes["instances.#{Zlib.crc32(instance.instance_id)}"] = instance.instance_id
|
122
|
+
end
|
123
|
+
|
124
|
+
attributes
|
125
|
+
end
|
126
|
+
|
127
|
+
def subnets_attributes_of(elb)
|
128
|
+
attributes = { "subnets.#" => elb.subnets.length.to_s }
|
129
|
+
|
130
|
+
elb.subnets.each do |subnet_id|
|
131
|
+
attributes["subnets.#{Zlib.crc32(subnet_id)}"] = subnet_id
|
132
|
+
end
|
133
|
+
|
134
|
+
attributes
|
135
|
+
end
|
136
|
+
|
137
|
+
def sg_attributes_of(elb)
|
138
|
+
attributes = { "security_groups.#" => elb.security_groups.length.to_s }
|
139
|
+
|
140
|
+
elb.security_groups.each do |sg_id|
|
141
|
+
attributes["security_groups.#{Zlib.crc32(sg_id)}"] = sg_id
|
142
|
+
end
|
143
|
+
|
144
|
+
attributes
|
145
|
+
end
|
146
|
+
|
147
|
+
def listeners_attributes_of(elb)
|
148
|
+
attributes = { "listener.#" => elb.listener_descriptions.length.to_s }
|
149
|
+
|
150
|
+
elb.listener_descriptions.each do |listener_description|
|
151
|
+
attributes.merge!(listener_attributes_of(listener_description.listener))
|
152
|
+
end
|
153
|
+
|
154
|
+
attributes
|
155
|
+
end
|
156
|
+
|
157
|
+
def listener_attributes_of(listener)
|
158
|
+
hashcode = listener_hashcode_of(listener)
|
159
|
+
|
160
|
+
attributes = {
|
161
|
+
"listener.#{hashcode}.instance_port" => listener.instance_port.to_s,
|
162
|
+
"listener.#{hashcode}.instance_protocol" => listener.instance_protocol.downcase,
|
163
|
+
"listener.#{hashcode}.lb_port" => listener.load_balancer_port.to_s,
|
164
|
+
"listener.#{hashcode}.lb_protocol" => listener.protocol.downcase,
|
165
|
+
"listener.#{hashcode}.ssl_certificate_id" => listener.ssl_certificate_id
|
166
|
+
}
|
167
|
+
|
168
|
+
attributes
|
169
|
+
end
|
170
|
+
|
171
|
+
def listener_hashcode_of(listener)
|
172
|
+
string =
|
173
|
+
"#{listener.instance_port}-" <<
|
174
|
+
"#{listener.instance_protocol.downcase}-" <<
|
175
|
+
"#{listener.load_balancer_port}-" <<
|
176
|
+
"#{listener.protocol.downcase}-" <<
|
177
|
+
"#{listener.ssl_certificate_id}-"
|
178
|
+
|
179
|
+
Zlib.crc32(string)
|
180
|
+
end
|
181
|
+
|
182
|
+
def load_balancers
|
183
|
+
@client.describe_load_balancers.map(&:load_balancer_descriptions).flatten
|
184
|
+
end
|
185
|
+
|
186
|
+
def load_balancer_attributes_of(load_balancer)
|
187
|
+
@client.describe_load_balancer_attributes(load_balancer_name: load_balancer.load_balancer_name).load_balancer_attributes
|
188
|
+
end
|
189
|
+
|
190
|
+
def module_name_of(load_balancer)
|
191
|
+
normalize_module_name(load_balancer.load_balancer_name)
|
192
|
+
end
|
193
|
+
|
194
|
+
def vpc_elb?(load_balancer)
|
195
|
+
load_balancer.vpc_id != ""
|
196
|
+
end
|
197
|
+
|
198
|
+
def internal?(load_balancer)
|
199
|
+
load_balancer.scheme == "internal"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMGroup
|
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)
|
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/iam_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
iam_groups.inject({}) do |resources, group|
|
24
|
+
attributes = {
|
25
|
+
"arn" => group.arn,
|
26
|
+
"id" => group.group_name,
|
27
|
+
"name" => group.group_name,
|
28
|
+
"path" => group.path,
|
29
|
+
"unique_id" => group.group_id,
|
30
|
+
}
|
31
|
+
resources["aws_iam_group.#{module_name_of(group)}"] = {
|
32
|
+
"type" => "aws_iam_group",
|
33
|
+
"primary" => {
|
34
|
+
"id" => group.group_name,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
resources
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def iam_groups
|
46
|
+
@client.list_groups.map(&:groups).flatten
|
47
|
+
end
|
48
|
+
|
49
|
+
def module_name_of(group)
|
50
|
+
normalize_module_name(group.group_name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMGroupMembership
|
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)
|
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/iam_group_membership")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
iam_groups.inject({}) do |resources, group|
|
24
|
+
membership_name = membership_name_of(group)
|
25
|
+
|
26
|
+
attributes = {
|
27
|
+
"group" => group.group_name,
|
28
|
+
"id" => membership_name,
|
29
|
+
"name" => membership_name,
|
30
|
+
"users.#" => group_members_of(group).length.to_s,
|
31
|
+
}
|
32
|
+
resources["aws_iam_group_membership.#{module_name_of(group)}"] = {
|
33
|
+
"type" => "aws_iam_group_membership",
|
34
|
+
"primary" => {
|
35
|
+
"id" => membership_name,
|
36
|
+
"attributes" => attributes
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
resources
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def group_members_of(group)
|
47
|
+
@client.get_group(group_name: group.group_name).map(&:users).flatten.map(&:user_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def iam_groups
|
51
|
+
@client.list_groups.map(&:groups).flatten
|
52
|
+
end
|
53
|
+
|
54
|
+
def membership_name_of(group)
|
55
|
+
"#{group.group_name}-group-membership"
|
56
|
+
end
|
57
|
+
|
58
|
+
def module_name_of(group)
|
59
|
+
normalize_module_name(group.group_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class IAMGroupPolicy
|
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)
|
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/iam_group_policy")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
iam_group_policies.inject({}) do |resources, policy|
|
24
|
+
attributes = {
|
25
|
+
"group" => policy.group_name,
|
26
|
+
"id" => iam_group_policy_id_of(policy),
|
27
|
+
"name" => policy.policy_name,
|
28
|
+
"policy" => prettify_policy(policy.policy_document, breakline: true, unescape: true)
|
29
|
+
}
|
30
|
+
resources["aws_iam_group_policy.#{unique_name(policy)}"] = {
|
31
|
+
"type" => "aws_iam_group_policy",
|
32
|
+
"primary" => {
|
33
|
+
"id" => iam_group_policy_id_of(policy),
|
34
|
+
"attributes" => attributes
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
resources
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def unique_name(policy)
|
45
|
+
"#{normalize_module_name(policy.group_name)}_#{normalize_module_name(policy.policy_name)}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def iam_group_policy_id_of(policy)
|
49
|
+
"#{policy.group_name}:#{policy.policy_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def iam_groups
|
53
|
+
@client.list_groups.map(&:groups).flatten
|
54
|
+
end
|
55
|
+
|
56
|
+
def iam_group_policy_names_in(group)
|
57
|
+
@client.list_group_policies(group_name: group.group_name).policy_names
|
58
|
+
end
|
59
|
+
|
60
|
+
def iam_group_policy_of(group, policy_name)
|
61
|
+
@client.get_group_policy(group_name: group.group_name, policy_name: policy_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def iam_group_policies
|
65
|
+
iam_groups.map do |group|
|
66
|
+
iam_group_policy_names_in(group).map { |policy_name| iam_group_policy_of(group, policy_name) }
|
67
|
+
end.flatten
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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)
|
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/iam_instance_profile")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
iam_instance_profiles.inject({}) do |resources, 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
|
+
resources["aws_iam_instance_profile.#{module_name_of(profile)}"] = {
|
32
|
+
"type" => "aws_iam_instance_profile",
|
33
|
+
"primary" => {
|
34
|
+
"id" => profile.instance_profile_name,
|
35
|
+
"attributes" => attributes
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
resources
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def iam_instance_profiles
|
46
|
+
@client.list_instance_profiles.map(&:instance_profiles).flatten
|
47
|
+
end
|
48
|
+
|
49
|
+
def module_name_of(profile)
|
50
|
+
normalize_module_name(profile.instance_profile_name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|