module CfnFlow

Constants

VERSION

Public Class Methods

cfn_client() click to toggle source

Aws Clients

# File lib/cfn_flow.rb, line 68
def cfn_client
  @cfn_client ||= Aws::CloudFormation::Client.new(region: config['region'] || ENV['AWS_REGION'])
end
cfn_resource() click to toggle source
# File lib/cfn_flow.rb, line 72
def cfn_resource
  # NB: increase default retry limit to avoid throttling errors iterating over stacks.
  # See https://github.com/aws/aws-sdk-ruby/issues/705
  @cfn_resource ||= Aws::CloudFormation::Resource.new(
    region: config['region'] || ENV['AWS_REGION'],
    retry_limit: 10
  )
end
clear!() click to toggle source

Clear aws sdk clients & config (for tests)

# File lib/cfn_flow.rb, line 82
def clear!
  @config = @cfn_client = @cfn_resource = nil
  CachedStack.stack_cache.clear
end
config() click to toggle source
# File lib/cfn_flow.rb, line 26
def config
  load_config unless config_loaded?
  @config
end
config_loaded?() click to toggle source
# File lib/cfn_flow.rb, line 22
def config_loaded?
  @config.is_a? Hash
end
config_path() click to toggle source

Configuration

# File lib/cfn_flow.rb, line 12
def config_path
  ENV['CFN_FLOW_CONFIG_PATH'] || 'cfn-flow.yml'
end
exit_on_failure=(value) click to toggle source
# File lib/cfn_flow.rb, line 97
def exit_on_failure=(value)
  @exit_on_failure = value
end
exit_on_failure?() click to toggle source

Exit with status code = 1 when raising a Thor::Error Override thor default

# File lib/cfn_flow.rb, line 89
def exit_on_failure?
  if instance_variable_defined?(:@exit_on_failure)
   @exit_on_failure
  else
    true
  end
end
load_config() click to toggle source
# File lib/cfn_flow.rb, line 16
def load_config
  @config = YAML.load(
    ERB.new( File.read(config_path) ).result(binding)
  )
end
service() click to toggle source
# File lib/cfn_flow.rb, line 31
def service
  unless config.key?('service')
    raise Thor::Error.new("No service name in #{config_path}. Add 'service: my_app_name'.")
  end
  config['service']
end
stack_params(environment) click to toggle source
# File lib/cfn_flow.rb, line 38
def stack_params(environment)
  unless config['stack'].is_a? Hash
    raise Thor::Error.new("No stack defined in #{config_path}. Add 'stack: ...'.")
  end
  params = StackParams.expanded(config['stack'])

  params.
    add_tag('CfnFlowService' => service).
    add_tag('CfnFlowEnvironment' => environment)
end
template_s3_bucket() click to toggle source
# File lib/cfn_flow.rb, line 49
def template_s3_bucket
  unless config['templates'].is_a?(Hash) &&  config['templates']['s3_bucket']
    raise Thor::Error.new("No s3_bucket defined for templates in #{config_path}. Add 'templates: { s3_bucket: ... }'.")
  end

  config['templates']['s3_bucket']
end
template_s3_prefix() click to toggle source
# File lib/cfn_flow.rb, line 57
def template_s3_prefix
  unless config['templates'].is_a?(Hash)
    raise Thor::Error.new("No templates defined in #{config_path}. Add 'templates: ... '.")
  end

  # Ok for this to be ''
  config['templates']['s3_prefix']
end