Sha256: 95778d300234b553b2688c34978918676ab70c901753334816299c35039faaba

Contents?: true

Size: 1.67 KB

Versions: 28

Compression:

Stored size: 1.67 KB

Contents

module Lono::AwsServices
  module Util
    def stack_exists?(stack_name)
      return true if testing_update?
      return false if @options[:noop]

      exist = nil
      begin
        # When the stack does not exist an exception is raised. Example:
        # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
        cfn.describe_stacks(stack_name: stack_name)
        exist = true
      rescue Aws::CloudFormation::Errors::ValidationError => e
        if e.message =~ /does not exist/
          exist = false
        elsif e.message.include?("'stackName' failed to satisfy constraint")
          # Example of e.message when describe_stack with invalid stack name
          # "1 validation error detected: Value 'instance_and_route53' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*"
          puts "Invalid stack name: #{stack_name}"
          puts "Full error message: #{e.message}"
          exit 1
        else
          raise # re-raise exception  because unsure what other errors can happen
        end
      end
      exist
    end

    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 rollback_complete?(stack)
      stack&.stack_status == 'ROLLBACK_COMPLETE'
    end

    def testing_update?
      ENV['TEST'] && self.class.name == "LonoCfn::Update"
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lono-6.1.11 lib/lono/aws_services/util.rb
lono-6.1.10 lib/lono/aws_services/util.rb
lono-6.1.9 lib/lono/aws_services/util.rb
lono-6.1.8 lib/lono/aws_services/util.rb
lono-6.1.7 lib/lono/aws_services/util.rb
lono-6.1.6 lib/lono/aws_services/util.rb
lono-6.1.5 lib/lono/aws_services/util.rb
lono-6.1.4 lib/lono/aws_services/util.rb
lono-6.1.3 lib/lono/aws_services/util.rb
lono-6.1.2 lib/lono/aws_services/util.rb
lono-6.1.1 lib/lono/aws_services/util.rb
lono-6.1.0 lib/lono/aws_services/util.rb
lono-6.0.1 lib/lono/aws_services/util.rb
lono-6.0.0 lib/lono/aws_services/util.rb
lono-5.3.4 lib/lono/aws_services/util.rb
lono-5.3.3 lib/lono/aws_services/util.rb
lono-5.3.2 lib/lono/aws_services/util.rb
lono-5.3.1 lib/lono/aws_services/util.rb
lono-5.3.0 lib/lono/aws_services/util.rb
lono-5.2.8 lib/lono/aws_services/util.rb