Sha256: f9b22cb5118db1567fe3d25b14d09134933cf67c4cb30bce6ffbb6751361343b

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

module Terraforming
  module Resource
    class NetworkACL
      include Terraforming::Util

      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 initialize(client)
        @client = client
      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" => {
              "id" => network_acl.network_acl_id,
              "attributes" => attributes
            }
          }

          result
        end

        generate_tfstate(resources)
      end

      private

      def egresses_of(network_acl)
        network_acl.entries.select { |entry| entry.egress }
      end

      def from_port_of(entry)
        entry.port_range ? entry.port_range.from : 0
      end

      def ingresses_of(network_acl)
        network_acl.entries.select { |entry| !entry.egress }
      end

      def module_name_of(network_acl)
        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 to_port_of(entry)
        entry.port_range ? entry.port_range.to : 65535
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraforming-0.0.2 lib/terraforming/resource/network_acl.rb