Sha256: 6db08e58e929d36ada0322937d164a9b5736618303381a9cd1b211960779bb1b

Contents?: true

Size: 1.79 KB

Versions: 115

Compression:

Stored size: 1.79 KB

Contents

module Awspec::Type
  class Elasticache < ResourceBase
    def initialize(name)
      super
      @display_name = name
    end

    def resource_via_client
      @resource_via_client ||= find_cache_cluster(@display_name)
    end

    def id
      @id ||= resource_via_client.cache_cluster_id if resource_via_client
    end

    STATES = %w(
      available creating deleted deleting
      incompatible-network modifying
      rebooting-cache-cluster-nodes restore-failed
      snapshotting
    )

    STATES.each do |state|
      define_method state.tr('-', '_') + '?' do
        resource_via_client.cache_cluster_status == state
      end
    end

    def has_cache_parameter_group?(group_name)
      resource_via_client.cache_parameter_group.cache_parameter_group_name == group_name
    end

    def has_security_group?(sg_id)
      return true if has_vpc_security_group_id?(sg_id)
      return true if has_vpc_security_group_name?(sg_id)
      return true if has_vpc_security_group_tag_name?(sg_id)
    end

    def vpc_id
      cache_subnet_group = find_cache_subnet_group(resource_via_client.cache_subnet_group_name)
      cache_subnet_group.vpc_id if cache_subnet_group
    end

    private

    def has_vpc_security_group_id?(sg_id)
      resource_security_group_ids.include?(sg_id)
    end

    def has_vpc_security_group_name?(sg_id)
      res = select_security_group_by_group_name([sg_id])

      return false unless res.count == 1
      has_vpc_security_group_id?(res.first.group_id)
    end

    def has_vpc_security_group_tag_name?(sg_id)
      res = select_security_group_by_tag_name([sg_id])

      return false unless res.count == 1
      has_vpc_security_group_id?(res.first.group_id)
    end

    def resource_security_group_ids
      resource_via_client.security_groups.map(&:security_group_id)
    end
  end
end

Version data entries

115 entries across 115 versions & 4 rubygems

Version Path
awspec-1.25.1 lib/awspec/type/elasticache.rb
awspec-1.25.0 lib/awspec/type/elasticache.rb
awspec-1.24.4 lib/awspec/type/elasticache.rb
awspec-1.24.3 lib/awspec/type/elasticache.rb
awspec-1.24.2 lib/awspec/type/elasticache.rb
awspec-1.24.1 lib/awspec/type/elasticache.rb
awspec-1.24.0 lib/awspec/type/elasticache.rb
awspec-1.23.0 lib/awspec/type/elasticache.rb
awspec-1.22.1 lib/awspec/type/elasticache.rb
awspec-1.22.0 lib/awspec/type/elasticache.rb
awspec-1.21.1 lib/awspec/type/elasticache.rb
awspec-1.21.0 lib/awspec/type/elasticache.rb
awspec-1.20.0 lib/awspec/type/elasticache.rb
awspec-1.19.2 lib/awspec/type/elasticache.rb
awspec-1.19.1 lib/awspec/type/elasticache.rb
awspec-1.19.0 lib/awspec/type/elasticache.rb
cthiesfork-awspec-1.2.4 lib/awspec/type/elasticache.rb
awspec-api_gateway_extended-1.2.4 lib/awspec/type/elasticache.rb
awspec-api_gateway_extended-1.2.3 lib/awspec/type/elasticache.rb
awspec-1.18.6 lib/awspec/type/elasticache.rb