Sha256: 3c8e78a5010bfe555863e53d5e5009ca55c9f5afed711877a1e940def2d2bade

Contents?: true

Size: 1.4 KB

Versions: 16

Compression:

Stored size: 1.4 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.cache_subnet_groups
      end

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

Version data entries

16 entries across 16 versions & 1 rubygems

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