Class: CfndslConverger

Inherits:
Object
  • Object
show all
Defined in:
lib/cfndsl_converger.rb

Instance Method Summary collapse

Instance Method Details

#chain_converge(cfndsl_stacks:, input_bindings: nil) ⇒ Object



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

def chain_converge(cfndsl_stacks:,
                   input_bindings: nil)

  previous_output_bindings = input_bindings
  cfndsl_stacks.each do |cfndsl_stack|
    previous_output_bindings = converge stack_name: cfndsl_stack[:stack_name],
                                        path_to_stack: cfndsl_stack[:path_to_stack],
                                        bindings: previous_output_bindings.merge(input_bindings)
  end
  previous_output_bindings
end

#cleanup(cloudformation_stack_name) ⇒ Object

Delete the specified Cloudformation stack by name



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cfndsl_converger.rb', line 57

def cleanup(cloudformation_stack_name)
  resource = Aws::CloudFormation::Resource.new
  stack_to_delete = resource.stack(cloudformation_stack_name)

  stack_to_delete.delete
  begin
    stack_to_delete.wait_until(max_attempts:100, delay:15) do |stack|
      stack.stack_status.match /DELETE_COMPLETE/
    end
  rescue
    #squash any errors - when stack is gone, the waiter might freak
  end
end

#converge(stack_name:, path_to_stack:, bindings: nil, fail_on_changes_to_immutable_resource: false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cfndsl_converger.rb', line 20

def converge(stack_name:,
             path_to_stack:,
             bindings: nil,
             fail_on_changes_to_immutable_resource: false)
  extras = []
  unless bindings.nil?
    temp_file = Tempfile.new(['cfnstackfortesting', '.yml'])
    temp_file.write bindings.to_yaml
    temp_file.close

    extras << [:yaml,File.expand_path(temp_file)]
  end

  verbose = false
  model = CfnDsl::eval_file_with_extras(File.expand_path(path_to_stack),
                                        extras,
                                        verbose)

  if fail_on_changes_to_immutable_resource and stack_exists?(stack_name)
    unsafe_logical_resource_id = ChangesetUtil.new.immutable_resources_that_would_change stack_name: stack_name,
                                                                                         template_body: model.to_json
    if unsafe_logical_resource_id.nil?
      outputs = converge_stack stack_name: stack_name,
                               stack_body: model.to_json
    else
      raise "update would modify or delete immutable resource #{unsafe_logical_resource_id}"
    end
  else
    outputs = converge_stack stack_name: stack_name,
                             stack_body: model.to_json
  end
  outputs
end