Sha256: 775ddb6cab473e72d9f5c3b0e400740d1079f442c27ebfbe5aab6e3fd5d8d9eb

Contents?: true

Size: 1.46 KB

Versions: 20

Compression:

Stored size: 1.46 KB

Contents

require "cfn_status"

module Ufo::AwsServices
  module Concerns
    extend Memoist

    def find_stack(stack_name)
      resp = cfn.describe_stacks(stack_name: stack_name)
      resp.stacks.first
    rescue Aws::CloudFormation::Errors::ValidationError => e
      # example: Stack with id demo-web does not exist
      if e.message =~ /Stack with/ && e.message =~ /does not exist/
        nil
      else
        raise
      end
    end

    def stack_resources(stack_name)
      resp = cfn.describe_stack_resources(stack_name: stack_name)
      resp.stack_resources
    rescue Aws::CloudFormation::Errors::ValidationError => e
      e.message.include?("does not exist") ? return : raise
    end

    def task_definition_arns(family, max_items=10)
      resp = ecs.list_task_definitions(
        family_prefix: family,
        sort: "DESC",
      )
      arns = resp.task_definition_arns
      arns = arns.select do |arn|
        task_definition = arn.split('/').last.split(':').first
        task_definition == family
      end
      arns[0..max_items]
    end

    def status
      CfnStatus.new(@stack_name) # NOTE: @stack_name must be set in the including Class
    end
    memoize :status

    def find_stack_resources(stack_name)
      resp = cfn.describe_stack_resources(stack_name: stack_name)
      resp.stack_resources
    rescue Aws::CloudFormation::Errors::ValidationError => e
      if e.message.include?("does not exist")
        nil
      else
        raise
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ufo-6.3.13 lib/ufo/aws_services/concerns.rb
ufo-6.3.12 lib/ufo/aws_services/concerns.rb
ufo-6.3.11 lib/ufo/aws_services/concerns.rb
ufo-6.3.10 lib/ufo/aws_services/concerns.rb
ufo-6.3.9 lib/ufo/aws_services/concerns.rb
ufo-6.3.8 lib/ufo/aws_services/concerns.rb
ufo-6.3.7 lib/ufo/aws_services/concerns.rb
ufo-6.3.6 lib/ufo/aws_services/concerns.rb
ufo-6.3.5 lib/ufo/aws_services/concerns.rb
ufo-6.3.4 lib/ufo/aws_services/concerns.rb
ufo-6.3.3 lib/ufo/aws_services/concerns.rb
ufo-6.3.2 lib/ufo/aws_services/concerns.rb
ufo-6.3.1 lib/ufo/aws_services/concerns.rb
ufo-6.3.0 lib/ufo/aws_services/concerns.rb
ufo-6.2.5 lib/ufo/aws_services/concerns.rb
ufo-6.2.4 lib/ufo/aws_services/concerns.rb
ufo-6.2.3 lib/ufo/aws_services/concerns.rb
ufo-6.2.2 lib/ufo/aws_services/concerns.rb
ufo-6.2.1 lib/ufo/aws_services/concerns.rb
ufo-6.2.0 lib/ufo/aws_services/concerns.rb