lib/terraforming/resource/network_acl.rb in terraforming-0.0.5 vs lib/terraforming/resource/network_acl.rb in terraforming-0.1.0
- old
+ new
@@ -1,32 +1,33 @@
module Terraforming
module Resource
class NetworkACL
include Terraforming::Util
- def self.tf(client = Aws::EC2::Client.new)
+ 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
+ def self.tfstate(client: Aws::EC2::Client.new, tfstate_base: nil)
+ self.new(client).tfstate(tfstate_base)
end
def initialize(client)
@client = client
end
def tf
apply_template(@client, "tf/network_acl")
end
- def tfstate
+ def tfstate(tfstate_base)
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,
+ "subnet_ids.#" => subnet_ids_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",
@@ -37,11 +38,11 @@
}
result
end
- generate_tfstate(resources)
+ generate_tfstate(resources, tfstate_base)
end
private
def default_entry?(entry)
@@ -68,9 +69,13 @@
normalize_module_name(name_from_tag(network_acl, network_acl.network_acl_id))
end
def network_acls
@client.describe_network_acls.network_acls
+ end
+
+ def subnet_ids_of(network_acl)
+ network_acl.associations.map { |association| association.subnet_id }
end
def to_port_of(entry)
entry.port_range ? entry.port_range.to : 0
end