Class: Cfer::Auster::Step
- Inherits:
-
Object
- Object
- Cfer::Auster::Step
- Includes:
- Logging::Mixin
- Defined in:
- lib/cfer/auster/step.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #apply(config_set) ⇒ Object
- #cfn_data(config_set) ⇒ Object
- #cfn_stack(config_set) ⇒ Object
- #cfn_stack_name(config_set) ⇒ Object
- #destroy(config_set) ⇒ Object
-
#initialize(repo:, count:, tag:, directory:) ⇒ Step
constructor
A new instance of Step.
- #json(config_set) ⇒ Object
Methods included from Logging::Mixin
Constructor Details
#initialize(repo:, count:, tag:, directory:) ⇒ Step
Returns a new instance of Step.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cfer/auster/step.rb', line 16 def initialize(repo:, count:, tag:, directory:) raise "directory '#{directory}' does not exist." unless File.directory?(directory) @repo = repo @count = count.to_i @tag = tag.dup.freeze @directory = directory.dup.freeze @cfer_directory = File.join(@directory, "cfer") raise "directory '#{@cfer_directory}' does not exist." unless File.directory?(directory) end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
12 13 14 |
# File 'lib/cfer/auster/step.rb', line 12 def count @count end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
14 15 16 |
# File 'lib/cfer/auster/step.rb', line 14 def directory @directory end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
10 11 12 |
# File 'lib/cfer/auster/step.rb', line 10 def repo @repo end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
13 14 15 |
# File 'lib/cfer/auster/step.rb', line 13 def tag @tag end |
Instance Method Details
#apply(config_set) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cfer/auster/step.rb', line 65 def apply(config_set) raise "config_set must be a Cfer::Auster::Config." unless config_set.is_a?(Cfer::Auster::Config) with_cfer(config_set) do |cfer| do_on_create(config_set) unless cfn_stack(config_set).exists? do_pre_converge(config_set) logger.info "Converging Cfer stack as '#{cfn_stack_name(config_set)}'." cfer.converge!(block: true) do_post_converge(config_set, cfn_data(config_set)) end end |
#cfn_data(config_set) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cfer/auster/step.rb', line 46 def cfn_data(config_set) stack = cfn_stack(config_set) if !stack.exists? nil else cfn_parameters = stack.parameters.map { |p| [p.parameter_key, p.parameter_value] }.to_h cfn_outputs = stack.outputs.map { |o| [o.output_key, o.output_value] }.to_h cfn_combined = cfn_parameters.merge(cfn_outputs) { inputs: cfn_parameters.symbolize_keys, outputs: cfn_outputs.symbolize_keys, combined: cfn_combined.symbolize_keys } end end |
#cfn_stack(config_set) ⇒ Object
41 42 43 44 |
# File 'lib/cfer/auster/step.rb', line 41 def cfn_stack(config_set) cfn_client = Aws::CloudFormation::Resource.new(region: config_set.aws_region) cfn_client.stack(cfn_stack_name(config_set)) end |
#cfn_stack_name(config_set) ⇒ Object
37 38 39 |
# File 'lib/cfer/auster/step.rb', line 37 def cfn_stack_name(config_set) "#{config_set.name}-step#{count.to_s.rjust(2, '0')}" end |
#destroy(config_set) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cfer/auster/step.rb', line 79 def destroy(config_set) raise "config_set must be a Cfer::Auster::Config." unless config_set.is_a?(Cfer::Auster::Config) stack_name = cfn_stack_name(config_set) stack = cfn_stack(config_set) if !stack.exists? logger.warn "No underlying CloudFormation stack '#{stack_name}' exists." else logger.info "Deleting CloudFormation stack '#{stack_name}'." with_cfer(config_set) do |cfer| cfer.destroy!(block: true) end do_on_destroy(config_set) end end |