lib/terraforming/resource/subnet.rb in terraforming-0.0.1 vs lib/terraforming/resource/subnet.rb in terraforming-0.0.2
- old
+ new
@@ -1,55 +1,57 @@
-module Terraforming::Resource
- class Subnet
- include Terraforming::Util
+module Terraforming
+ module Resource
+ class Subnet
+ 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/subnet")
- end
+ def tf
+ apply_template(@client, "tf/subnet")
+ end
- def tfstate
- resources = subnets.inject({}) do |result, subnet|
- attributes = {
- "availability_zone" => subnet.availability_zone,
- "cidr_block" => subnet.cidr_block,
- "id" => subnet.subnet_id,
- "map_public_ip_on_launch" => subnet.map_public_ip_on_launch.to_s,
- "tags.#" => subnet.tags.length.to_s,
- "vpc_id" => subnet.vpc_id,
- }
- result["aws_subnet.#{module_name_of(subnet)}"] = {
- "type" => "aws_subnet",
- "primary" => {
+ def tfstate
+ resources = subnets.inject({}) do |result, subnet|
+ attributes = {
+ "availability_zone" => subnet.availability_zone,
+ "cidr_block" => subnet.cidr_block,
"id" => subnet.subnet_id,
- "attributes" => attributes
+ "map_public_ip_on_launch" => subnet.map_public_ip_on_launch.to_s,
+ "tags.#" => subnet.tags.length.to_s,
+ "vpc_id" => subnet.vpc_id,
}
- }
+ result["aws_subnet.#{module_name_of(subnet)}"] = {
+ "type" => "aws_subnet",
+ "primary" => {
+ "id" => subnet.subnet_id,
+ "attributes" => attributes
+ }
+ }
- result
+ result
+ end
+
+ generate_tfstate(resources)
end
- generate_tfstate(resources)
- end
+ private
- private
+ def subnets
+ @client.describe_subnets.subnets
+ end
- def subnets
- @client.describe_subnets.subnets
- end
-
- def module_name_of(subnet)
- normalize_module_name(name_from_tag(subnet, subnet.subnet_id))
+ def module_name_of(subnet)
+ normalize_module_name(name_from_tag(subnet, subnet.subnet_id))
+ end
end
end
end