class TerraformInventory::Cli

Public Instance Methods

create(inventory_path) click to toggle source
# 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