class YleTf::Action::WriteTerraformrcDefaults
Constants
- DEFAULT_PLUGIN_CACHE_PATH
Path of the plugin cache directory
- RC_PATH
Path of the Terraform
CLI
configuration file
Public Class Methods
new(app)
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 17 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 21 def call(env) if rc_file.exist? Logger.debug("Terraform configuration file '#{RC_PATH}' already exists") if !existing_keys.include?('plugin_cache_dir') Logger.warn("'plugin_cache_dir' not configured in '#{RC_PATH}'") end else Logger.debug("Writing default configuration to '#{RC_PATH}'") write_default_config end @app.call(env) end
configure_checkpoint(file)
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 55 def configure_checkpoint(file) Logger.info("Disabling Terraform upgrade and security bulletin checks by '#{RC_PATH}'") file.puts('disable_checkpoint = true') end
configure_plugin_cache_dir(file)
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 61 def configure_plugin_cache_dir(file) Logger.info("Configuring global Terraform plugin cache by '#{RC_PATH}'") # Replace `~` with `$HOME` as it is not expanded correctly in all architectures. # Can't use `$HOME` in the constant though, as it won't be expanded by # `expand_path` below. Can't win this game. file.puts("plugin_cache_dir = \"#{DEFAULT_PLUGIN_CACHE_PATH.sub(/^~/, '$HOME')}\"") dir = File.expand_path(DEFAULT_PLUGIN_CACHE_PATH) return if File.directory?(dir) Logger.debug("Creating the plugin cache dir '#{dir}'") FileUtils.mkdir_p(dir) end
existing_keys()
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 39 def existing_keys @existing_keys ||= [].tap do |keys| rc_file.readlines.each do |line| # The matcher is a bit naive, but enough for out use keys << Regexp.last_match(1) if line =~ /^(.+?)[ \t]*=/ end end end
rc_file()
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 35 def rc_file @rc_file ||= Pathname.new(RC_PATH).expand_path end
write_default_config()
click to toggle source
# File lib/yle_tf/action/write_terraformrc_defaults.rb, line 48 def write_default_config rc_file.open('w') do |rc_file| configure_checkpoint(rc_file) configure_plugin_cache_dir(rc_file) end end