Sha256: 1cd748e9e7c8c955ee2a6afae4118ab5a7fc29301534f4939c8954dec38511e0

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 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, tfstate_base: nil)
        self.new(client).tfstate(tfstate_base)
      end

      def initialize(client)
        @client = client
      end

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

      def tfstate(tfstate_base)
        resources = cache_subnet_groups.inject({}) do |result, 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,
          }
          result["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
            }
          }

          result
        end

        generate_tfstate(resources, tfstate_base)
      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

3 entries across 3 versions & 1 rubygems

Version Path
terraforming-0.1.3 lib/terraforming/resource/elasti_cache_subnet_group.rb
terraforming-0.1.2 lib/terraforming/resource/elasti_cache_subnet_group.rb
terraforming-0.1.1 lib/terraforming/resource/elasti_cache_subnet_group.rb