Class: EbDeployer::CloudFormationProvisioner

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

Constant Summary collapse

SUCCESS_STATS =
["CREATE_COMPLETE", "UPDATE_COMPLETE"]
FAILED_STATS =
["CREATE_FAILED", "UPDATE_FAILED", "UPDATE_ROLLBACK_COMPLETE"]

Instance Method Summary collapse

Constructor Details

#initialize(stack_name, cf_driver) ⇒ CloudFormationProvisioner

Returns a new instance of CloudFormationProvisioner.



9
10
11
12
13
# File 'lib/eb_deployer/cloud_formation_provisioner.rb', line 9

def initialize(stack_name, cf_driver)
  @stack_name = stack_name
  @cf_driver = cf_driver
  @poller = EventPoller.new(CfEventSource.new(@stack_name, @cf_driver))
end

Instance Method Details

#output(key) ⇒ Object



49
50
51
52
53
# File 'lib/eb_deployer/cloud_formation_provisioner.rb', line 49

def output(key)
  @cf_driver.query_output(@stack_name, key)
rescue Aws::CloudFormation::Errors::ValidationError
  raise ResourceNotInReadyState.new("Resource stack not in ready state yet, perhaps you should provision it first?")
end

#provision(resources) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/eb_deployer/cloud_formation_provisioner.rb', line 15

def provision(resources)
  resources = symbolize_keys(resources)
  template = File.read(resources[:template])
  capabilities = resources[:capabilities] || []
  params = resources[:inputs] || resources[:parameters] || {}
  policy = File.read(resources[:policy]) if resources[:policy]
  override_policy = resources[:override_policy] || false
  anchor = nil
  begin
    if stack_exists?
      anchor = @poller.get_anchor
      update_stack(template, params, capabilities, policy, override_policy)
    else
      create_stack(template, params, capabilities, policy)
    end
  rescue Aws::CloudFormation::Errors::ValidationError => e
    if e.message =~ /No updates are to be performed/
      log(e.message)
      return
    else
      raise
    end
  end
  wait_for_stack_op_terminate(anchor)
  log("Resource stack provisioned successfully")
end

#transform_outputs(resources) ⇒ Object



42
43
44
45
46
47
# File 'lib/eb_deployer/cloud_formation_provisioner.rb', line 42

def transform_outputs(resources)
  resources = symbolize_keys(resources)
  outputs = resources[:outputs] || {}
  transforms = resources[:transforms] || {}
  transform_output_to_settings(convert_to_transforms(outputs).merge(transforms))
end