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,52 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class DBSubnetGroup
|
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_subnet_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
db_subnet_groups.inject({}) do |resources, subnet_group|
|
24
|
+
attributes = {
|
25
|
+
"description" => subnet_group.db_subnet_group_description,
|
26
|
+
"name" => subnet_group.db_subnet_group_name,
|
27
|
+
"subnet_ids.#" => subnet_group.subnets.length.to_s
|
28
|
+
}
|
29
|
+
resources["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
|
30
|
+
"type" => "aws_db_subnet_group",
|
31
|
+
"primary" => {
|
32
|
+
"id" => subnet_group.db_subnet_group_name,
|
33
|
+
"attributes" => attributes
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
resources
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def db_subnet_groups
|
44
|
+
@client.describe_db_subnet_groups.map(&:db_subnet_groups).flatten
|
45
|
+
end
|
46
|
+
|
47
|
+
def module_name_of(subnet_group)
|
48
|
+
normalize_module_name(subnet_group.db_subnet_group_name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class EC2
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::EC2::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/ec2")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
instances.inject({}) do |resources, instance|
|
24
|
+
in_vpc = in_vpc?(instance)
|
25
|
+
block_devices = block_devices_of(instance)
|
26
|
+
|
27
|
+
attributes = {
|
28
|
+
"ami" => instance.image_id,
|
29
|
+
"associate_public_ip_address" => associate_public_ip?(instance).to_s,
|
30
|
+
"availability_zone" => instance.placement.availability_zone,
|
31
|
+
"ebs_block_device.#" => ebs_block_devices_in(block_devices, instance).length.to_s,
|
32
|
+
"ebs_optimized" => instance.ebs_optimized.to_s,
|
33
|
+
"ephemeral_block_device.#" => "0", # Terraform 0.6.1 cannot fetch this field from AWS
|
34
|
+
"id" => instance.instance_id,
|
35
|
+
"instance_type" => instance.instance_type,
|
36
|
+
"monitoring" => monitoring_state(instance).to_s,
|
37
|
+
"private_dns" => instance.private_dns_name,
|
38
|
+
"private_ip" => instance.private_ip_address,
|
39
|
+
"public_dns" => instance.public_dns_name,
|
40
|
+
"public_ip" => instance.public_ip_address,
|
41
|
+
"root_block_device.#" => root_block_devices_in(block_devices, instance).length.to_s,
|
42
|
+
"security_groups.#" => in_vpc ? "0" : instance.security_groups.length.to_s,
|
43
|
+
"source_dest_check" => instance.source_dest_check.to_s,
|
44
|
+
"tenancy" => instance.placement.tenancy,
|
45
|
+
"vpc_security_group_ids.#" => in_vpc ? instance.security_groups.length.to_s : "0",
|
46
|
+
}
|
47
|
+
|
48
|
+
placement_group = instance.placement.group_name
|
49
|
+
attributes["placement_group"] = placement_group unless placement_group.empty?
|
50
|
+
|
51
|
+
attributes["subnet_id"] = instance.subnet_id if in_vpc?(instance)
|
52
|
+
|
53
|
+
resources["aws_instance.#{module_name_of(instance)}"] = {
|
54
|
+
"type" => "aws_instance",
|
55
|
+
"primary" => {
|
56
|
+
"id" => instance.instance_id,
|
57
|
+
"attributes" => attributes,
|
58
|
+
"meta" => {
|
59
|
+
"schema_version" => "1"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
resources
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def block_device_ids_of(instance)
|
71
|
+
instance.block_device_mappings.map { |bdm| bdm.ebs.volume_id }
|
72
|
+
end
|
73
|
+
|
74
|
+
def block_devices_of(instance)
|
75
|
+
return [] if instance.block_device_mappings.empty?
|
76
|
+
@client.describe_volumes(volume_ids: block_device_ids_of(instance)).map(&:volumes).flatten
|
77
|
+
end
|
78
|
+
|
79
|
+
def block_device_mapping_of(instance, volume_id)
|
80
|
+
instance.block_device_mappings.select { |bdm| bdm.ebs.volume_id == volume_id }[0]
|
81
|
+
end
|
82
|
+
|
83
|
+
def ebs_block_devices_in(block_devices, instance)
|
84
|
+
block_devices.reject do |bd|
|
85
|
+
root_block_device?(block_device_mapping_of(instance, bd.volume_id), instance)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# NOTE(dtan4):
|
91
|
+
# Original logic is here:
|
92
|
+
# https://github.com/hashicorp/terraform/blob/281e4d3e67f66daab9cdb1f7c8b6f602d949e5ee/builtin/providers/aws/resource_aws_instance.go#L481-L501
|
93
|
+
#
|
94
|
+
def in_vpc?(instance)
|
95
|
+
!vpc_security_groups_of(instance).empty? ||
|
96
|
+
(instance.subnet_id && instance.subnet_id != "" && instance.security_groups.empty?)
|
97
|
+
end
|
98
|
+
|
99
|
+
def associate_public_ip?(instance)
|
100
|
+
!instance.public_ip_address.to_s.empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
def monitoring_state(instance)
|
104
|
+
%w(enabled pending).include?(instance.monitoring.state)
|
105
|
+
end
|
106
|
+
|
107
|
+
def instances
|
108
|
+
@client.describe_instances.map(&:reservations).flatten.map(&:instances).flatten.reject do |instance|
|
109
|
+
instance.state.name == "terminated"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def module_name_of(instance)
|
114
|
+
normalize_module_name(name_from_tag(instance, instance.instance_id))
|
115
|
+
end
|
116
|
+
|
117
|
+
def root_block_device?(block_device_mapping, instance)
|
118
|
+
block_device_mapping.device_name == instance.root_device_name
|
119
|
+
end
|
120
|
+
|
121
|
+
def root_block_devices_in(block_devices, instance)
|
122
|
+
block_devices.select { |bd| root_block_device?(block_device_mapping_of(instance, bd.volume_id), instance) }
|
123
|
+
end
|
124
|
+
|
125
|
+
def vpc_security_groups_of(instance)
|
126
|
+
instance.security_groups.select { |security_group| /\Asg-/ =~ security_group.group_id }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class EFSFileSystem
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::EFS::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::EFS::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/elastic_filesystem")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
file_systems.inject({}) do |resources, efs|
|
24
|
+
attributes = {
|
25
|
+
"creation_token" => efs.creation_token,
|
26
|
+
"id" => efs.file_system_id,
|
27
|
+
"performance_mode" => efs.performance_mode,
|
28
|
+
"tags.%" => "1",
|
29
|
+
"tags.Name" => efs.name,
|
30
|
+
}
|
31
|
+
|
32
|
+
resources["aws_efs_file_system.#{module_name_of(efs)}"] = {
|
33
|
+
"type" => "aws_efs_file_system",
|
34
|
+
"depends_on" => [],
|
35
|
+
"primary" => {
|
36
|
+
"id" => efs.file_system_id,
|
37
|
+
"attributes" => attributes,
|
38
|
+
"meta" => {},
|
39
|
+
"tainted" => false,
|
40
|
+
},
|
41
|
+
"deposed" => [],
|
42
|
+
"provider" => "aws",
|
43
|
+
}
|
44
|
+
|
45
|
+
resources
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def file_systems
|
52
|
+
@client.describe_file_systems.data.file_systems.flatten
|
53
|
+
end
|
54
|
+
|
55
|
+
def module_name_of(efs)
|
56
|
+
normalize_module_name(efs.file_system_id)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class EIP
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::EC2::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::EC2::Client.new)
|
11
|
+
self.new(client).tfstate
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def tf
|
19
|
+
apply_template(@client, "tf/eip")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
eips.inject({}) do |resources, addr|
|
24
|
+
attributes = {
|
25
|
+
"association_id" => addr.association_id,
|
26
|
+
"domain" => addr.domain,
|
27
|
+
"id" => vpc?(addr) ? addr.allocation_id : addr.public_ip,
|
28
|
+
"instance" => addr.instance_id,
|
29
|
+
"network_interface" => addr.network_interface_id,
|
30
|
+
"private_ip" => addr.private_ip_address,
|
31
|
+
"public_ip" => addr.public_ip,
|
32
|
+
"vpc" => vpc?(addr).to_s,
|
33
|
+
}
|
34
|
+
attributes.delete_if { |_k, v| v.nil? }
|
35
|
+
resources["aws_eip.#{module_name_of(addr)}"] = {
|
36
|
+
"type" => "aws_eip",
|
37
|
+
"primary" => {
|
38
|
+
"id" => vpc?(addr) ? addr.allocation_id : addr.public_ip,
|
39
|
+
"attributes" => attributes
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
resources
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def eips
|
50
|
+
@client.describe_addresses.map(&:addresses).flatten
|
51
|
+
end
|
52
|
+
|
53
|
+
def vpc?(addr)
|
54
|
+
addr.domain.eql?("vpc")
|
55
|
+
end
|
56
|
+
|
57
|
+
def module_name_of(addr)
|
58
|
+
if vpc?(addr)
|
59
|
+
normalize_module_name(addr.allocation_id)
|
60
|
+
else
|
61
|
+
normalize_module_name(addr.public_ip)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class ElastiCacheCluster
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::ElastiCache::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::ElastiCache::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/elasti_cache_cluster")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
cache_clusters.inject({}) do |resources, cache_cluster|
|
24
|
+
attributes = {
|
25
|
+
"cache_nodes.#" => cache_cluster.cache_nodes.length.to_s,
|
26
|
+
"cluster_id" => cache_cluster.cache_cluster_id,
|
27
|
+
"engine" => cache_cluster.engine,
|
28
|
+
"engine_version" => cache_cluster.engine_version,
|
29
|
+
"id" => cache_cluster.cache_cluster_id,
|
30
|
+
"node_type" => cache_cluster.cache_node_type,
|
31
|
+
"num_cache_nodes" => "1",
|
32
|
+
"parameter_group_name" => cache_cluster.cache_parameter_group.cache_parameter_group_name,
|
33
|
+
"security_group_ids.#" => security_group_ids_of(cache_cluster).length.to_s,
|
34
|
+
"security_group_names.#" => security_group_names_of(cache_cluster).length.to_s,
|
35
|
+
"subnet_group_name" => cache_cluster.cache_subnet_group_name,
|
36
|
+
"tags.#" => "0",
|
37
|
+
}
|
38
|
+
|
39
|
+
attributes["port"] = if cache_cluster.configuration_endpoint
|
40
|
+
cache_cluster.configuration_endpoint.port.to_s
|
41
|
+
else
|
42
|
+
cache_cluster.cache_nodes[0].endpoint.port.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
resources["aws_elasticache_cluster.#{module_name_of(cache_cluster)}"] = {
|
46
|
+
"type" => "aws_elasticache_cluster",
|
47
|
+
"primary" => {
|
48
|
+
"id" => cache_cluster.cache_cluster_id,
|
49
|
+
"attributes" => attributes
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
resources
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def cache_clusters
|
60
|
+
@client.describe_cache_clusters(show_cache_node_info: true).map(&:cache_clusters).flatten
|
61
|
+
end
|
62
|
+
|
63
|
+
def cluster_in_vpc?(cache_cluster)
|
64
|
+
cache_cluster.cache_security_groups.empty?
|
65
|
+
end
|
66
|
+
|
67
|
+
def security_group_ids_of(cache_cluster)
|
68
|
+
cache_cluster.security_groups.map { |sg| sg.security_group_id }
|
69
|
+
end
|
70
|
+
|
71
|
+
def security_group_names_of(cache_cluster)
|
72
|
+
cache_cluster.cache_security_groups.map { |sg| sg.cache_security_group_name }
|
73
|
+
end
|
74
|
+
|
75
|
+
def module_name_of(cache_cluster)
|
76
|
+
normalize_module_name(cache_cluster.cache_cluster_id)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Terraforming
|
2
|
+
module Resource
|
3
|
+
class ElastiCacheSubnetGroup
|
4
|
+
include Terraforming::Util
|
5
|
+
|
6
|
+
def self.tf(client: Aws::ElastiCache::Client.new)
|
7
|
+
self.new(client).tf
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.tfstate(client: Aws::ElastiCache::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/elasti_cache_subnet_group")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tfstate
|
23
|
+
cache_subnet_groups.inject({}) do |resources, cache_subnet_group|
|
24
|
+
attributes = {
|
25
|
+
"description" => cache_subnet_group.cache_subnet_group_description,
|
26
|
+
"name" => cache_subnet_group.cache_subnet_group_name,
|
27
|
+
"subnet_ids.#" => subnet_ids_of(cache_subnet_group).length.to_s,
|
28
|
+
}
|
29
|
+
resources["aws_elasticache_subnet_group.#{module_name_of(cache_subnet_group)}"] = {
|
30
|
+
"type" => "aws_elasticache_subnet_group",
|
31
|
+
"primary" => {
|
32
|
+
"id" => cache_subnet_group.cache_subnet_group_name,
|
33
|
+
"attributes" => attributes
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
resources
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def cache_subnet_groups
|
44
|
+
@client.describe_cache_subnet_groups.map(&:cache_subnet_groups).flatten
|
45
|
+
end
|
46
|
+
|
47
|
+
def subnet_ids_of(cache_subnet_group)
|
48
|
+
cache_subnet_group.subnets.map { |sn| sn.subnet_identifier }
|
49
|
+
end
|
50
|
+
|
51
|
+
def module_name_of(cache_subnet_group)
|
52
|
+
normalize_module_name(cache_subnet_group.cache_subnet_group_name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|