Class: ActiveAws::CloudFormationProvisioner
- Defined in:
- lib/active_aws/cloud_formation_provisioner.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Class Method Summary collapse
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(name, template_path, parameters = {}) ⇒ CloudFormationProvisioner
constructor
A new instance of CloudFormationProvisioner.
- #normalized_name ⇒ Object
- #normalized_parameters ⇒ Object
- #save! ⇒ Object
- #template_body ⇒ Object
- #to_h ⇒ Object
-
#wait_until(waiter_name, &block) ⇒ Object
‘waiter_name` can be checked with the command below.
Methods inherited from Base
configure, inherited, load_config!
Constructor Details
#initialize(name, template_path, parameters = {}) ⇒ CloudFormationProvisioner
Returns a new instance of CloudFormationProvisioner.
16 17 18 19 20 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 16 def initialize( name, template_path, parameters={} ) @name = name @template_path = template_path @parameters = parameters end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 4 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
4 5 6 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 4 def parameters @parameters end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
4 5 6 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 4 def template_path @template_path end |
Class Method Details
.client ⇒ Object
7 8 9 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 7 def client Aws::CloudFormation::Client.new( **configure.default_client_params ) end |
.find(stack_name) ⇒ Object
11 12 13 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 11 def find( stack_name ) response = client.describe_stacks( stack_name: stack_name ) end |
Instance Method Details
#exists? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 50 def exists? res = self.class.client.describe_stacks( stack_name: normalized_name ) return res.stacks.length > 0 rescue => e return false end |
#normalized_name ⇒ Object
26 27 28 29 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 26 def normalized_name # self.class.configure.cfn_stack_name_prefix + name name end |
#normalized_parameters ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 31 def normalized_parameters parameters.map do |k,v| { parameter_key: k, parameter_value: v, } end end |
#save! ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 57 def save! response = if exists? self.class.client.update_stack( self.to_h ) else self.class.client.create_stack( self.to_h ) end end |
#template_body ⇒ Object
22 23 24 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 22 def template_body @template_body ||= File.read( template_path ) end |
#to_h ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 40 def to_h { stack_name: normalized_name, template_body: template_body, parameters: normalized_parameters, capabilities: ["CAPABILITY_IAM"], # on_failure: "DELETE", } end |
#wait_until(waiter_name, &block) ⇒ Object
‘waiter_name` can be checked with the command below. ActiveAws::CloudFormationProvisioner.client.waiter_names
Usage: prov.wait_until :instance_running do |i|
i.max_attempts = 5
i.delay = 5
end
73 74 75 |
# File 'lib/active_aws/cloud_formation_provisioner.rb', line 73 def wait_until( waiter_name, &block ) self.class.client.wait_until(waiter_name, stack_name: normalized_name, &block) end |