So, in general, since you’re trying to add methods to self
within config/app.rb
, the extend
keyword can be used. It would be something like this:
config/app.rb
self.send(:extend, TerraspacePluginAws::Interfaces::Helper)
However, don’t recommend it as it won’t work with the way Terraspace currently implements helpers. This is because terraspace helpers are used as part of terraspace all
dependency graph calculation, and terraspace processes some files twice. Hence the helper methods are called twice. 1st pass: to calculate the dependency graph. 2nd pass: With the resolved graph, the output values are fetched from terraform state pull
.
This is mentioned here:
- Dependencies Tfvars Considerations - Terraspace
- Backend in different AWS account - #4 by tung
- https://github.com/boltops-tools/terraspace/issues/115
So if you try to call aws_secret
, you’ll see an error undefined method resolved' for nil:NilClass
for !!@mod.resolved
. It’s because when calling the helper methods directly it’s always the first pass. Don’t think there’s no way to force into the 2nd pass without even more hackery. Also, in the config/app.rb
the @mod
instance variable is unavailable.
Think will change the way double-processing works, only evaluating the helper methods required for dependency graph calculations on the first pass. This solves the issue more generally. This would make it possible to call methods like aws_secrets
without dealing with the double-pass.
As part of this, would probably also add helpers support to config/app.rb
automatically, so then you don’t even have use extend
hackery. Have recently been adding the helper support concept to the config
file in other tools like VPC Settings - UFO ECS Deploy Tool and can see its usefulness. Unsure when will get to this, though. Will review and consider PRs for this. Of course, no sweat either way.