Class: TerraformWrapper::Shared::Config
- Inherits:
-
Object
- Object
- TerraformWrapper::Shared::Config
- Includes:
- Logging
- Defined in:
- lib/terraform-wrapper/shared/config.rb
Constant Summary collapse
- @@config_exts =
[ "", ".yaml", ".yml" ]
Instance Attribute Summary collapse
-
#auths ⇒ Object
readonly
Returns the value of attribute auths.
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#initialize(code:, options:) ⇒ Config
constructor
A new instance of Config.
Methods included from Logging
configure_logger_for, logger_for
Constructor Details
#initialize(code:, options:) ⇒ Config
Returns a new instance of Config.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/terraform-wrapper/shared/config.rb', line 38 def initialize(code:, options:) logger.fatal("Configuration base path must be a string!") unless ["base"].kind_of?(String) logger.fatal("Configuration base path must not be blank!") if ["base"].strip.empty? @base = ["base"] logger.fatal("Configuration name must be a string!") unless ["name"].kind_of?(String) logger.fatal("Configuration name must not be blank!") if ["name"].strip.empty? @name = ["name"] logger.fatal("Configuration service name must be a string!") unless ["service"].kind_of?(String) logger.fatal("Configuration service name must not be blank!") if ["service"].strip.empty? @service = ["service"] logger.fatal("Configuration authenticator for Azure enabled must be a Boolean!") unless [ true, false ].include?(["auth-azure"]) auth_azure = ["auth-azure"] logger.fatal("Configuration authenticator for Azure options must be a Hash!") unless ["auth-azure-options"].kind_of?(Hash) = ["auth-azure-options"] logger.fatal("Configuration backend name must be a string!") unless ["backend"].kind_of?(String) logger.fatal("Configuration backend name must not be blank!") if ["backend"].strip.empty? backend = ["backend"] logger.fatal("Configuration backend options must be a Hash!") unless ["backend-options"].kind_of?(Hash) = ["backend-options"] @code = code @path = ::TerraformWrapper.find(base: @base, name: @name, exts: @@config_exts, description: "Configuration") yaml = YAML.load(File.read(@path)) logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash) identifiers = yaml.key?("identifiers") ? yaml["identifiers"] : Hash.new @variables = TerraformWrapper::Shared::Variables.new(config: @name, component: @code.name, service: @service, identifiers: identifiers) if yaml.key?("globals") then logger.fatal("Key 'globals' is not a hash in configuration file: #{@path}") unless yaml["globals"].kind_of?(Hash) globals = yaml["globals"] @variables.add_variables(variables: globals["variables"]) if globals.key?("variables") end if yaml.key?("terraform") then logger.fatal("Key 'terraform' is not a hash in configuration file: #{@path}") unless yaml["terraform"].kind_of?(Hash) terraform = yaml["terraform"] [ "globals", @code.name ].each do |extra| if terraform.key?(extra) then logger.fatal("Key '#{extra}' under 'terraform' is not a hash in configuration file: #{@path}") unless terraform[extra].kind_of?(Hash) section = terraform[extra] @variables.add_variables(variables: section["variables"]) if section.key?("variables") @variables.add_files(base: @base, files: section["files"]) if section.key?("files") end end end @auths = Array.new @auths.append(TerraformWrapper::Shared::Auths::Azure.new(options: , variables: @variables)) if auth_azure if backend == "local" then @backend = TerraformWrapper::Shared::Backends::Local.new(options: , variables: @variables) elsif backend == "aws" then @backend = TerraformWrapper::Shared::Backends::AWS.new(options: , variables: @variables) elsif backend == "azure" then @backend = TerraformWrapper::Shared::Backends::Azure.new(options: , variables: @variables) else logger.fatal("Backend: #{backend} is not valid!") end end |
Instance Attribute Details
#auths ⇒ Object (readonly)
Returns the value of attribute auths.
27 28 29 |
# File 'lib/terraform-wrapper/shared/config.rb', line 27 def auths @auths end |
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
28 29 30 |
# File 'lib/terraform-wrapper/shared/config.rb', line 28 def backend @backend end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
29 30 31 |
# File 'lib/terraform-wrapper/shared/config.rb', line 29 def base @base end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
30 31 32 |
# File 'lib/terraform-wrapper/shared/config.rb', line 30 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/terraform-wrapper/shared/config.rb', line 31 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
32 33 34 |
# File 'lib/terraform-wrapper/shared/config.rb', line 32 def path @path end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
33 34 35 |
# File 'lib/terraform-wrapper/shared/config.rb', line 33 def service @service end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
34 35 36 |
# File 'lib/terraform-wrapper/shared/config.rb', line 34 def variables @variables end |