Commit 14e34592 authored by Daisuke Fujita's avatar Daisuke Fujita

Merge pull request #29 from dtan4/refactor-module-name

Refactor module name
parents 54068475 405e08c9
......@@ -27,7 +27,7 @@ module Terraforming::Resource
"name" => parameter_group.db_parameter_group_name,
"parameter.#" => db_parameters_in(parameter_group).length.to_s
}
result["aws_db_parameter_group.#{normalize_module_name(parameter_group.db_parameter_group_name)}"] = {
result["aws_db_parameter_group.#{module_name_of(parameter_group)}"] = {
"type" => "aws_db_parameter_group",
"primary" => {
"id" => parameter_group.db_parameter_group_name,
......@@ -50,5 +50,9 @@ module Terraforming::Resource
def db_parameters_in(parameter_group)
@client.describe_db_parameters(db_parameter_group_name: parameter_group.db_parameter_group_name).parameters
end
def module_name_of(parameter_group)
normalize_module_name(parameter_group.db_parameter_group_name)
end
end
end
......@@ -26,7 +26,7 @@ module Terraforming::Resource
"ingress.#" => (security_group.ec2_security_groups.length + security_group.ip_ranges.length).to_s,
"name" => security_group.db_security_group_name,
}
result["aws_db_security_group.#{normalize_module_name(security_group.db_security_group_name)}"] = {
result["aws_db_security_group.#{module_name_of(security_group)}"] = {
"type" => "aws_db_security_group",
"primary" => {
"id" => security_group.db_security_group_name,
......@@ -45,5 +45,9 @@ module Terraforming::Resource
def db_security_groups
@client.describe_db_security_groups.db_security_groups
end
def module_name_of(security_group)
normalize_module_name(security_group.db_security_group_name)
end
end
end
......@@ -25,7 +25,7 @@ module Terraforming::Resource
"name" => subnet_group.db_subnet_group_name,
"subnet_ids.#" => subnet_group.subnets.length.to_s
}
result["aws_db_subnet_group.#{normalize_module_name(subnet_group.db_subnet_group_name)}"] = {
result["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
"type" => "aws_db_subnet_group",
"primary" => {
"id" => subnet_group.db_subnet_group_name,
......@@ -44,5 +44,9 @@ module Terraforming::Resource
def db_subnet_groups
@client.describe_db_subnet_groups.db_subnet_groups
end
def module_name_of(subnet_group)
normalize_module_name(subnet_group.db_subnet_group_name)
end
end
end
......@@ -39,7 +39,7 @@ module Terraforming::Resource
"subnet_id"=> instance.subnet_id,
"tenancy"=> instance.placement.tenancy
}
result["aws_instance.#{normalize_module_name(name_from_tag(instance, instance.instance_id))}"] = {
result["aws_instance.#{module_name_of(instance)}"] = {
"type" => "aws_instance",
"primary" => {
"id" => instance.instance_id,
......@@ -61,5 +61,9 @@ module Terraforming::Resource
def instances
@client.describe_instances.reservations.map(&:instances).flatten
end
def module_name_of(instance)
normalize_module_name(name_from_tag(instance, instance.instance_id))
end
end
end
......@@ -31,7 +31,7 @@ module Terraforming::Resource
"security_groups.#" => load_balancer.security_groups.length.to_s,
"subnets.#" => load_balancer.subnets.length.to_s,
}
result["aws_elb.#{normalize_module_name(load_balancer.load_balancer_name)}"] = {
result["aws_elb.#{module_name_of(load_balancer)}"] = {
"type" => "aws_elb",
"primary" => {
"id" => load_balancer.load_balancer_name,
......@@ -48,5 +48,9 @@ module Terraforming::Resource
def load_balancers
@client.describe_load_balancers.load_balancer_descriptions
end
def module_name_of(load_balancer)
normalize_module_name(load_balancer.load_balancer_name)
end
end
end
......@@ -47,7 +47,7 @@ module Terraforming::Resource
"username" => instance.master_username,
"vpc_security_group_ids.#" => instance.vpc_security_groups.length.to_s,
}
result["aws_db_instance.#{normalize_module_name(instance.db_instance_identifier)}"] = {
result["aws_db_instance.#{module_name_of(instance)}"] = {
"type" => "aws_db_instance",
"primary" => {
"id" => instance.db_instance_identifier,
......@@ -66,5 +66,9 @@ module Terraforming::Resource
def db_instances
@client.describe_db_instances.db_instances
end
def module_name_of(instance)
normalize_module_name(instance.db_instance_identifier)
end
end
end
......@@ -20,7 +20,7 @@ module Terraforming::Resource
def tfstate
resources = buckets.inject({}) do |result, bucket|
result["aws_s3_bucket.#{normalize_module_name(bucket.name)}"] = {
result["aws_s3_bucket.#{module_name_of(bucket)}"] = {
"type" => "aws_s3_bucket",
"primary" => {
"id" => bucket.name,
......@@ -43,5 +43,9 @@ module Terraforming::Resource
def buckets
@client.list_buckets.buckets
end
def module_name_of(bucket)
normalize_module_name(bucket.name)
end
end
end
......@@ -29,7 +29,7 @@ module Terraforming::Resource
"owner_id" => security_group.owner_id,
"vpc_id" => security_group.vpc_id || "",
}
result["aws_security_group.#{normalize_module_name(security_group.group_name)}"] = {
result["aws_security_group.#{module_name_of(security_group)}"] = {
"type" => "aws_security_group",
"primary" => {
"id" => security_group.group_id,
......@@ -45,6 +45,10 @@ module Terraforming::Resource
private
def module_name_of(security_group)
normalize_module_name(security_group.group_name)
end
def security_groups
@client.describe_security_groups.security_groups
end
......
......@@ -28,7 +28,7 @@ module Terraforming::Resource
"instance_tenancy" => vpc.instance_tenancy,
"tags.#" => vpc.tags.length.to_s,
}
result["aws_vpc.#{normalize_module_name(name_from_tag(vpc, vpc.vpc_id))}"] = {
result["aws_vpc.#{module_name_of(vpc)}"] = {
"type" => "aws_vpc",
"primary" => {
"id" => vpc.vpc_id,
......@@ -44,14 +44,6 @@ module Terraforming::Resource
private
def vpcs
@client.describe_vpcs.vpcs
end
def vpc_attribute(vpc, attribute)
@client.describe_vpc_attribute(vpc_id: vpc.vpc_id, attribute: attribute)
end
def enable_dns_hostnames?(vpc)
vpc_attribute(vpc, :enableDnsHostnames).enable_dns_hostnames.value
end
......@@ -59,5 +51,17 @@ module Terraforming::Resource
def enable_dns_support?(vpc)
vpc_attribute(vpc, :enableDnsSupport).enable_dns_support.value
end
def module_name_of(vpc)
normalize_module_name(name_from_tag(vpc, vpc.vpc_id))
end
def vpcs
@client.describe_vpcs.vpcs
end
def vpc_attribute(vpc, attribute)
@client.describe_vpc_attribute(vpc_id: vpc.vpc_id, attribute: attribute)
end
end
end
<% db_parameter_groups.each do |parameter_group| -%>
resource "aws_db_parameter_group" "<%= normalize_module_name(parameter_group.db_parameter_group_name) %>" {
resource "aws_db_parameter_group" "<%= module_name_of(parameter_group) %>" {
name = "<%= parameter_group.db_parameter_group_name %>"
family = "<%= parameter_group.db_parameter_group_family %>"
description = "<%= parameter_group.description %>"
......
<% db_security_groups.each do |security_group| -%>
resource "aws_db_security_group" "<%= normalize_module_name(security_group.db_security_group_name) %>" {
resource "aws_db_security_group" "<%= module_name_of(security_group) %>" {
name = "<%= security_group.db_security_group_name %>"
description = "<%= security_group.db_security_group_description %>"
......
<% db_subnet_groups.each do |subnet_group| -%>
resource "aws_db_subnet_group" "<%= normalize_module_name(subnet_group.db_subnet_group_name) %>" {
resource "aws_db_subnet_group" "<%= module_name_of(subnet_group) %>" {
name = "<%= subnet_group.db_subnet_group_name %>"
description = "<%= subnet_group.db_subnet_group_description %>"
subnet_ids = <%= subnet_group.subnets.map { |subnet| subnet.subnet_identifier }.inspect %>
......
<% instances.each do |instance| -%>
resource "aws_instance" "<%= normalize_module_name(name_from_tag(instance, instance.instance_id)) %>" {
resource "aws_instance" "<%= module_name_of(instance) %>" {
ami = "<%= instance.image_id %>"
availability_zone = "<%= instance.placement.availability_zone %>"
ebs_optimized = <%= instance.ebs_optimized %>
......
<% load_balancers.each do |load_balancer| -%>
resource "aws_elb" "<%= normalize_module_name(load_balancer.load_balancer_name) %>" {
resource "aws_elb" "<%= module_name_of(load_balancer) %>" {
name = "<%= load_balancer.load_balancer_name %>"
availability_zones = <%= load_balancer.availability_zones.inspect %>
subnets = <%= load_balancer.subnets.inspect %>
......
<% db_instances.each do |instance| -%>
resource "aws_db_instance" "<%= instance.db_instance_identifier %>" {
identifier = "<%= normalize_module_name(instance.db_instance_identifier) %>"
identifier = "<%= module_name_of(instance) %>"
allocated_storage = <%= instance.allocated_storage %>
storage_type = "<%= instance.storage_type %>"
engine = "<%= instance.engine %>"
......
<% buckets.each do |bucket| -%>
resource "aws_s3_bucket" "<%= normalize_module_name(bucket.name) %>" {
resource "aws_s3_bucket" "<%= module_name_of(bucket) %>" {
bucket = "<%= bucket.name %>"
acl = "private"
}
......
<% security_groups.each do |security_group| -%>
resource "aws_security_group" "<%= normalize_module_name(security_group.group_name) %>" {
resource "aws_security_group" "<%= module_name_of(security_group) %>" {
name = "<%= security_group.group_name %>"
description = "<%= security_group.description %>"
owner_id = "<%= security_group.owner_id %>"
......
<% vpcs.each do |vpc| -%>
resource "aws_vpc" "<%= normalize_module_name(name_from_tag(vpc, vpc.vpc_id)) %>" {
resource "aws_vpc" "<%= module_name_of(vpc) %>" {
cidr_block = "<%= vpc.cidr_block %>"
enable_dns_hostnames = <%= enable_dns_hostnames?(vpc) %>
enable_dns_support = <%= enable_dns_support?(vpc) %>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment