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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/kitchen/driver/sparkleformation.rb', line 24
def create(state)
unless state[:stack_id].nil?
@stack_desc = @cf.describe_stacks(stack_name: state[:stack_id]).stacks.first
case @stack_desc.stack_status
when 'CREATE_IN_PROGRESS'
@cf.wait_until :stack_create_complete, stack_name: state[:stack_id]
when 'CREATE_COMPLETE'
else
raise "Invalid stack state: #{@stack_desc.stack_status}"
end
if state[:hostname].nil?
state[:hostname] = hostname(state[:stack_id])
end
return
end
@stack_name = config[:stack_name]
if config[:stack_name_random_suffix]
@stack_name << "-#{SecureRandom.hex(6)}"
end
json = generate_cloudformation_template
if config[:upload_template]
url = upload_template @stack_name, json
end
stack_options = {
stack_name: @stack_name,
parameters: config[:cf_params].map { |k, v| { parameter_key: SparkleFormation.camel(k), parameter_value: v } }
}
if config[:upload_template]
stack_options[:template_url] = url
else
stack_options[:template_body] = json.to_json
end
stack_options.merge! config[:cf_options]
info 'Triggering CloudFormation stack creation'
state[:stack_id] = @cf.create_stack(stack_options).stack_id
info "Waiting for stack #{state[:stack_id]} to reach state CREATE_COMPLETE..."
@cf.wait_until :stack_create_complete, stack_name: state[:stack_id]
info 'Stack creation finished'
state[:hostname] = hostname(state[:stack_id])
end
|