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,98 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class ALB
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::ElasticLoadBalancingV2::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::ElasticLoadBalancingV2::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/alb")
|
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
|
+
"dns_name" => load_balancer.dns_name,
|
27
|
+
"enable_deletion_protection" => load_balancer_attributes["deletion_protection.enabled"].to_s,
|
28
|
+
"id" => load_balancer.load_balancer_arn,
|
29
|
+
"idle_timeout" => load_balancer_attributes["idle_timeout.timeout_seconds"].to_s,
|
30
|
+
"internal" => internal?(load_balancer).to_s,
|
31
|
+
"name" => load_balancer.load_balancer_name,
|
32
|
+
"security_groups.#" => load_balancer.security_groups.length.to_s,
|
33
|
+
"subnets.#" => load_balancer.availability_zones.length.to_s,
|
34
|
+
"zone_id" => load_balancer.canonical_hosted_zone_id,
|
35
|
+
}
|
36
|
+
|
37
|
+
attributes.merge!(access_logs_attributes_of(load_balancer_attributes))
|
38
|
+
attributes.merge!(tag_attributes_of(load_balancer))
|
39
|
+
|
40
|
+
resources["aws_alb.#{module_name_of(load_balancer)}"] = {
|
41
|
+
"type" => "aws_alb",
|
42
|
+
"primary" => {
|
43
|
+
"id" => load_balancer.load_balancer_arn,
|
44
|
+
"attributes" => attributes
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
resources
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def access_logs_attributes_of(load_balancer_attributes)
|
55
|
+
{
|
56
|
+
"access_logs.#" => "1",
|
57
|
+
"access_logs.0.bucket" => load_balancer_attributes["access_logs.s3.bucket"],
|
58
|
+
"access_logs.0.enabled" => load_balancer_attributes["access_logs.s3.enabled"].to_s,
|
59
|
+
"access_logs.0.prefix" => load_balancer_attributes["access_logs.s3.prefix"],
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def internal?(load_balancer)
|
64
|
+
load_balancer.scheme == "internal"
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_balancers
|
68
|
+
@client.describe_load_balancers.load_balancers
|
69
|
+
end
|
70
|
+
|
71
|
+
def load_balancer_attributes_of(load_balancer)
|
72
|
+
@client.describe_load_balancer_attributes(load_balancer_arn: load_balancer.load_balancer_arn).attributes.inject({}) do |result, attribute|
|
73
|
+
result[attribute.key] = attribute.value
|
74
|
+
result
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def module_name_of(load_balancer)
|
79
|
+
normalize_module_name(load_balancer.load_balancer_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def tag_attributes_of(load_balancer)
|
83
|
+
tags = tags_of(load_balancer)
|
84
|
+
attributes = { "tags.%" => tags.length.to_s }
|
85
|
+
|
86
|
+
tags.each do |tag|
|
87
|
+
attributes["tags.#{tag.key}"] = tag.value
|
88
|
+
end
|
89
|
+
|
90
|
+
attributes
|
91
|
+
end
|
92
|
+
|
93
|
+
def tags_of(load_balancer)
|
94
|
+
@client.describe_tags(resource_arns: [load_balancer.load_balancer_arn]).tag_descriptions.first.tags
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class AutoScalingGroup
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::AutoScaling::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::AutoScaling::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/auto_scaling_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
auto_scaling_groups.inject({}) do |resources, group|
|
24
|
+
vpc_zone_specified = vpc_zone_specified?(group)
|
25
|
+
|
26
|
+
attributes = {
|
27
|
+
"availability_zones.#" => vpc_zone_specified ? "0" : group.availability_zones.length.to_s,
|
28
|
+
"default_cooldown" => "300",
|
29
|
+
"desired_capacity" => group.desired_capacity.to_s,
|
30
|
+
"health_check_grace_period" => group.health_check_grace_period.to_s,
|
31
|
+
"health_check_type" => group.health_check_type,
|
32
|
+
"id" => group.auto_scaling_group_name,
|
33
|
+
"launch_configuration" => group.launch_configuration_name,
|
34
|
+
"load_balancers.#" => "0",
|
35
|
+
"max_size" => group.max_size.to_s,
|
36
|
+
"min_size" => group.min_size.to_s,
|
37
|
+
"name" => group.auto_scaling_group_name,
|
38
|
+
"tag.#" => group.tags.length.to_s,
|
39
|
+
"termination_policies.#" => "0",
|
40
|
+
"vpc_zone_identifier.#" => vpc_zone_specified ? vpc_zone_identifier_of(group).length.to_s : "0",
|
41
|
+
}
|
42
|
+
|
43
|
+
group.tags.each do |tag|
|
44
|
+
hashcode = tag_hashcode_of(tag)
|
45
|
+
attributes.merge!({
|
46
|
+
"tag.#{hashcode}.key" => tag.key,
|
47
|
+
"tag.#{hashcode}.propagate_at_launch" => tag.propagate_at_launch.to_s,
|
48
|
+
"tag.#{hashcode}.value" => tag.value,
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
resources["aws_autoscaling_group.#{module_name_of(group)}"] = {
|
53
|
+
"type" => "aws_autoscaling_group",
|
54
|
+
"primary" => {
|
55
|
+
"id" => group.auto_scaling_group_name,
|
56
|
+
"attributes" => attributes,
|
57
|
+
"meta" => {
|
58
|
+
"schema_version" => "1"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
resources
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def auto_scaling_groups
|
70
|
+
@client.describe_auto_scaling_groups.map(&:auto_scaling_groups).flatten
|
71
|
+
end
|
72
|
+
|
73
|
+
def module_name_of(group)
|
74
|
+
normalize_module_name(group.auto_scaling_group_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
def tag_hashcode_of(tag)
|
78
|
+
Zlib.crc32("#{tag.key}-#{tag.value}-#{tag.propagate_at_launch}-")
|
79
|
+
end
|
80
|
+
|
81
|
+
def vpc_zone_identifier_of(group)
|
82
|
+
group.vpc_zone_identifier.split(",")
|
83
|
+
end
|
84
|
+
|
85
|
+
def vpc_zone_specified?(group)
|
86
|
+
group.vpc_zone_identifier && !vpc_zone_identifier_of(group).empty?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class CloudWatchAlarm
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::CloudWatch::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::CloudWatch::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/cloud_watch_alarm")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
alarms.inject({}) do |resources, alarm|
|
24
|
+
resources["aws_cloudwatch_metric_alarm.#{module_name_of(alarm)}"] = {
|
25
|
+
"type" => "aws_cloudwatch_metric_alarm",
|
26
|
+
"primary" => {
|
27
|
+
"id" => alarm.alarm_name,
|
28
|
+
"attributes" => alarm_attributes(alarm)
|
29
|
+
}
|
30
|
+
}
|
31
|
+
resources
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def alarm_attributes(alarm)
|
38
|
+
attributes = {
|
39
|
+
"actions_enabled" => alarm.actions_enabled.to_s,
|
40
|
+
"alarm_description" => sanitize(alarm.alarm_description),
|
41
|
+
"alarm_name" => alarm.alarm_name,
|
42
|
+
"comparison_operator" => alarm.comparison_operator,
|
43
|
+
"evaluation_periods" => alarm.evaluation_periods.to_s,
|
44
|
+
"id" => alarm.alarm_name,
|
45
|
+
"metric_name" => alarm.metric_name,
|
46
|
+
"namespace" => alarm.namespace,
|
47
|
+
"period" => alarm.period.to_s,
|
48
|
+
"statistic" => alarm.statistic,
|
49
|
+
"threshold" => alarm.threshold.to_s,
|
50
|
+
"unit" => sanitize(alarm.unit)
|
51
|
+
}
|
52
|
+
add_checksummed_attributes(attributes, alarm)
|
53
|
+
end
|
54
|
+
|
55
|
+
def alarms
|
56
|
+
@client.describe_alarms.map(&:metric_alarms).flatten
|
57
|
+
end
|
58
|
+
|
59
|
+
def module_name_of(alarm)
|
60
|
+
normalize_module_name(alarm.alarm_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def sanitize(argument)
|
64
|
+
argument.nil? ? "" : argument
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_checksummed_attributes(attributes, alarm)
|
68
|
+
%w(insufficient_data_actions alarm_actions ok_actions dimensions).each do |action|
|
69
|
+
attribute = alarm.send(action.to_sym)
|
70
|
+
attributes["#{action}.#"] = attribute.size.to_s
|
71
|
+
attribute.each do |attr|
|
72
|
+
if attr.is_a? String
|
73
|
+
checksum = Zlib.crc32(attr)
|
74
|
+
value = attr
|
75
|
+
else
|
76
|
+
checksum = attr.name
|
77
|
+
value = attr.value
|
78
|
+
end
|
79
|
+
attributes["#{action}.#{checksum}"] = value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
attributes
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class Config
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::ElasticLoadBalancingV2::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::ElasticLoadBalancingV2::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/alb")
|
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
|
+
"dns_name" => load_balancer.dns_name,
|
27
|
+
"enable_deletion_protection" => load_balancer_attributes["deletion_protection.enabled"].to_s,
|
28
|
+
"id" => load_balancer.load_balancer_arn,
|
29
|
+
"idle_timeout" => load_balancer_attributes["idle_timeout.timeout_seconds"].to_s,
|
30
|
+
"internal" => internal?(load_balancer).to_s,
|
31
|
+
"name" => load_balancer.load_balancer_name,
|
32
|
+
"security_groups.#" => load_balancer.security_groups.length.to_s,
|
33
|
+
"subnets.#" => load_balancer.availability_zones.length.to_s,
|
34
|
+
"zone_id" => load_balancer.canonical_hosted_zone_id,
|
35
|
+
}
|
36
|
+
|
37
|
+
attributes.merge!(access_logs_attributes_of(load_balancer_attributes))
|
38
|
+
attributes.merge!(tag_attributes_of(load_balancer))
|
39
|
+
|
40
|
+
resources["aws_alb.#{module_name_of(load_balancer)}"] = {
|
41
|
+
"type" => "aws_alb",
|
42
|
+
"primary" => {
|
43
|
+
"id" => load_balancer.load_balancer_arn,
|
44
|
+
"attributes" => attributes
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
resources
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def access_logs_attributes_of(load_balancer_attributes)
|
55
|
+
{
|
56
|
+
"access_logs.#" => "1",
|
57
|
+
"access_logs.0.bucket" => load_balancer_attributes["access_logs.s3.bucket"],
|
58
|
+
"access_logs.0.enabled" => load_balancer_attributes["access_logs.s3.enabled"].to_s,
|
59
|
+
"access_logs.0.prefix" => load_balancer_attributes["access_logs.s3.prefix"],
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def internal?(load_balancer)
|
64
|
+
load_balancer.scheme == "internal"
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_balancers
|
68
|
+
@client.describe_load_balancers.load_balancers
|
69
|
+
end
|
70
|
+
|
71
|
+
def load_balancer_attributes_of(load_balancer)
|
72
|
+
@client.describe_load_balancer_attributes(load_balancer_arn: load_balancer.load_balancer_arn).attributes.inject({}) do |result, attribute|
|
73
|
+
result[attribute.key] = attribute.value
|
74
|
+
result
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def module_name_of(load_balancer)
|
79
|
+
normalize_module_name(load_balancer.load_balancer_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def tag_attributes_of(load_balancer)
|
83
|
+
tags = tags_of(load_balancer)
|
84
|
+
attributes = { "tags.%" => tags.length.to_s }
|
85
|
+
|
86
|
+
tags.each do |tag|
|
87
|
+
attributes["tags.#{tag.key}"] = tag.value
|
88
|
+
end
|
89
|
+
|
90
|
+
attributes
|
91
|
+
end
|
92
|
+
|
93
|
+
def tags_of(load_balancer)
|
94
|
+
@client.describe_tags(resource_arns: [load_balancer.load_balancer_arn]).tag_descriptions.first.tags
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class DBParameterGroup
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::RDS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::RDS::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/db_parameter_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
db_parameter_groups.inject({}) do |resources, parameter_group|
|
24
|
+
attributes = {
|
25
|
+
"description" => parameter_group.description,
|
26
|
+
"family" => parameter_group.db_parameter_group_family,
|
27
|
+
"id" => parameter_group.db_parameter_group_name,
|
28
|
+
"name" => parameter_group.db_parameter_group_name,
|
29
|
+
"parameter.#" => db_parameters_in(parameter_group).length.to_s
|
30
|
+
}
|
31
|
+
resources["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
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
resources
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def db_parameter_groups
|
46
|
+
@client.describe_db_parameter_groups.map(&:db_parameter_groups).flatten
|
47
|
+
end
|
48
|
+
|
49
|
+
def db_parameters_in(parameter_group)
|
50
|
+
@client.describe_db_parameters(db_parameter_group_name: parameter_group.db_parameter_group_name).map(&:parameters).flatten
|
51
|
+
end
|
52
|
+
|
53
|
+
def module_name_of(parameter_group)
|
54
|
+
normalize_module_name(parameter_group.db_parameter_group_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class DBSecurityGroup
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::RDS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::RDS::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/db_security_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
db_security_groups.inject({}) do |resources, security_group|
|
24
|
+
attributes = {
|
25
|
+
"db_subnet_group_name" => security_group.db_security_group_name,
|
26
|
+
"id" => security_group.db_security_group_name,
|
27
|
+
"ingress.#" => ingresses_of(security_group).length.to_s,
|
28
|
+
"name" => security_group.db_security_group_name,
|
29
|
+
}
|
30
|
+
resources["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
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
resources
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def ingresses_of(security_group)
|
45
|
+
security_group.ec2_security_groups + security_group.ip_ranges
|
46
|
+
end
|
47
|
+
|
48
|
+
def db_security_groups
|
49
|
+
@client.describe_db_security_groups.map(&:db_security_groups).flatten.select { |sg| !ingresses_of(sg).empty? }
|
50
|
+
end
|
51
|
+
|
52
|
+
def module_name_of(security_group)
|
53
|
+
normalize_module_name(security_group.db_security_group_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|