class WavefrontHclOutput::Dashboard

This is a rather kludgy class which generates HCL output suitable for the Wavefront Terraform provider. It has to work round a number of inconsistencies and omissions in said provider, and will have to change as the provider improves.

It works, manually, down the hierarchy described in github.com/spaceapegames/terraform-provider-wavefront/blob/master/wavefront/resource_dashboard.go

Public Instance Methods

handle_chart(chart) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 55
def handle_chart(chart)
  fields = %w[units name description]

  lines = chart.each_with_object([]) do |(k, v), a|
    next unless fields.include?(k)

    a.<< format('%<key>s = %<value>s', key: k, value: quote_value(v))
  end

  lines.<< "source = #{handle_sources(chart[:sources])}"
  lines.to_hcl_obj(10)
end
handle_charts(charts) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 51
def handle_charts(charts)
  listmaker(charts, :handle_chart)
end
handle_rows(rows) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 45
def handle_rows(rows)
  rows.each_with_object([]) do |row, a|
    a.<< ('chart = ' + handle_charts(row[:charts]).to_s).braced(8)
  end.to_hcl_list
end
handle_source(source) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 72
def handle_source(source)
  source.each_with_object([]) do |(k, v), a|
    next unless source_fields.include?(k)

    k = 'queryBuilderEnabled' if k == 'querybuilderEnabled'

    a.<< format('%<key>s = %<value>s',
                key: k.to_snake,
                value: quote_value(v))
  end.to_hcl_obj(14)
end
handle_sources(sources) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 68
def handle_sources(sources)
  listmaker(sources, :handle_source)
end
hcl_fields() click to toggle source

Top-level fields

# File lib/wavefront-cli/output/hcl/dashboard.rb, line 21
def hcl_fields
  %w[name description url sections parameter_details tags]
end
khandle_sections() click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 25
def khandle_sections
  'section'
end
listmaker(vals, method) click to toggle source

@param vals [Array] an array of objects @param method [Symbol] a method which knows how to deal with one

of the objects in vals

@return [String] HCL list of vals

# File lib/wavefront-cli/output/hcl/dashboard.rb, line 34
def listmaker(vals, method)
  vals.each_with_object([]) { |v, a| a.<< send(method, v) }.to_hcl_list
end
qhandle_sections(val) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 89
def qhandle_sections(val)
  val
end
quote_value(val) click to toggle source
Calls superclass method WavefrontHclOutput::Base#quote_value
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 93
def quote_value(val)
  val.gsub!(/\$/, '$$') if val.is_a?(String)
  super
end
source_fields() click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 84
def source_fields
  %w[name query disabled scatterPlotSource querybuilderEnabled
     sourceDescription]
end
vhandle_sections(vals) click to toggle source
# File lib/wavefront-cli/output/hcl/dashboard.rb, line 38
def vhandle_sections(vals)
  vals.each_with_object([]) do |section, a|
    a.<< ("name = \"#{section[:name]}\"\n      row = " +
          handle_rows(section[:rows])).braced(4)
  end.to_hcl_list
end