Sha256: 9e174037736b406a1c2cc6123017a9e5329b40055803b02e170d430dc52e1437

Contents?: true

Size: 1.72 KB

Versions: 29

Compression:

Stored size: 1.72 KB

Contents

require 'json'
require 'lino'
require_relative 'base'

module RubyTerraform
  module Commands
    class Apply < Base
      def configure_command(builder, opts)
        directory = opts[:directory]
        plan = opts[:plan]
        vars = opts[:vars] || {}
        var_file = opts[:var_file]
        var_files = opts[:var_files] || []
        target = opts[:target]
        targets = opts[:targets] || []
        state = opts[:state]
        input = opts[:input]
        auto_approve = opts[:auto_approve]
        no_backup = opts[:no_backup]
        backup = no_backup ? '-' : opts[:backup]
        no_color = opts[:no_color]

        builder
            .with_subcommand('apply') do |sub|
              vars.each do |key, value|
                var_value = value.is_a?(String) ? value : JSON.generate(value)
                sub = sub.with_option(
                    '-var', "'#{key}=#{var_value}'", separator: ' ')
              end
              sub = sub.with_option('-var-file', var_file) if var_file
              var_files.each do |file|
                sub = sub.with_option('-var-file', file)
              end
              sub = sub.with_option('-target', target) if target
              targets.each do |file|
                sub = sub.with_option('-target', file)
              end
              sub = sub.with_option('-state', state) if state
              sub = sub.with_option('-input', input) if input
              sub = sub.with_option('-auto-approve', auto_approve) unless
                  auto_approve.nil?
              sub = sub.with_option('-backup', backup) if backup
              sub = sub.with_flag('-no-color') if no_color
              sub
            end
            .with_argument(plan || directory)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ruby-terraform-0.64.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.63.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.62.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.61.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.60.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.59.0.pre.2 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.59.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.58.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.57.0.pre.2 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.57.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.56.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.55.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.54.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.53.0.pre.2 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.53.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.52.0 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.51.0.pre.3 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.51.0.pre.2 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.51.0.pre.1 lib/ruby_terraform/commands/apply.rb
ruby-terraform-0.50.0 lib/ruby_terraform/commands/apply.rb