lib/terraforming/resource/security_group.rb in terraforming-0.0.1 vs lib/terraforming/resource/security_group.rb in terraforming-0.0.2
- old
+ new
@@ -1,56 +1,58 @@
-module Terraforming::Resource
- class SecurityGroup
- include Terraforming::Util
+module Terraforming
+ module Resource
+ class SecurityGroup
+ 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/security_group")
- end
+ def tf
+ apply_template(@client, "tf/security_group")
+ end
- def tfstate
- resources = security_groups.inject({}) do |result, security_group|
- attributes = {
- "description" => security_group.description,
- "egress.#" => security_group.ip_permissions_egress.length.to_s,
- "id" => security_group.group_id,
- "ingress.#" => security_group.ip_permissions.length.to_s,
- "name" => security_group.group_name,
- "owner_id" => security_group.owner_id,
- "vpc_id" => security_group.vpc_id || "",
- }
- result["aws_security_group.#{module_name_of(security_group)}"] = {
- "type" => "aws_security_group",
- "primary" => {
+ def tfstate
+ resources = security_groups.inject({}) do |result, security_group|
+ attributes = {
+ "description" => security_group.description,
+ "egress.#" => security_group.ip_permissions_egress.length.to_s,
"id" => security_group.group_id,
- "attributes" => attributes
+ "ingress.#" => security_group.ip_permissions.length.to_s,
+ "name" => security_group.group_name,
+ "owner_id" => security_group.owner_id,
+ "vpc_id" => security_group.vpc_id || "",
}
- }
+ result["aws_security_group.#{module_name_of(security_group)}"] = {
+ "type" => "aws_security_group",
+ "primary" => {
+ "id" => security_group.group_id,
+ "attributes" => attributes
+ }
+ }
- result
+ result
+ end
+
+ generate_tfstate(resources)
end
- generate_tfstate(resources)
- end
+ private
- private
+ def module_name_of(security_group)
+ normalize_module_name(security_group.group_name)
+ end
- def module_name_of(security_group)
- normalize_module_name(security_group.group_name)
- end
-
- def security_groups
- @client.describe_security_groups.security_groups
+ def security_groups
+ @client.describe_security_groups.security_groups
+ end
end
end
end