Sha256: 1fea32c6598cfc3e55cf63c3a83b4d630c94056d2fa831292fb9acdb65db64c2

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

module Terraforming
  module Resource
    class DBSecurityGroup
      include Terraforming::Util

      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 initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/db_security_group")
      end

      def tfstate
        db_security_groups.inject({}) do |resources, security_group|
          attributes = {
            "db_subnet_group_name" => security_group.db_security_group_name,
            "id" => security_group.db_security_group_name,
            "ingress.#" => ingresses_of(security_group).length.to_s,
            "name" => security_group.db_security_group_name,
          }
          resources["aws_db_security_group.#{module_name_of(security_group)}"] = {
            "type" => "aws_db_security_group",
            "primary" => {
              "id" => security_group.db_security_group_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def ingresses_of(security_group)
        security_group.ec2_security_groups + security_group.ip_ranges
      end

      def db_security_groups
        @client.describe_db_security_groups.db_security_groups.select { |sg| ingresses_of(sg).length > 0 }
      end

      def module_name_of(security_group)
        normalize_module_name(security_group.db_security_group_name)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
terraforming-0.9.1 lib/terraforming/resource/db_security_group.rb
terraforming-0.9.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.8.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.7.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.6.2 lib/terraforming/resource/db_security_group.rb
terraforming-0.6.1 lib/terraforming/resource/db_security_group.rb
terraforming-0.6.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.5.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.4.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.3.2 lib/terraforming/resource/db_security_group.rb
terraforming-0.3.1 lib/terraforming/resource/db_security_group.rb
terraforming-0.3.0 lib/terraforming/resource/db_security_group.rb
terraforming-0.2.0 lib/terraforming/resource/db_security_group.rb