Module: CfnFlow

Defined in:
lib/cfn_flow.rb,
lib/cfn_flow/cli.rb,
lib/cfn_flow/version.rb,
lib/cfn_flow/template.rb,
lib/cfn_flow/cached_stack.rb,
lib/cfn_flow/stack_params.rb,
lib/cfn_flow/event_presenter.rb

Defined Under Namespace

Classes: CLI, CachedStack, EventPresenter, Git, StackParams, Template

Constant Summary collapse

VERSION =
'0.9.0'

Class Method Summary collapse

Class Method Details

.cfn_clientObject

Aws Clients



68
69
70
# File 'lib/cfn_flow.rb', line 68

def cfn_client
  @cfn_client ||= Aws::CloudFormation::Client.new(region: config['region'] || ENV['AWS_REGION'])
end

.cfn_resourceObject



72
73
74
75
76
77
78
79
# 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!Object

Clear aws sdk clients & config (for tests)



82
83
84
85
# File 'lib/cfn_flow.rb', line 82

def clear!
  @config = @cfn_client = @cfn_resource = nil
  CachedStack.stack_cache.clear
end

.configObject



26
27
28
29
# File 'lib/cfn_flow.rb', line 26

def config
  load_config unless config_loaded?
  @config
end

.config_loaded?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/cfn_flow.rb', line 22

def config_loaded?
  @config.is_a? Hash
end

.config_pathObject

Configuration



12
13
14
# File 'lib/cfn_flow.rb', line 12

def config_path
  ENV['CFN_FLOW_CONFIG_PATH'] || 'cfn-flow.yml'
end

.exit_on_failure=(value) ⇒ Object



97
98
99
# File 'lib/cfn_flow.rb', line 97

def exit_on_failure=(value)
  @exit_on_failure = value
end

.exit_on_failure?Boolean

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

Returns:

  • (Boolean)


89
90
91
92
93
94
95
# 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_configObject



16
17
18
19
20
# File 'lib/cfn_flow.rb', line 16

def load_config
  @config = YAML.load(
    ERB.new( File.read(config_path) ).result(binding)
  )
end

.serviceObject



31
32
33
34
35
36
# 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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# 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_bucketObject



49
50
51
52
53
54
55
# 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_prefixObject



57
58
59
60
61
62
63
64
# 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