Sha256: 88643c908cb019598d617ca0124853671d150c59fe4d8f29c0b9c1f847fec9d8

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

module Terraforming
  module Resource
    class ElastiCacheSubnetGroup
      include Terraforming::Util

      def self.tf(client: Aws::ElastiCache::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::ElastiCache::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

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

      def tfstate
        cache_subnet_groups.inject({}) do |resources, cache_subnet_group|
          attributes = {
            "description" => cache_subnet_group.cache_subnet_group_description,
            "name" => cache_subnet_group.cache_subnet_group_name,
            "subnet_ids.#" => subnet_ids_of(cache_subnet_group).length.to_s,
          }
          resources["aws_elasticache_subnet_group.#{cache_subnet_group.cache_subnet_group_name}"] = {
            "type" => "aws_elasticache_subnet_group",
            "primary" => {
              "id" => cache_subnet_group.cache_subnet_group_name,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def cache_subnet_groups
        @client.describe_cache_subnet_groups.map(&:cache_subnet_groups).flatten
      end

      def subnet_ids_of(cache_subnet_group)
        cache_subnet_group.subnets.map { |sn| sn.subnet_identifier }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
terraforming-0.12.0 lib/terraforming/resource/elasti_cache_subnet_group.rb
terraforming-0.11.0 lib/terraforming/resource/elasti_cache_subnet_group.rb
terraforming-0.10.0 lib/terraforming/resource/elasti_cache_subnet_group.rb