SparkleFormation provides a collection of helper methods for facilitating faster development and cleaner code. Some helpers provide easier access to underlying SparkleFormation functionality, while others provide automatic generation of known template data structures.
Inserting a dynamic directly requires calling out to the singleton method and providing the local context, which looks like this:
SparkleFormation.new(:test) do
SparkleFormation.insert(:my_dynamic, self, :some => [:value])
end
The helper compacts this call to:
SparkleFormation.new(:test) do
dynamic!(:my_dynamic, :some => [:value])
end
Registries are used by calling out the singleton method and providing the local context:
SparkleFormation.new(:test) do
SparkleFormation::Registry.insert(:my_registry, self, :some => [:value])
end
and can be compacted to:
SparkleFormation.new(:test) do
registry!(:my_registry, :some => [:value])
end
Nests are used by calling out to the singleton method and providing the local context:
SparkleFormation.new(:test) do
SparkleFormation.nest(:my_template, self, :some => [:value])
end
and can be compacted to:
SparkleFormation.new(:test) do
nest!(:my_template, :some => [:value])
end
Use the system!
helper method to shell out to the local system,
execute a command, and return the string output:
SparkleFormation.new(:test) do
parameters.creator.default system!('whoami')
end
Use the puts!
helper method to print content to the console:
SparkleFormation.new(:test) do
puts! 'Hi everybody!'
...
end
Use the raise!
helper method to raise exceptions:
SparkleFormation.new(:test) do
raise! 'ERROR'
end
SparkleFormation includes provider specific helpers based on the provider defined when instantiating the SparkleFormation template instance. For example:
SparkleFormation.new(:my_stack, :provider => :aws) do
...
output.instance_id.value ref!(:my_instance)
end
will make the AWS specific helper functions available within this template instance. If the provider specified Azure, then the Azure specific helper methods would be available:
SparkleFormation.new(:my_stack, :provider => :azure) do
...
outputs.instance_id do
type 'string'
value reference_id(:my_instance)
end
end
To see all the available helpers for specific providers, refer to the library documentation: