Class: Cloudspin::Stack::InstanceConfiguration
- Inherits:
-
Object
- Object
- Cloudspin::Stack::InstanceConfiguration
- Defined in:
- lib/cloudspin/stack/instance_configuration.rb
Instance Attribute Summary collapse
-
#backend_configuration ⇒ Object
readonly
Returns the value of attribute backend_configuration.
-
#base_folder ⇒ Object
readonly
Returns the value of attribute base_folder.
-
#instance_identifier ⇒ Object
readonly
Returns the value of attribute instance_identifier.
-
#instance_values ⇒ Object
readonly
Returns the value of attribute instance_values.
-
#parameter_values ⇒ Object
readonly
Returns the value of attribute parameter_values.
-
#resource_values ⇒ Object
readonly
Returns the value of attribute resource_values.
-
#stack_definition ⇒ Object
readonly
Returns the value of attribute stack_definition.
-
#stack_name ⇒ Object
readonly
Returns the value of attribute stack_name.
-
#stack_values ⇒ Object
readonly
Returns the value of attribute stack_values.
Class Method Summary collapse
- .from_files(*configuration_files, stack_definition:, base_folder: '.') ⇒ Object
- .load_configuration_values(configuration_files) ⇒ Object
- .yaml_file_to_hash(yaml_file) ⇒ Object
Instance Method Summary collapse
- #has_local_state_configuration? ⇒ Boolean
- #has_remote_state_configuration? ⇒ Boolean
- #init_instance_identifier ⇒ Object
-
#initialize(configuration_values: {}, stack_definition:, base_folder: '.') ⇒ InstanceConfiguration
constructor
A new instance of InstanceConfiguration.
- #to_s ⇒ Object
Constructor Details
#initialize(configuration_values: {}, stack_definition:, base_folder: '.') ⇒ InstanceConfiguration
Returns a new instance of InstanceConfiguration.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 20 def initialize( configuration_values: {}, stack_definition:, base_folder: '.' ) # puts "DEBUG: InstanceConfiguration configuration_values: #{configuration_values}" @stack_definition = stack_definition @base_folder = Pathname.new(base_folder).realdirpath.to_s @stack_values = configuration_values['stack'] || {} @instance_values = configuration_values['instance'] || {} @parameter_values = configuration_values['parameters'] || {} @resource_values = configuration_values['resources'] || {} @stack_name = @stack_values['name'] || stack_definition.name init_instance_identifier @backend_configuration = BackendConfiguration.new( terraform_backend_configuration_values: configuration_values['terraform_backend'] || {}, instance_identifier: instance_identifier, stack_name: stack_name, base_folder: @base_folder ) end |
Instance Attribute Details
#backend_configuration ⇒ Object (readonly)
Returns the value of attribute backend_configuration.
18 19 20 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 18 def backend_configuration @backend_configuration end |
#base_folder ⇒ Object (readonly)
Returns the value of attribute base_folder.
9 10 11 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 9 def base_folder @base_folder end |
#instance_identifier ⇒ Object (readonly)
Returns the value of attribute instance_identifier.
17 18 19 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 17 def instance_identifier @instance_identifier end |
#instance_values ⇒ Object (readonly)
Returns the value of attribute instance_values.
11 12 13 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 11 def instance_values @instance_values end |
#parameter_values ⇒ Object (readonly)
Returns the value of attribute parameter_values.
12 13 14 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 12 def parameter_values @parameter_values end |
#resource_values ⇒ Object (readonly)
Returns the value of attribute resource_values.
13 14 15 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 13 def resource_values @resource_values end |
#stack_definition ⇒ Object (readonly)
Returns the value of attribute stack_definition.
8 9 10 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 8 def stack_definition @stack_definition end |
#stack_name ⇒ Object (readonly)
Returns the value of attribute stack_name.
16 17 18 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 16 def stack_name @stack_name end |
#stack_values ⇒ Object (readonly)
Returns the value of attribute stack_values.
14 15 16 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 14 def stack_values @stack_values end |
Class Method Details
.from_files(*configuration_files, stack_definition:, base_folder: '.') ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 52 def self.from_files( *configuration_files, stack_definition:, base_folder: '.' ) configuration_values = load_configuration_values(configuration_files) self.new( stack_definition: stack_definition, base_folder: base_folder, configuration_values: configuration_values ) end |
.load_configuration_values(configuration_files) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 65 def self.load_configuration_values(configuration_files) configuration_values = {} configuration_files.flatten.each { |config_file| # puts "DEBUG: Reading configuration file: #{config_file}" configuration_values = configuration_values.deep_merge(yaml_file_to_hash(config_file)) } configuration_values end |
.yaml_file_to_hash(yaml_file) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 74 def self.yaml_file_to_hash(yaml_file) if File.exists?(yaml_file) YAML.load_file(yaml_file) || {} else puts "WARNING: No configuration file: #{yaml_file}" {} end end |
Instance Method Details
#has_local_state_configuration? ⇒ Boolean
83 84 85 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 83 def has_local_state_configuration? ! @backend_configuration.remote_state? end |
#has_remote_state_configuration? ⇒ Boolean
87 88 89 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 87 def has_remote_state_configuration? @backend_configuration.remote_state? end |
#init_instance_identifier ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 42 def init_instance_identifier @instance_identifier = if @instance_values['identifier'] @instance_values['identifier'] elsif @instance_values['group'] @stack_name + '-' + @instance_values['group'] else @stack_name end end |
#to_s ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/cloudspin/stack/instance_configuration.rb', line 91 def to_s { 'instance_identifier' => instance_identifier, 'instance' => instance_values, 'parameters' => parameter_values, 'resources' => resource_values, 'backend_configuration' => backend_configuration }.to_s end |