Class: CfnDslPipeline::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/params.rb,
lib/exec_cfndsl.rb,
lib/exec_syntax.rb,
lib/exec_cfn_nag.rb,
lib/cfndsl-pipeline.rb

Overview

Main pipeline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_dir, options) ⇒ Pipeline

Returns a new instance of Pipeline.



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

def initialize
  self.s3_client = Aws::S3::Client.new(region: aws_region)
end

Instance Attribute Details

#base_nameObject

Returns the value of attribute base_name.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def base_name
  @base_name
end

#input_filenameObject

Returns the value of attribute input_filename.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def input_filename
  @input_filename
end

#optionsObject

Returns the value of attribute options.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def options
  @options
end

#output_dirObject

Returns the value of attribute output_dir.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def output_dir
  @output_dir
end

#output_fileObject

Returns the value of attribute output_file.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def output_file
  @output_file
end

#output_filenameObject

Returns the value of attribute output_filename.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def output_filename
  @output_filename
end

#s3_clientObject

Returns the value of attribute s3_client.



10
11
12
# File 'lib/exec_syntax.rb', line 10

def s3_client
  @s3_client
end

#syntax_reportObject

Returns the value of attribute syntax_report.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def syntax_report
  @syntax_report
end

#templateObject

Returns the value of attribute template.



42
43
44
# File 'lib/cfndsl-pipeline.rb', line 42

def template
  @template
end

Instance Method Details

#build(input_filename, cfndsl_extras) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/cfndsl-pipeline.rb', line 55

def build(input_filename, cfndsl_extras)
  abort "Input file #{input_filename} doesn't exist!" unless File.file?(input_filename)
  self.input_filename = input_filename.to_s
  self.base_name = File.basename(input_filename, '.*')
  self.output_filename = File.expand_path("#{output_dir}/#{base_name}.yaml")
  exec_cfndsl cfndsl_extras
  exec_syntax_validation if options.validate_syntax
  exec_dump_params if options.dump_deploy_params
  exec_cfn_nag if options.validate_cfn_nag
end

#exec_cfn_nagObject



10
11
12
13
14
15
16
17
18
# File 'lib/exec_cfn_nag.rb', line 10

def exec_cfn_nag
  puts 'Auditing template with cfn-nag...'
  configure_cfn_nag_logging
  cfn_nag = CfnNag.new(config: options.cfn_nag)
  result = cfn_nag.audit(cloudformation_string: template)
  save_report result
  display_report result
  show_summary result
end

#exec_cfndsl(cfndsl_extras) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/exec_cfndsl.rb', line 10

def exec_cfndsl(cfndsl_extras)
  puts 'Generating CloudFormation template...'

  model = CfnDsl.eval_file_with_extras(@input_filename.to_s, cfndsl_extras, (options.debug_cfndsl ? STDOUT : nil))
  @template = JSON.parse(model.to_json).to_yaml
  File.open(@output_filename, 'w') do |file|
    file.puts @template
  end
  @output_file = File.open(@output_filename)
  puts "#{@output_file.size} bytes written to #{@output_filename}"
end

#exec_dump_paramsObject



8
9
10
11
12
13
14
15
# File 'lib/params.rb', line 8

def exec_dump_params
  param_filename = "#{output_dir}/#{base_name}.params"
  puts "Deploy parameters written to #{param_filename}"
  param_file = File.open(File.expand_path(param_filename), 'w')
  syntax_report['parameters'].each do |param|
    param_file.puts "#{param['parameter_key']}=#{param['default_value']}"
  end
end

#exec_syntax_validationObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/exec_syntax.rb', line 16

def exec_syntax_validation
  puts 'Validating template syntax...'
  if options.estimate_cost || (output_file.size > 51_200)
    puts 'Filesize is greater than 51200, or cost estimation required. Validating via S3 bucket '
    uuid = UUID.new
    bucket = determine_bucket
    object_name = uuid.generate.to_s
    upload_template(bucket, object_name)
    self.syntax_report = s3_validate_syntax(bucket, object_name)
    estimate_cost(bucket_name, object_name)
    unless options.validation_bucket
      puts 'Deleting temporary S3 bucket...'
      bucket.delete!
    end
  else
    self.syntax_report = local_validate_syntax
  end
  save_syntax_report
end