boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
678 stars 46 forks source link

Example on how to load helper from within app.rb? #230

Closed mgzenitech closed 2 years ago

mgzenitech commented 2 years ago

Guys, can someone please give me an example on how to access helper methods from within app.rb? Specifically built in helper of AWS secrets manager.

Currently stuck on:

class SecretsLoader
  include TerraspacePluginAws::Interfaces::Helper

  def initialize()
    puts aws_secret("secret name")
  end
end

SecretsLoader.new()

However I get:

/opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator/printer.rb:49:in `info_from_backtrace': undefined method `first' for nil:NilClass (NoMethodError)
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator/printer.rb:23:in `error_info'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator/printer.rb:9:in `print'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator.rb:22:in `rescue in evaluate_file'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator.rb:18:in `evaluate_file'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/lib/terraspace/app.rb:89:in `load_project_config'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/lib/terraspace/core.rb:37:in `config'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/memoist-0.16.2/lib/memoist.rb:169:in `config'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/lib/terraspace/booter.rb:20:in `set_plugin_cache!'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/lib/terraspace/booter.rb:9:in `boot'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/lib/terraspace.rb:38:in `<top (required)>'
        from <internal:/opt/terraspace/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/terraspace/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/exe/terraspace:11:in `<top (required)>'
        from /usr/local/bin/terraspace:25:in `load'
        from /usr/local/bin/terraspace:25:in `<main>'
/home/xxx/Documents/Projects/xxx/config/app.rb:20:in `initialize': undefined method `resolved' for nil:NilClass (NoMethodError)
        from /home/xxx/Documents/Projects/xxx/config/app.rb:24:in `new'
        from /home/xxx/Documents/Projects/xxx/config/app.rb:24:in `evaluate_file'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator.rb:20:in `instance_eval'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/dsl_evaluator-0.3.0/lib/dsl_evaluator.rb:20:in `evaluate_file'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/memoist-0.16.2/lib/memoist.rb:169:in `config'
        from <internal:/opt/terraspace/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/terraspace/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/terraspace-1.1.7/exe/terraspace:11:in `<top (required)>'
        from /usr/local/bin/terraspace:25:in `load'
        from /usr/local/bin/terraspace:25:in `<main>'
tongueroo commented 2 years ago

Answered here https://community.boltops.com/t/example-on-how-to-load-helper-from-within-app-rb/873/3