Class: YleTf::BackendConfig
- Inherits:
-
Object
- Object
- YleTf::BackendConfig
- Defined in:
- lib/yle_tf/backend_config.rb
Direct Known Subclasses
Constant Summary collapse
- BACKEND_CONFIG_FILE =
'_backend.tf.json'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#cli_args ⇒ Object
Returns an ‘Array` of CLI args for Terraform pre 0.9 `init` command.
-
#generate_config ⇒ Object
Generate backend configuration file for Terraform v0.9+.
-
#initialize(type, config) ⇒ BackendConfig
constructor
A new instance of BackendConfig.
-
#to_h ⇒ Object
(also: #to_s)
Returns the backend configuration as a ‘Hash` for Terraform v0.9+.
Constructor Details
#initialize(type, config) ⇒ BackendConfig
Returns a new instance of BackendConfig.
9 10 11 12 |
# File 'lib/yle_tf/backend_config.rb', line 9 def initialize(type, config) @type = type @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/yle_tf/backend_config.rb', line 7 def config @config end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/yle_tf/backend_config.rb', line 7 def type @type end |
Instance Method Details
#cli_args ⇒ Object
Returns an ‘Array` of CLI args for Terraform pre 0.9 `init` command
15 16 17 18 19 20 21 |
# File 'lib/yle_tf/backend_config.rb', line 15 def cli_args args = ["-backend=#{type}"] config.each do |key, value| args << "-backend-config=#{key}=#{value}" end args end |
#generate_config ⇒ Object
Generate backend configuration file for Terraform v0.9+
24 25 26 27 28 29 30 31 32 |
# File 'lib/yle_tf/backend_config.rb', line 24 def generate_config data = { terraform: [{ backend: [to_h] }] } File.write(BACKEND_CONFIG_FILE, JSON.pretty_generate(data)) yield if block_given? end |
#to_h ⇒ Object Also known as: to_s
Returns the backend configuration as a ‘Hash` for Terraform v0.9+
35 36 37 |
# File 'lib/yle_tf/backend_config.rb', line 35 def to_h { type => config } end |