Class: TerraformInventory::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/terraform_inventory/cli.rb

Instance Method Summary collapse

Instance Method Details

#create(inventory_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/terraform_inventory/cli.rb', line 27

def create(inventory_path)
  state = TerraformState.new `terraform show -no-color #{options[:state]}`

  begin
    @groups = state.group_by_host(options[:map])
  rescue Exception::InvalidResourceSelectorException, Exception::ResourceNotFoundException => ex
    say ex.message, :red
    exit(1)
  else
    @ungrouped_resources = @groups[:none] || []
    @groups.delete(:none)

    config = {
      ip_type: "#{options[:ip_type]}_ip"
    }

    template("inventory.erb", inventory_path, config)
  end
end