Commit bd4c349a authored by Daisuke Fujita's avatar Daisuke Fujita

Merge pull request #35 from dtan4/fix-module-nesting

Fix module nesting declation
parents 537f5e10 74174bb4
module Terraforming::Resource
class DBParameterGroup
include Terraforming::Util
module Terraforming
module Resource
class DBParameterGroup
include Terraforming::Util
def self.tf(client = Aws::RDS::Client.new)
self.new(client).tf
end
def self.tf(client = Aws::RDS::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::RDS::Client.new)
self.new(client).tfstate
end
def self.tfstate(client = Aws::RDS::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/db_parameter_group")
end
def tf
apply_template(@client, "tf/db_parameter_group")
end
def tfstate
resources = db_parameter_groups.inject({}) do |result, parameter_group|
attributes = {
"description" => parameter_group.description,
"family" => parameter_group.db_parameter_group_family,
"id" => parameter_group.db_parameter_group_name,
"name" => parameter_group.db_parameter_group_name,
"parameter.#" => db_parameters_in(parameter_group).length.to_s
}
result["aws_db_parameter_group.#{module_name_of(parameter_group)}"] = {
"type" => "aws_db_parameter_group",
"primary" => {
def tfstate
resources = db_parameter_groups.inject({}) do |result, parameter_group|
attributes = {
"description" => parameter_group.description,
"family" => parameter_group.db_parameter_group_family,
"id" => parameter_group.db_parameter_group_name,
"attributes" => attributes
"name" => parameter_group.db_parameter_group_name,
"parameter.#" => db_parameters_in(parameter_group).length.to_s
}
result["aws_db_parameter_group.#{module_name_of(parameter_group)}"] = {
"type" => "aws_db_parameter_group",
"primary" => {
"id" => parameter_group.db_parameter_group_name,
"attributes" => attributes
}
}
}
result
end
result
end
generate_tfstate(resources)
end
generate_tfstate(resources)
end
private
private
def db_parameter_groups
@client.describe_db_parameter_groups.db_parameter_groups
end
def db_parameter_groups
@client.describe_db_parameter_groups.db_parameter_groups
end
def db_parameters_in(parameter_group)
@client.describe_db_parameters(db_parameter_group_name: parameter_group.db_parameter_group_name).parameters
end
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)
def module_name_of(parameter_group)
normalize_module_name(parameter_group.db_parameter_group_name)
end
end
end
end
module Terraforming::Resource
class DBSecurityGroup
include Terraforming::Util
module Terraforming
module Resource
class DBSecurityGroup
include Terraforming::Util
def self.tf(client = Aws::RDS::Client.new)
self.new(client).tf
end
def self.tf(client = Aws::RDS::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::RDS::Client.new)
self.new(client).tfstate
end
def self.tfstate(client = Aws::RDS::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/db_security_group")
end
def tf
apply_template(@client, "tf/db_security_group")
end
def tfstate
resources = db_security_groups.inject({}) do |result, security_group|
attributes = {
"db_subnet_group_name" => security_group.db_security_group_name,
"id" => security_group.db_security_group_name,
"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.#{module_name_of(security_group)}"] = {
"type" => "aws_db_security_group",
"primary" => {
def tfstate
resources = db_security_groups.inject({}) do |result, security_group|
attributes = {
"db_subnet_group_name" => security_group.db_security_group_name,
"id" => security_group.db_security_group_name,
"attributes" => attributes
"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.#{module_name_of(security_group)}"] = {
"type" => "aws_db_security_group",
"primary" => {
"id" => security_group.db_security_group_name,
"attributes" => attributes
}
}
}
result
end
result
end
generate_tfstate(resources)
end
generate_tfstate(resources)
end
private
private
def db_security_groups
@client.describe_db_security_groups.db_security_groups
end
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)
def module_name_of(security_group)
normalize_module_name(security_group.db_security_group_name)
end
end
end
end
module Terraforming::Resource
class DBSubnetGroup
include Terraforming::Util
module Terraforming
module Resource
class DBSubnetGroup
include Terraforming::Util
def self.tf(client = Aws::RDS::Client.new)
self.new(client).tf
end
def self.tf(client = Aws::RDS::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::RDS::Client.new)
self.new(client).tfstate
end
def self.tfstate(client = Aws::RDS::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/db_subnet_group")
end
def tf
apply_template(@client, "tf/db_subnet_group")
end
def tfstate
resources = db_subnet_groups.inject({}) do |result, subnet_group|
attributes = {
"description" => subnet_group.db_subnet_group_description,
"name" => subnet_group.db_subnet_group_name,
"subnet_ids.#" => subnet_group.subnets.length.to_s
}
result["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
"type" => "aws_db_subnet_group",
"primary" => {
"id" => subnet_group.db_subnet_group_name,
"attributes" => attributes
def tfstate
resources = db_subnet_groups.inject({}) do |result, subnet_group|
attributes = {
"description" => subnet_group.db_subnet_group_description,
"name" => subnet_group.db_subnet_group_name,
"subnet_ids.#" => subnet_group.subnets.length.to_s
}
result["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
"type" => "aws_db_subnet_group",
"primary" => {
"id" => subnet_group.db_subnet_group_name,
"attributes" => attributes
}
}
}
result
end
result
end
generate_tfstate(resources)
end
generate_tfstate(resources)
end
private
private
def db_subnet_groups
@client.describe_db_subnet_groups.db_subnet_groups
end
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)
def module_name_of(subnet_group)
normalize_module_name(subnet_group.db_subnet_group_name)
end
end
end
end
module Terraforming::Resource
class EC2
include Terraforming::Util
module Terraforming
module Resource
class EC2
include Terraforming::Util
def self.tf(client = Aws::EC2::Client.new)
self.new(client).tf
end
def self.tf(client = Aws::EC2::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::EC2::Client.new)
self.new(client).tfstate
end
def self.tfstate(client = Aws::EC2::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/ec2")
end
def tf
apply_template(@client, "tf/ec2")
end
def tfstate
resources = instances.inject({}) do |result, instance|
attributes = {
"ami"=> instance.image_id,
"associate_public_ip_address"=> "true",
"availability_zone"=> instance.placement.availability_zone,
"ebs_block_device.#"=> instance.block_device_mappings.length.to_s,
"ebs_optimized"=> instance.ebs_optimized.to_s,
"ephemeral_block_device.#"=> "0",
"id"=> instance.instance_id,
"instance_type"=> instance.instance_type,
"private_dns"=> instance.private_dns_name,
"private_ip"=> instance.private_ip_address,
"public_dns"=> instance.public_dns_name,
"public_ip"=> instance.public_ip_address,
"root_block_device.#"=> instance.root_device_name ? "1" : "0",
"security_groups.#"=> instance.security_groups.length.to_s,
"source_dest_check"=> instance.source_dest_check.to_s,
"subnet_id"=> instance.subnet_id,
"tenancy"=> instance.placement.tenancy
}
result["aws_instance.#{module_name_of(instance)}"] = {
"type" => "aws_instance",
"primary" => {
"id" => instance.instance_id,
"attributes" => attributes,
"meta" => {
"schema_version" => "1"
def tfstate
resources = instances.inject({}) do |result, instance|
attributes = {
"ami"=> instance.image_id,
"associate_public_ip_address"=> "true",
"availability_zone"=> instance.placement.availability_zone,
"ebs_block_device.#"=> instance.block_device_mappings.length.to_s,
"ebs_optimized"=> instance.ebs_optimized.to_s,
"ephemeral_block_device.#"=> "0",
"id"=> instance.instance_id,
"instance_type"=> instance.instance_type,
"private_dns"=> instance.private_dns_name,
"private_ip"=> instance.private_ip_address,
"public_dns"=> instance.public_dns_name,
"public_ip"=> instance.public_ip_address,
"root_block_device.#"=> instance.root_device_name ? "1" : "0",
"security_groups.#"=> instance.security_groups.length.to_s,
"source_dest_check"=> instance.source_dest_check.to_s,
"subnet_id"=> instance.subnet_id,
"tenancy"=> instance.placement.tenancy
}
result["aws_instance.#{module_name_of(instance)}"] = {
"type" => "aws_instance",
"primary" => {
"id" => instance.instance_id,
"attributes" => attributes,
"meta" => {
"schema_version" => "1"
}
}
}
}
result
end
result
end
generate_tfstate(resources)
end
generate_tfstate(resources)
end
private
private
def instances
@client.describe_instances.reservations.map(&:instances).flatten
end
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))
def module_name_of(instance)
normalize_module_name(name_from_tag(instance, instance.instance_id))
end
end
end
end
module Terraforming::Resource
class ELB
include Terraforming::Util
module Terraforming
module Resource
class ELB
include Terraforming::Util
def self.tf(client = Aws::ElasticLoadBalancing::Client.new)
self.new(client).tf
end
def self.tf(client = Aws::ElasticLoadBalancing::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::ElasticLoadBalancing::Client.new)
self.new(client).tfstate
end
def self.tfstate(client = Aws::ElasticLoadBalancing::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/elb")
end
def tf
apply_template(@client, "tf/elb")
end
def tfstate
resources = load_balancers.inject({}) do |result, load_balancer|
attributes = {
"availability_zones.#" => load_balancer.availability_zones.length.to_s,
"dns_name" => load_balancer.dns_name,
"health_check.#" => "1",
"id" => load_balancer.load_balancer_name,
"instances.#" => load_balancer.instances.length.to_s,
"listener.#" => load_balancer.listener_descriptions.length.to_s,
"name" => load_balancer.load_balancer_name,
"security_groups.#" => load_balancer.security_groups.length.to_s,
"subnets.#" => load_balancer.subnets.length.to_s,
}
result["aws_elb.#{module_name_of(load_balancer)}"] = {
"type" => "aws_elb",
"primary" => {
def tfstate
resources = load_balancers.inject({}) do |result, load_balancer|
attributes = {
"availability_zones.#" => load_balancer.availability_zones.length.to_s,
"dns_name" => load_balancer.dns_name,
"health_check.#" => "1",
"id" => load_balancer.load_balancer_name,
"attributes" => attributes
"instances.#" => load_balancer.instances.length.to_s,
"listener.#" => load_balancer.listener_descriptions.length.to_s,
"name" => load_balancer.load_balancer_name,
"security_groups.#" => load_balancer.security_groups.length.to_s,
"subnets.#" => load_balancer.subnets.length.to_s,
}
result["aws_elb.#{module_name_of(load_balancer)}"] = {
"type" => "aws_elb",
"primary" => {
"id" => load_balancer.load_balancer_name,
"attributes" => attributes
}
}
}
result
end
result
end
generate_tfstate(resources)
end
generate_tfstate(resources)
end
def load_balancers
@client.describe_load_balancers.load_balancer_descriptions
end
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)
def module_name_of(load_balancer)
normalize_module_name(load_balancer.load_balancer_name)
end
end
end
end
module Terraforming::Resource
class NetworkACL
include Terraforming::Util
module Terraforming
module Resource
class NetworkACL
include Terraforming::Util
def self.tf(client = Aws::EC2::Client.new)
self.new(client).tf
end
def self.tf(client = Aws::EC2::Client.new)
self.new(client).tf
end
def self.tfstate(client = Aws::EC2::Client.new)
self.new(client).tfstate
end
def self.tfstate(client = Aws::EC2::Client.new)
self.new(client).tfstate
end
def initialize(client)
@client = client
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/network_acl")
end
def tf
apply_template(@client, "tf/network_acl")
end
def tfstate
resources = network_acls.inject({}) do |result, network_acl|
attributes = {
"egress.#" => egresses_of(network_acl).length.to_s,
"id" => network_acl.network_acl_id,
"ingress.#" => ingresses_of(network_acl).length.to_s,
"tags.#" => network_acl.tags.length.to_s,
"vpc_id" => network_acl.vpc_id,
}
result["aws_network_acl.#{module_name_of(network_acl)}"] = {
"type" => "aws_network_acl",
"primary" => {
def tfstate
resources = network_acls.inject({}) do |result, network_acl|
attributes = {
"egress.#" => egresses_of(network_acl).length.to_s,
"id" => network_acl.network_acl_id,
"attributes" => attributes
"ingress.#" => ingresses_of(network_acl).length.to_s,
"tags.#" => network_acl.tags.length.to_s,
"vpc_id" => network_acl.vpc_id,
}
result["aws_network_acl.#{module_name_of(network_acl)}"] = {
"type" => "aws_network_acl",
"primary" => {
"id" => network_acl.network_acl_id,
"attributes" => attributes
}
}
}
result
end
result
end
generate_tfstate(resources)
end
generate_tfstate(resources)
end
private
private