Closed coderanger closed 6 years ago
Hi, @coderanger
Ok. We manage to solve this problem by changing this line in the followed files: ../resources/agent_infrastructure.rb ../resources/agent_php.rb
From:
attribute :license, :kind_of => String, :default => NewRelic.application_monitoring_license(node)
To:
attribute :license, :kind_of => String, :default => lazy { NewRelic.application_monitoring_license(node) }
Inside the recipe
node.default['newrelic']['license'] = newrelic['license_key']
Calling our data bag with this structure:
id: newrelic license_key:xxxxxxxxxxxxxxxxxxxxx
Thanks for your help.
Thanks @coderanger for the suggestion!
@coderanger: any way I could hide the lazy'ness in the module instead? That would feel cleaner rather than spreading "lazy {}" across the recipes / resources... Thanks in advance!
While technically doable in the library file if you tried hard enough, putting it in the resources and recipes is the correct way. Think of it as part of the DSL, not just a Ruby method :)
Ah ok, makes sense - thank you!
It looks like all the custom resources have some variation on
:default => NewRelic.application_monitoring_license(node)
which means the default value is being computed at file compile time. If you change that to:default => lazy { NewRelic.application_monitoring_license(node) }
it will make life a little easier since it delays the computation of the default until it gets used.