Sha256: c44b91161aba52ec8b0a925b5a29f271d11532551e0dbe73217e965a36224364

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

module Terraforming
  module Resource
    class DBSubnetGroup
      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_subnet_group")
      end

      def tfstate
        resources = db_subnet_groups.inject({}) do |result, subnet_group|
          attributes = {
            "description" => subnet_group.db_subnet_group_description,
            "name" => subnet_group.db_subnet_group_name,
            "subnet_ids.#" => subnet_group.subnets.length.to_s
          }
          result["aws_db_subnet_group.#{module_name_of(subnet_group)}"] = {
            "type" => "aws_db_subnet_group",
            "primary" => {
              "id" => subnet_group.db_subnet_group_name,
              "attributes" => attributes
            }
          }

          result
        end

        generate_tfstate(resources)
      end

      private

      def db_subnet_groups
        @client.describe_db_subnet_groups.db_subnet_groups
      end

      def module_name_of(subnet_group)
        normalize_module_name(subnet_group.db_subnet_group_name)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
terraforming-0.0.5 lib/terraforming/resource/db_subnet_group.rb
terraforming-0.0.4 lib/terraforming/resource/db_subnet_group.rb
terraforming-0.0.3 lib/terraforming/resource/db_subnet_group.rb
terraforming-0.0.2 lib/terraforming/resource/db_subnet_group.rb